STM32F051 TIMER2 INTERRUPT PROBLEM

69 views
Skip to first unread message

Marlon Sequeira

unread,
May 21, 2015, 11:33:50 PM5/21/15
to stm3...@googlegroups.com

I would like to get TIMER 2 working for stm32f051 microcontroller in coocox IDE(1.7.8) . The problem i am facing is that as soon as I enable the intrrupt for TIMER 2 using NVIC_EnableIRQ(TIM2_IRQn) the code gets stuck in a infinite loop in the Default_Handler:

    Default_Handler:
    Infinite_Loop:
    b Infinite_Loop
    .size Default_Handler, .-Default_Handler

this is the code for intialization of the timer

  TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure; // 2
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); // 4
  TIM_TimeBaseInitStructure.TIM_Prescaler = 0x30; // 6
  TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; // 7
  TIM_TimeBaseInitStructure.TIM_Period = 10000; // 8
  TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; // 9
  TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0; // 10
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitStructure); // 11
  NVIC_EnableIRQ(TIM2_IRQn); // Enable IRQ for TIM5 in NVIC // 13
  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); // Enable IRQ on update for Timer5 // 14
  TIM_Cmd(TIM2, ENABLE); // 16

and this is the code for interrrup handler

   void TIM2_IRQHandler(void) {
   TIM_ClearITPendingBit(TIM2, TIM_IT_Update); // clear interrupt flag // 3
   // Do Something
   // here 
   }

can anyone tell me what I am doing wrong. I feel the way the interrupt handler is defined is not correct. Has any one faced the same problem in the past.

Дмитрий Бравиков

unread,
May 22, 2015, 5:54:21 AM5/22/15
to stm3...@googlegroups.com
Show startup file. Does it contain TIM2_IRQHandler?
> --
> You received this message because you are subscribed to the Google Groups
> "stm32" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to stm32_en+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages