2021-02-08 12:27 PM
Hello STM-Community,
I'm fairly new to STM programming and I use an STM32 microcontroller with STM32CubeMX encountered a weird issue with my functions.
I've got an IRQ, which collects data every interrupt. Similair like this:
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == INT_EXT_Pin)
{
ACCMETER_IRQ(accdata);
data_counter++;
}
}
In the main function I want to see if enough data have been collected for an FFT.
Similair like this in my while loop:
while(1)
{
if (data_counter > 4096)
{
FFT_ACCMETER(accdata);
data_counter = 0;
}
}
while performing the FFT, the IRQ still collects data for a buffer function, therefore no data should be lost in between each FFT.
Here's the issue, after gathering enough data, data_couner is set to 4096 (or higher), but never actually goes into the if condition. I've tried out many different things such as accessing the variable to different one within my main loop and it didn't help. I'd be really glad for some advices.
Kind Regards
Norman
Solved! Go to Solution.
2021-02-08 12:57 PM
data_counter must be defined volatile if used for synchronization, otherwise the compiler may optimize too much.
2021-02-08 12:57 PM
data_counter must be defined volatile if used for synchronization, otherwise the compiler may optimize too much.
2021-02-08 02:03 PM
Oh okay thank you! I just wanted to write that it might have been fixed since it worked when I just checked it after restarting the pc. Though I will consider this the next time it happens to me.
Thanks!