Interrupt and variable

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Interrupt and variable

1,152 次查看
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 项奖励
回复
1 回复

1,002 次查看
converse
Senior Contributor V

Do not use printf in your interrupt handler:

- it disables interrupts while running

- is very very slow

0 项奖励
回复