Skip to main content
ADahr
Associate
June 17, 2019
Question

Why is the flag not cleared when __HAL_TIM_CLEAR_IT is run?

  • June 17, 2019
  • 1 reply
  • 1594 views

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)

This topic has been closed for replies.

1 reply

ADahr
ADahrAuthor
Associate
June 18, 2019

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!