Bingo! I want to write a program for LIS302DL(MEMS Accelerometer) by my self since I've bought STM32F4 Discovery. After few days of working and learning, I've just finish my programming few minutes ago and it is working perfectly well.
So, the program is written to keep the discovery board's surface level at zero, means if the surface is tilted on which the Board is placed, the led(s) will glow such that it indicate the direction at which the surface should be tilted to balance the level.
STM32F4 Discovery also came with the same program, but it is too complex to understand. In their Demo, TIMER4 is used. Instead of using timer I've used only simple led on-off command. It is too simple to understand then using timer.
Here are some photos:
It isn't possible for me to tilt the whole table. So, I just tilted the board!Bad PJ, isn't it?
So, the program is written to keep the discovery board's surface level at zero, means if the surface is tilted on which the Board is placed, the led(s) will glow such that it indicate the direction at which the surface should be tilted to balance the level.
STM32F4 Discovery also came with the same program, but it is too complex to understand. In their Demo, TIMER4 is used. Instead of using timer I've used only simple led on-off command. It is too simple to understand then using timer.
Here are some photos:
It isn't possible for me to tilt the whole table. So, I just tilted the board!Bad PJ, isn't it?
Here's the video of Acceleromter and STM32F4 in action:
The program used one special type of interrupt Sys_Tick. This interrupt generates at every 1ms in my program. You can change if you want. So, at every 1ms we check the resisters of LIS302DL and compare it with our logic to blink led according to the direction. I don't want to say that we should not use TIMx in programming, but what I mean is why to use complex programming method when the simplest form of programming is available. The main advantage of not using TIM4 is that the time require to handle TIM4 interrupt is saved in case of using simple GPIO On-Off command.