Interrupt and variable

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Interrupt and variable

679 Views
svip
Contributor I

Hi to all, i am new with lpcxpresso and i have a simple question

i would like change the value of a variable during an interrupt but the interrupt function is void, for this reason i try to use extern volatile variable but it seems not work

this is the code

extern volatile uint64_t counter_1=0;


void RIT_IRQHandler(void)
{


/* Clear interrupt */
Chip_RIT_ClearIntStatus(LPC_RITIMER);

counter_1=counter_1+1;
printf(" counter_1 vale %d \n",counter_1);

Board_LED_Toggle(1);

}


/**
* @brief Main entry point
* @return Nothing
*/
int main(void)
{

/* Generic Initialization */
SystemCoreClockUpdate();
Board_Init();

/* Initialize RITimer */
Chip_RIT_Init(LPC_RITIMER);

/* Configure RIT for a periodic interrupt tick rate */
Chip_RIT_SetTimerIntervalHz(LPC_RITIMER, TIME_INTERVAL);
Chip_RIT_Enable(LPC_RITIMER);


NVIC_EnableIRQ(RITIMER_IRQn);

/* LED is toggled in interrupt handler */
while (1) {
/* Sleep between interrupts */
__WFI();
}
}

i would like increment the variable counter_1 every time an interrupt occours but it seems not work

thx you

0 Kudos
1 Reply

529 Views
converse
Senior Contributor V

Do not use printf in your interrupt handler:

- it disables interrupts while running

- is very very slow

0 Kudos