Timer interrupt never hits TIMER0_IRQHandler

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Timer interrupt never hits TIMER0_IRQHandler

1,804 Views
senersoft
Contributor I

I have LPCXpresso 1769 and LPC-Link 2 for debugging. My development environment is IAR.

I wanted to experience a simple LED blinking using Timer. There are many sample codes about it and I picked one I presume it is a working sample. I have also read some here and there how timer works with LPC's, etc...

The code compiles and I downloaded the program to the device.

My question is how to debug and find the reason why TIMER0_IRQHandler doesn't get hit at all.

Here is the complete code in my main.c file:

#include <lpc17xx.h>

void TIMER0_IRQHandler(void);

int main(void)
{
  // (1) Timer 0 configuration (see page 490 of user manual)
  LPC_SC->PCONP |= 1 << 1; // Power up Timer 0 (see page 63 of user manual)
  LPC_SC->PCLKSEL0 |= 1 << 2; // Clock for timer = CCLK, i.e., CPU Clock (page 56 user manual)
  // MR0 is "Match Register 0". MR0 can be enabled through the MCR to reset
  // the Timer/Counter (TC), stop both the TC and PC, and/or generate an interrupt
  // every time MR0 matches the TC. (see page 492 and 496 of user manual)
 
  LPC_TIM0->MR0 = 500; //Toggle Time in mS
  //LPC_TIM0->MR0 = 1 << 23; // Give a value suitable for the LED blinking
 
  // frequency based on the clock frequency
  // MCR is "Match Control Register". The MCR is used to control if an
  // interrupt is generated and if the TC is reset when a Match occurs.
  // (see page 492 and 496 of user manual)
  LPC_TIM0->MCR |= 1 << 0; // Interrupt on Match 0 compare
  LPC_TIM0->MCR |= 1 << 1; // Reset timer on Match 0
  // TCR is "Timer Control Register". The TCR is used to control the Timer
  // Counter functions. The Timer Counter can be disabled or reset
  // through the TCR. (see page 492 and 494 of user manual)
  LPC_TIM0->TCR |= 1 << 1; // Manually Reset Timer 0 (forced);
  LPC_TIM0->TCR &= ~(1 << 1); // Stop resetting the timer
  // (2) Enable timer interrupt;
  // TIMER0_IRQn is 1, see lpc17xx.h and page 73 of user manual
  NVIC_EnableIRQ(TIMER0_IRQn); // see core_cm3.h header file
  // (3) Some more one-time set-up's;
  LPC_TIM0->TCR |= 1 << 0; // Start timer (see page 492 and 494 of user manual)
  LPC_SC->PCONP |= ( 1 << 15 ); // Power up GPIO (see lab1)
  LPC_GPIO1->FIODIR |= 1 << 29; // Put P1.29 into output mode. LED is connected to P1.29
  // (4) infinite loop;
  while (1) // Why do we need this?
  {
    //LPC_GPIO1->FIOPIN ^= 1 << 29; // Toggle the LED (see lab1)
  }
  return 0;
}


// Here, we describe what should be done when the interrupt on Timer 0 is handled;
// We do that by writing this function, whose address is “recorded” in the vector table
// from file startup_LPC17xx.s under the name TIMER0_IRQHandler;
void TIMER0_IRQHandler(void)
{
  // IR is "Interrupt Register". The IR can be written to clear interrupts. The IR
  // can be read to identify which of eight possible interrupt sources are
  // pending. (see page 492 and 493 of user manual)
  if ( (LPC_TIM0->IR & 0x01) == 0x01 ) // if MR0 interrupt (this is a sanity check);
  {
    LPC_TIM0->IR |= 1 << 0; // Clear MR0 interrupt flag (see page 492 and 493 of user manual)
    LPC_GPIO1->FIOPIN ^= 1 << 29; // Toggle the LED (see lab1)
  }
}

Note that: Sorry for the code part. "Source Code <>" option didn't work for some reason.

Labels (1)
0 Kudos
Reply
1 Reply

1,496 Views
soledad
NXP Employee
NXP Employee

Hi, 

Please check the following link, 

https://community.nxp.com/thread/423278 

I hope this helps, 

regards

Soledad

0 Kudos
Reply