cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 and Timer Interrupt flags

Valeev.Kamil
Associate II
Posted on August 05, 2015 at 11:39

Greetings.

I have a timer3 configured to be 1 ms timer with an interrupt on the overflow:

void InitTIM3()

{

  TIM_TimeBaseInitTypeDef timer;

  TIM_TimeBaseStructInit(&timer); // Fill structure fields with default values

 

  timer.TIM_Prescaler = 59;

  timer.TIM_Period = 999;

 

  TIM_TimeBaseInit(TIM3, &timer);

 

 

  TIM_Cmd(TIM3, DISABLE);

 

  TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);

  TIM3->SR = 0;

  NVIC_ClearPendingIRQ (TIM3_IRQn);

}

Timer3 is enabled soon in the main() after enabling all interrupts.

When interrupt occurs not only the Update Flag is set in TIM3_SR, but also all Capture/Compare interrupt flags: CC1IF, CC2IF, CC3IF, CC4IF. Though I do absolutely nothing to the CC modules. All corresponding CC registers are 0 and why  does it happen I don't know.

The interrupt handler:

void TIM3_IRQHandler(void)

{

  if (TIM3->SR & TIM_SR_UIF) {

    TIM3->SR = ~TIM_SR_UIF;

  }

}

I'm using STM32F205RE, but it also happened on other MCUs.

I wonder if someone knows about this 'issue'. Thank you!

#stm32-interrupts-flags-timer
2 REPLIES 2
Posted on August 05, 2015 at 13:54

It's a register that flags state, it doesn't actually generate an interrupt unless you explicitly enable the interrupt so it gates to the NVIC's TIM IRQ pin.

Why does it do this? Because it simplifies the silicon implementation. The bits from the flags register AND with the enable register, and are then OR'd together to generate the IRQ signal.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Valeev.Kamil
Associate II
Posted on August 05, 2015 at 14:00

Ok, got it . Thank you for your reply.