Sadra Nasiri
Sadra Nasiri

Reputation: 5

ARM timers and interrupts

I'm going to learn how to work with timers and interrupts using ARM micro-controllers. This is my code:

 #include "LPC17xx.h"
 int flag=0;   

 void TIMER0_RIQHandler(void)
 {
    if (flag == 0 )
    {
       LPC_GPIO1 -> FIOSET = 1 «28;              //turn on LED 
       flag =1;
    }
    else 
    {
       LPC_GPIO1 -> FIOCLR = 1 «28;              //turn off LED
       flag=1;
    }
    LPC_TIM0 -> IR = 1 ;               //clear interrupt flag
 }


 int main()
 {
    LPC_TIM0 -> CTCR = 00;                     //set timer mode
    LPC_TIM0 -> PR = 1;
    LPC_TIM0 -> MR0 = 12000000;
    LPC_TIM0 ->  MCR = 3 ;               //IF PC REACHES PR, TC will BE 
                                      //RESET AND INTERRUPT WILL BE GENERATE
    LPC_TIM0 -> TCR = 2;                         //RESET TIMER

    NVIC_SetPriority(TIMER0_IRQn , 0 );
    NVIC_EnableIRQ(TIMER0_IRQn);  
    LPC_TIM0 ->TCR = 1;                        //ENABLE TIMER

    LPC_GPIO1 -> FIODIR = 1 « 28 ; 
    LPC_GPIO1 -> FIOCLR = 1 « 28 ; 
    while (1)
    {
    }
 }

it's supposed to turn on and turn off the LED every sec. at the first the LED turns off but interrupt doesn't work. what is wrong with my code ?

Upvotes: 1

Views: 2463

Answers (1)

DinhQC
DinhQC

Reputation: 133

The name of your Interrupt Service Routine (ISR) is not correct. I believe it should be TIMER0_IRQHandler. It should match the name that appears in the startup file startup_LPC17xx.s

Because of this mismatch, the interrupt is triggered, but there is no corresponding ISR to be called.

Upvotes: 1

Related Questions