Timer interrupt not work

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

Timer interrupt not work

402 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by anhdung88 on Sat Aug 02 20:20:52 MST 2014
Hi everyone,
I'm writing a test LPC1769 Timer1 interrupt, I have enable the interrupt but it does not walk into the timer interrupt handler code. Can anyone tell me something wrong in my code?
The symptom is it stucks at while loop in main() function and doesn't respond while debugging.
PS: my project has 3 files: timer.h, timer.c & main.c
/*
* timer.h
*
*  Created on: 03-08-2014
*      Author: Vaio
*/

#include <LPC17xx.h>
#include <stdio.h>

#ifndef TIMER_H_
#define TIMER_H_

void TIMER_init();
extern void TIMER1_IRQHandler();

extern volatile uint32_t data[10];
extern uint8_t cnt;

#endif /* TIMER_H_ */

/*
* timer.c
*
*  Created on: 03-08-2014
*      Author: Vaio
*/

#include <timer.h>

volatile uint32_t data[10] = {0xffffffff,0,0xffffffff,0,0xffffffff,0,0xffffffff,0,0xffffffff,0};
uint8_t cnt = 0;

void TIMER_init()
{
// setup timer1
LPC_SC->PCONP |= 1 << 2; // Power up
LPC_SC->PCLKSEL0 |= 0x01 << 4; // CCLK -> 10nseg ticks
LPC_TIM1->MR0 = 2000;// Match a los 20 useg
//LPC_TIM1->MCR = 1 << 1; // reset on Match Compare 0
LPC_TIM1->MCR = 3; // reset on Match Compare 0 & generate interrupt

NVIC_EnableIRQ(TIMER1_IRQn);
}


void TIMER1_IRQHandler()
{
printf("0x%x\n",data[cnt]);
if(cnt < 10)
{
cnt += 1;
}
else
{
cnt=0;
}
}


/*
===============================================================================
Name        : DMA_test.c
Author      : $(author)
Version     :
Copyright   : $(copyright)
Description : main definition
===============================================================================
*/
#include <stdio.h>

// TODO: insert other include files here
#include <timer.h>

// TODO: insert other definitions and declarations here
//extern volatile uint32_t data[10];

int main(void) {
TIMER_init();

    printf("Hello World\n");

    // Force the counter to be placed into memory
    volatile static int i = 0 ;
    // Enter an infinite loop, just incrementing a counter
    while(1) {
        i++ ;  // it stucks here and doesn't go to interrupt handler
    }
    return 0 ;
}
Labels (1)
0 Kudos
1 Reply

359 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wmues on Sun Aug 03 03:30:59 MST 2014
In TIMER_init, you miss
TCR=0x02
PR= 0
IR=0xFF
and, to start the timer
TCR=0x01
0 Kudos