cancel
Showing results for 
Search instead for 
Did you mean: 

Counter after interrupt request doesn't enable if condition in main

crackl1ng
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

data_counter must be defined volatile if used for synchronization, otherwise the compiler may optimize too much.

View solution in original post

2 REPLIES 2
KnarfB
Principal III

data_counter must be defined volatile if used for synchronization, otherwise the compiler may optimize too much.

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!