cancel
Showing results for 
Search instead for 
Did you mean: 

unexpected behavior? not able to clear TIM_IT_Update

enrico239955_st
Associate II
Posted on August 19, 2014 at 01:01

Hi, I am not able to clear a timer update flag while the timer is enabled. I am initializing a timer and the behavior is the following:

    ....

    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

    TIM4->SR = (uint16_t)~TIM_IT_Update; // clear update flag

the flag was cleared

   ...

    TIM_Cmd(TIM4, ENABLE);

this sets all IT flags (update, cc1, cc2, cc3, cc4), why? I initialized cc1 with a large number, so it cant be hit by the initial counter value

    TIM4->SR = (uint16_t)~TIM_IT_Update; // clear update flag

the flag was NOT deleted

    TIM_Cmd(TIM4, DISABLE);

    TIM4->SR = (uint16_t)~TIM_IT_Update; // clear update flag

now the flag was deleted

What could be the reason for this behavior?
3 REPLIES 3
enrico239955_st
Associate II
Posted on August 19, 2014 at 01:33

ps: I am stepping through the code and I am watching the status flags after executing each line.

enrico239955_st
Associate II
Posted on August 19, 2014 at 01:44

Is it possible that immediatly after clearing the flag the controller is setting the flag again (while debugging the timer is still running) so that I can not see the cleared flag?

enrico239955_st
Associate II
Posted on August 19, 2014 at 01:54

Yes, that was the problem 🙂

btw, I know that one can stop the timer while debugging the controller, but I use that seldom and I always forget the running timers..