Timer 32 interrupt not correctly triggering

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

Timer 32 interrupt not correctly triggering

388 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by otavioborges on Wed Sep 23 16:00:33 MST 2015
Hello all,

I just recently started programming NXP microcontrollers, so I'm still getting the hang of it.

I'm having trouble setting an interrupt for Timer_32_0. I have configured the registers, the code enters the interrupt handler, but I was not able to correctly set the interrupt period.

I put an watch on the TC register when the interrupt is called and I'm getting random values on the timer values. I've checked the registers for the timer and the match register seen to be correct and there's no pin capture enabled. The code I'm using is as follows:

#if defined (__USE_LPCOPEN)
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif

//#include <cr_section_macros.h>

uint32_t CPUfreq;

#if defined (__cplusplus)
extern "C" {
#endif

void TIMER32_0_IRQHandler(void){
CPUfreq = LPC_TIMER32_0->TC;
Chip_GPIO_SetPinToggle(LPC_GPIO,0,8);
}

#if defined (__cplusplus)
} // extern "C"
#endif

int main(void) {
uint32_t timerFreq;

/* Timer rate is system clock rate */
timerFreq = Chip_Clock_GetSystemClockRate();

LPC_SYSCON->SYSAHBCLKCTRL |= 1 << 9;
LPC_TIMER32_0->MCR |= 3 << 3; // Enables int on MR1 and Resets on match;
LPC_TIMER32_0->MR[1] = timerFreq;
LPC_TIMER32_0->TCR |= 1;


NVIC_ClearPendingIRQ(TIMER_32_0_IRQn);
NVIC_EnableIRQ(TIMER_32_0_IRQn);

Chip_GPIO_SetPinDIROutput(LPC_GPIO,0,8);
Chip_GPIO_SetPinState(LPC_GPIO,0,8,true);

volatile static int i = 0 ;
while(1){
__WFI();
i++;
}
}

Labels (1)
0 Kudos
2 Replies

318 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by otavioborges on Wed Sep 23 20:47:01 MST 2015
Worked great! 8-)

Thank you R2D2.
0 Kudos

318 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Sep 23 16:38:15 MST 2015
There's a blinky sample, which is showing how to use timer and interrupts 

/**
 * @briefHandle interrupt from 32-bit timer
 * @returnNothing
 */
void TIMER32_0_IRQHandler(void)
{
// if(Chip_TIMER_MatchPending(LPC_TIMER32_0, 1))
 {
  [color=#f00]Chip_TIMER_ClearMatch(LPC_TIMER32_0, 1);[/color]
  //Board_LED_Set(0, true);
  Board_LED_Toggle(0);
 }
}


In your code you've obviously forgotten to reset the interrupt 
0 Kudos