Interrupt variables...

23 Aug 2011

So I have this code (smaller part of my program)

#include "mbed.h"

volatile uint32_t systick=0;

extern "C" void RIT_IRQHandler()
{
    //update counter
    systick++;
    
    //clear flag
    LPC_RIT->RICTRL |= (1<<0);
}

int main(void)
{
    //initialize timer
    LPC_SC->PCONP |= (1<<16);             //power up RIT clock
    LPC_SC->PCLKSEL1 |= (3<<26);          //run RIT clock by 12MHz (prescale by 8)
    LPC_RIT->RICOUNTER = 0;               //set counter to zero
    LPC_RIT->RICOMPVAL = 12000000;        //interrupt tick every second
    LPC_RIT->RICTRL |= (1<<1) | (1<<3);   //enable timer clear on match

    //enable interrupt
    NVIC_EnableIRQ(RIT_IRQn);

    while(1) {
      wait(5.0);
      printf("%d\r\n", systick);
    }
}

interrupt works fine, only problem is, systick is incremented twice.

1st printf - systick=10

2st printf - systick=20

etc...

I don't see any reason why my program is behaving as such

23 Aug 2011

Hi,

Try this in your interrupt handler:

extern "C" void RIT_IRQHandler()
{
    //clear flag
    LPC_RIT->RICTRL |= (1<<0);

    //update counter
    systick++;
}
23 Aug 2011

wow, it works. thanks

but i don't get why it behaves like that