SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By Cyberzim
#144659
Hi,
I'm trying to work out the TIM2 interrupt handler. But it doesn't seem to run the function at all.
Here is my initialization code for the TIM2:
Code: Select all
//Enable TIM2.
  RCC_APB1ENR |= RCC_APB1ENR_TIM2EN;
  //Prescaler.
  TIM2->PSC = 65535;
  //Auto reload value.
  TIM2->ARR = 1000;
  //Enable update interrupt (timer level).
  TIM2->DIER = TIM_DIER_UIE;
  //Enable timer.
  TIM2->CR1 = TIM_CR1_CEN;
  //Enable interrupt.
  NVIC_EnableIRQ(TIM2_IRQn);


Here is my handler:
Code: Select all
//Timer 2 interrupt.
void TIM2_IRQHandler(void) {
  
  //Is the timer set?
  if(TIM2->SR & TIM_SR_UIF) {

    //Draw a rectangle on screen (test purpose).
    FillRect(100, 100, 20, 20, 0xFF);   
  
    //Clears flag.
    TIM2_SR &= ~TIM_SR_UIF;
  }
}
I have tested the timer itself and it works flawlessly, but It won't work with an interrupt handler.
I'm using CrossWorks for ARM.

Any suggestions?

Regards,

Simon H.A.
By hsutherl
#144786
Your code flashed an LED for me once I changed the TIM2_SR to TIM2->SR in the last line. This using generic tools rather than Crossworks. You might have to post the entire code and include details on board and uC.