AnsweredAssumed Answered

STM32L152RB Timer Interrupts

Question asked by grove.kevin on Oct 16, 2013
Latest reply on Oct 17, 2013 by r.denis
I've been trying to solve this issue for way too long now.  I've looked at other similar posts, but I am still unable to enter my ISR when the timer rolls over.  

void init_interface(void)
{
   GPIO_InitTypeDef GPIO_InitStruct;
   //init pin for output
   GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;
   GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
   GPIO_InitStruct.GPIO_Speed = GPIO_Speed_40MHz;
   GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
   GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
   GPIO_Init(GPIOC, &GPIO_InitStruct);
}
 
void init_timer(void)
{
   TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
   NVIC_InitTypeDef NVIC_InitStructure;
     
   /* Enable the TIM9 global Interrupt */
   NVIC_InitStructure.NVIC_IRQChannel = TIM9_IRQn;
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
   NVIC_Init(&NVIC_InitStructure);     
     
   TIM_TimeBaseStructure.TIM_Period = 160;
   TIM_TimeBaseStructure.TIM_Prescaler = 1124;
   TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
   TIM_TimeBaseInit(TIM9, &TIM_TimeBaseStructure);
     
    TIM_ClearFlag(TIM9, TIM_FLAG_Update);
    TIM_ITConfig(TIM9, TIM_IT_Update, ENABLE);
    TIM_Cmd(TIM9, ENABLE);
}
 
void main()
{
   RCC_Config();
   init_interface();
   init_timer();
 
   while(1);
}

Below is my ISR:
void TIM9_IRQHandler(void)
{
   if(TIM_GetITStatus(TIM9, TIM_IT_Update) != RESET)
   {
      //clear interrupt
      TIM_ClearITPendingBit(TIM9, TIM_IT_Update|TIM_IT_CC1|TIM_IT_CC2);
      //toggle 'clock'
      GPIO_ToggleBits(GPIOC, GPIO_Pin_1);
   }
}

Basically, all I'm trying to do is toggle an output pin every X ms (or us or whatever.  it doesn't really matter until the interrupt triggers), but I know I want to use the peripheral timers instead of the SysTick.  When I run the debugger, I see that the code enters the NMI handler, and the disassembly says something about a 'bus error' which causes my program to hang.  Everywhere I look says that this is how you set up a timebase, but I  haven't had any luck whatsoever.

Any suggestions?  Did I just miss something?

Thanks.

Outcomes