cancel
Showing results for 
Search instead for 
Did you mean: 

Why is the flag not cleared when __HAL_TIM_CLEAR_IT is run?

ADahr
Associate

Using the CubeMX generated code, the timer interrupt goes to HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) where the source of the interrupt is checked. It then calls the correct callback function depending on the source. Problem is that both the OC and the UPDATE flags always are set because these lines do nothing:

       __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1);

....

     __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE);

Checking the timer registers with the debugger I can see that the bits don't change. I can also see that the counter is at a random value every time the interrupt routine is called: void TIM1_BRK_TIM15_IRQHandler(void)

1 REPLY 1
ADahr
Associate

The instruction works (of course) but I could not see it because the timer was not stopped in debug mode and thus triggered a new interrupt before the debugger stopped on the next instruction. By setting the DBG_TIMx_STOP bit in the DBGMCU register I could see that it was cleared. Problem solved!