Interrupts and ISRs
Hardware events pause the main program and run a short Interrupt Service Routine immediately.
Intermediate
Sources include timers, GPIO edges, UART bytes received and ADC conversions complete.
volatile uint32_t ticks = 0;
void SysTick_Handler(void) { // runs every 1 ms
ticks++;
}
Rules for ISRs:
- keep them short — set a flag, store data, return;
- mark shared variables volatile;
- protect multi-byte shared data from being read half-updated (disable interrupts briefly or use atomics);
- never use blocking calls (
delay,printf) inside them.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.