Home / Learn Embedded C / Keeping ISRs Short
Keeping ISRs Short
Why an ISR should do the absolute minimum, and defer real work to the main loop.
How to think about this
What it is
Keeping ISRs short means doing only the absolute minimum inside the handler (reading a value, setting a flag, pushing to a queue) and deferring any real processing to the main loop or a dedicated task, which runs with interrupts re-enabled.
Why it matters
A long ISR blocks lower (and sometimes equal) priority interrupts from running for its entire duration — a UART ISR that takes too long could cause the next incoming byte to be lost while it is still busy with the previous one.
Mechanically speaking
The standard pattern is: ISR does the minimal, time-critical hardware interaction (read a register, clear a flag) and sets a flag or pushes data to a buffer; a corresponding main-loop check (or a separate task) picks up that flag/data and does the actual, possibly slow, processing.
Shows up in
- UART/SPI/I2C reception
- Any interrupt-driven data handling
- Responsive multi-source interrupt design
Try it
The ISR itself does almost nothing — all the real work (here, just a printf) happens safely in the main loop afterward.
Try it: checking an ISR's measured duration against a budget
Measuring an ISR against an explicit cycle budget is how teams catch an ISR that has grown too long before it starts causing missed interrupts.
Check yourself
1. What is the standard pattern for handling real work triggered by an interrupt?
This "minimal ISR, deferred processing" pattern keeps interrupt response fast while still getting the real work done, just slightly later in the main loop.