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.