This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPC 2148 timer o interrupt working once

hi ,

I am configuring LPC 2148 timer 0 in interrupt mode, i am able to receive pnterrupt once but next time interrupt is not generating.(interrupt occurs at rate of 1 second)

Following are the routines

/****************************************************************************************
*Function :timer init
*Inputs_gen :
*Output :
*Purpose :This function INTIALISES TIMER 0
****************************************************************************************/

void timer0_init(void) {

T0TCR=0X02; // RESETTING THE TIMER COUNTER AND PRESCALER COUNTER

T0IR=0XFF; // RESETTING ALL THE INTERRUPT

T0CTCR=0X00; // SELECTING TIMER /COUNTER MODE

T0TC=0X00000000; // TIMER COUNT REGISTER

T0PR=0X10DFF; // PRESCALER REGISTER

T0PC=0X00; // PRESCALER COUNT REGISTER

T0MR0=0XFF; // MATCH REGISTER

T0MCR=0X0005; // RESET TC AND STOP TIMER & GENERATES INTERRUPT
WHEN TC==TOMRO

}

/****************************************************************************************
*Function :timer0_start
*Inputs_gen :
*Output :
*Purpose :This function is used to start
****************************************************************************************/
void timer0_start(void) { T0TCR=0X01; // RESETTING THE TIMER COUNTER AND PRESCALER COUNTER

}

/****************************************************************************************
*Function :timer0_reset
*Inputs_gen :
*Output :
*Purpose :This function is used to reset pc and tc
****************************************************************************************/
void timer0_reset(void) {

T0TCR=0X02; // RESETTING THE TIMER COUNTER AND PRESCALER COUNTER

}

/****************************************************************************************
*Function :timer0_int
*Inputs_gen :
*Output :
*Purpose :This function is used to initalize timer interrupt
****************************************************************************************/
void timer0_int(void) {

VICIntEnable=0x00000010;

VICIntSelect=0x00000010;

}
/****************************************************************************************
*Function :timer0_start
*Inputs_gen :
*Output :
*Purpose :This function is used to start
****************************************************************************************/
void timer0_start(void) {

T0TCR=0X01;

}

/****************************************************************************************
*Function :timer0_reset
*Inputs_gen :
*Output :
*Purpose :This function is used to reset pc and tc
****************************************************************************************/
void timer0_reset(void) {

T0TCR=0X02; // RESETTING THE TIMER COUNTER AND PRESCALER COUNTER

}

/****************************************************************************************
*Function :timer0_int
*Inputs_gen :
*Output :
*Purpose :This function is used to initalize timer interrupt
****************************************************************************************/
void timer0_int(void) { VICIntEnable=0x00000010;

VICIntSelect=0x00000010;

}

/****************************************************************************************
*Function :FIQ_Handler
*Inputs_gen :
*Output :
*Purpose :This function is FIQ interrupt
****************************************************************************************/

void FIQ_Handler (void) { if((VICFIQStatus & 0x00000010)==0x00000010) {

T0IR=0xFF;

puts_gen("\n\r Timer interrupt generated",0);

puts_gen("s",0);

//VICIntEnable=0x00000010;

timer0_reset();

timer0_start();

} else {

puts_gen("\n\r some one else",0); } }

Following is the change in startup file

Vectors LDR PC, Reset_Addr

LDR PC, Undef_Addr

LDR PC, SWI_Addr

LDR PC, PAbt_Addr

LDR PC, DAbt_Addr

NOP ; Reserved Vector

; LDR PC, IRQ_Addr

LDR PC, [PC, #-0x0FF0] ; Vector from VicVectAddr

LDR PC, FIQ_Addr

IMPORT FIQ_Handler

Reset_Addr DCD Reset_Handler

Undef_Addr DCD Undef_Handler

SWI_Addr DCD SWI_Handler

PAbt_Addr DCD PAbt_Handler

DAbt_Addr DCD DAbt_Handler

DCD 0 ; Reserved Address

IRQ_Addr DCD IRQ_Handler

FIQ_Addr DCD FIQ_Handler

Undef_Handler B Undef_Handler

SWI_Handler B SWI_Handler

PAbt_Handler B PAbt_Handler

DAbt_Handler B DAbt_Handler

IRQ_Handler B IRQ_Handler

;FIQ_Handler B FIQ_Handler

I am suspecting some problem in my asm file changes of FIQ HANDLER can any body suggest the cause of problem

regards
sumit

  • Your code contains duplicated functions, which you didn't notice.
    Your code isn't formatted as the posting instructions for the source code.
    Maybe you missed other important details too...

    By the way - you use FIQ. A high-priority handler for something really important. How important can it be if you then use:

    puts_gen("\n\r Timer interrupt generated",0);
    puts_gen("s",0);
    


    in your ISR? Don't you think an ISR should end quickly, to allow the processor to be able to service other - less prioritized - interrupts?

    Next thing: The processor can generate a continuous set of interrupts using the timer. So why is your FIQ handler containing:

    timer0_reset();
    timer0_start();
    

    Haven't you looked at the sample code already available both from Keil and from NXP? Does that code really reset and restart the timer in the interrupt service routine?