cancel
Showing results for 
Search instead for 
Did you mean: 

TIMx_SR register not being cleared from interrupt (really strange issue)

Posted on November 16, 2015 at 03:24

Hello all,

I'm having another strange issue, when an update interrupt happens, neither the instruction ''__HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE)'' (line 2869) of the hal_tim.c library or my code in the callback function are being able to clear the UIF flag (Bit 0 from SR register), as stated in the screenshot (attached)

But if I try the same instruction (either the HAL_TIM_CLEAR_IT or the direct register attribution) from outside the interrupt (like before enabling the IRQ again) everything works

What could be the problem? someone else experienced the same problem? 
2 REPLIES 2
Posted on November 16, 2015 at 04:21

What's the time scale of the timer vs the breakpoint and debugger? Do you have DBGMCU stopping the timer? Otherwise it's likely to keep ticking faster that you can react.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on November 16, 2015 at 05:36

Thank you !!

You nailed it, I was checking the flag before calling the function that stops the timer, probably at some point the interrupt was not fast enough to stop it before overflowing again (I am using RTOS, so maybe some other interrupt with higher prio happened), then I saw the problem happening and I started checking with breakpoints.. therefore causing it again and again .. typical chicken-egg problem =(

For precaution, I'll always clear the bit right before enabling the timer interrupt, better safe than sorry