Timer for 3 s interrupts after 8 s
Hi !
I am currently using STM32 Nucleo-L073RZ
The problem is that I've set it to 3 s but it executes after 8 s. In a different application it finished exactly after 3 s. I just don't understand what went wrong.



The code looks like that :
What main has :
uint8_t min = 1;
uint8_t max = 6;
uint8_t result_rand;
uint8_t timer;
uint8_t Display[4];
srand(time(NULL));
while (1)
{
if(HAL_GPIO_ReadPin(Button_GPIO_Port, Button_Pin) == GPIO_PIN_RESET || spin == 1)
{
result_rand = (rand() % (max - min + 1) + min);
Display[0] = int2inta(result_rand);
Display[1] = int2inta(result_rand-2);
Display[2] = int2inta(result_rand-4);
Display[3] = char2segments(' ');
tm1637_DisplayHandle(7, Display);
if(HAL_GPIO_ReadPin(Button_GPIO_Port, Button_Pin) == GPIO_PIN_RESET)
{
timer = 1;
}
}
else
{
if(timer == 1)
{
timer = 0;
spin = 1;
HAL_TIM_Base_Start_IT(&htim2);
}
}What the interrupt has :
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
spin = 0;
HAL_TIM_Base_Stop_IT(&htim2);
}
Also there is a problem because when I don't click the button it is always "1" but when I click it then it is "0" in other boards it was the opposite. Weird.