lpcware

Timer 32 interrupt not correctly triggering

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
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++;
}
}

Outcomes