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.

Quick summaryWhy 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

A UART-receive-style ISR deferring to the main loopC: edit and run

The ISR itself does almost nothing — all the real work (here, just a printf) happens safely in the main loop afterward.

Careful:Never call blocking functions (like a long delay, or anything that waits for another interrupt) from inside an ISR — this can deadlock the system or cause missed interrupts elsewhere.

Try it: checking an ISR's measured duration against a budget

Deciding whether an ISR is too long and must defer more workC: edit and run

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?