Skip to main content
David Martins
Senior
June 21, 2016
Question

Timer interrupt works immediately

  • June 21, 2016
  • 4 replies
  • 678 views
Posted on June 21, 2016 at 10:52

Hello.

I have configured the timer 6 to interrupt every 3s, but immediately after initialize the timer the interrupt occurs.

Why?

1 - HAL_TIM_Base_Init (&htim6);

2 - HAL_TIM_Base_Start_IT(&htim6);

3 - ''immediately'' (almost) it goes to interrupt handler...

How can I resolve this problem?

Thank you.
    This topic has been closed for replies.

    4 replies

    waclawek.jan
    Super User
    June 21, 2016
    Posted on June 21, 2016 at 11:57

    > Why?

    Because

    > 1 - HAL_TIM_Base_Init (&htim6);

    forces update through setting TIMx_EGR.UG (the reason is to force the prescaler setting into the real prescaler counter).

    > How can I resolve this problem?

    Clear TIMx_SR.UIF before enabling the timer.

    JW

    David Martins
    Senior
    June 21, 2016
    Posted on June 21, 2016 at 12:32

    Hello.

    I had already done it ... but the result is the same.

    The interruption is immediate ...

    https://s31.postimg.org/bgurb25a3/Capturar.png

    waclawek.jan
    Super User
    June 21, 2016
    Posted on June 21, 2016 at 12:45

    Clear the flag *before* HAL_TIM_Base_Start_IT().

    JW

    David Martins
    Senior
    June 21, 2016
    Posted on June 21, 2016 at 13:00

    Oh... sorry xD.

    I think that the flag had changed in Start_IT, so I tried modify the flag after...

    In resume, the flag is changed in Timer Init...

    My mistake.

    It works!

    Thank you very much!