Global Variables and Timer Interrupt
Greetings to all.
I'm new to this forum and new with STM32 too. So i decided to experiment (and mess) with them to learn something.
Now the first problem. I am esperimenting with timers, and after i discovered we can't use HAL_Delay() inside a timer's interrupt calling, I used a workaround. I set a global variable as a switch, so the interrupt routine only changes the switch. The rest should be made in the while(). After some days changing the code, putting breakpoints, etc.. i surrender.
Here is some code:
#include "main.h"
int Bounce = 0; //Bounce Counter
int swTim3 = 0; //Interrupt switch
/* some other code lines ...*/
while (1)
{
if (swTim3 > 0)
{
/* some code toggling the led*/
swTim3=0; //reset interrupt
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM3)
{
swTim3=1;
}
}debugging the program, it does not enter inside the if (swTim3 > 0) {}. If I pause the debugging, it is saying me the swTim3 is equal to 1, so i suppose that the interrupt routine is executed and correctly set the variable.
If i comment the code inside the interrupt routine and set the swTim3=1 before the while(1), it enters inside the "if" block.
Sorry for my bad english and thanks a lot
Vittorio
P.s. I'm using Atollic Studio and a Nucleo F401RE board