10 years, 6 months ago.

I am trying to blink LED with interupt match but LED is not working

#include "mbed.h"

Serial pc(USBTX,USBRX);


DigitalOut myled(LED1);
void initpcon()

{    

    pc.printf("in pconp\n");

    LPC_SC->PCONP =(1<<1);////power up timr

    LPC_SC->PCLKSEL0 =(0<<2)|(0<<3); ////////cclk/4=25mhz;

}

void inittimer()

{ 
   pc.printf("intimer\n")
;
    LPC_TIM0->CTCR&=~(1<<0);////init timer

    LPC_TIM0->TCR=(1<<1);////RESET TIMER

    LPC_TIM0->PR=0;

    LPC_TIM0->MR0= 3124;

    LPC_TIM0->MCR=(1<<0);///ENABLE TIMER0 INTERRUPT 

 }

 void connect()

 { 
 pc.printf("in irq\n");

    LPC_TIM0->TCR=(1<<1);///RESET TIMER

    LPC_TIM0->TCR=(1<<0);/// ENABLE TIMER

    NVIC_EnableIRQ(TIMER0_IRQn);
   
 }
 void TIMER0_IRQHandler (void)

 {    
 pc.printf("in handler\n");

    /// LPC_TIM0->TCR=(1<<0);/// ENABLE TIMER

     while(LPC_TIM0->IR&0x01!=0x01);///wait till it matches the TC value of MRO

      myled=!myled;

     //LPC_PINCON->PINSEL3^=(1<<4); //// BLINK LED

     LPC_TIM0->MCR=(1<<1); //reset mcr
}
 int main()

 {
     initpcon();

     inittimer();
     
   while(1)

     {
       connect();

       pc.printf("in main\n");
      
 }

}  

why are you calling connect() all over again ?

posted by Martin Kojtal 28 May 2014

HOPING THAT EVERY TIME IT CALLS THE LED TO TOGGLE

posted by Ashok K 28 May 2014

hi can anyone pls tel me d problem in my code my led is not blinking

posted by Ashok K 29 May 2014

dont invoke connect all over again, most of its implementation is supposed to be executed just once. You don't register IRQ anywhere, just enabling IRQ.. Register your handler to timer IRQ. What about enablign interrupts in the timers register? is there any flag for that?

posted by Martin Kojtal 29 May 2014
Be the first to answer this question.

Assigned to Ashok K 10 years, 6 months ago.

This means that the question has been accepted and is being worked on.