1

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 ?

DinhQC
  • 133
  • 10
Sadra Nasiri
  • 5
  • 1
  • 4
  • so correct me if I am wrong, long before you got to this point you first used the status register to see the timer roll over? then next you enabled the interrupt BUT DIDNT ALLOW IT THROUGH to the cpu, instead polled for it at the peripheral end of the VNIC, then learned how to clear the interrupt from the peripheral through to the vnic (each one of these experiments you polled and toggled the led successfully). – old_timer May 27 '17 at 02:25
  • Then eventually you allowed it through to the vnic, with either the right vector somehow (reading docs) or spammed the vector table with a handler that caught it then narrowed in by changing some of the vectors to to go a branch self or elsewhere? And now you are at this point? – old_timer May 27 '17 at 02:25
  • @old_timer yes exactly. – Sadra Nasiri May 27 '17 at 12:52
  • then you are done, it works... – old_timer May 28 '17 at 19:35
  • What happens to `flag` in `TIMER0_RIQHandler` when `flag == 1`? – Jeff Jun 25 '19 at 14:43

1 Answers1

1

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.

DinhQC
  • 133
  • 10