Home / Learn Embedded C / Enabling and Disabling Interrupts
Enabling and Disabling Interrupts
Controlling whether a specific interrupt source (or all interrupts) can fire at all.
Theory in plain words
The basic idea
Interrupts must be explicitly enabled (both globally, and individually per source) before they will fire — this is a safety measure so a chip does not start reacting to events before the program is ready to handle them.
Why this comes up
A common early bug is configuring a peripheral correctly but forgetting to enable its specific interrupt (or forgetting to globally enable interrupts at all) — the hardware event happens, but nothing reacts to it.
The mechanics
Enabling typically involves two separate steps: a global interrupt enable (sometimes one CPU instruction) and a per-peripheral/per-source enable bit in that peripheral's own control register — both must be set.
Where it is used
- Peripheral interrupt setup
- Debugging "interrupt never fires" bugs
- Startup/initialization code
Try it
Here the global switch is on but the per-source bit is off, exactly the common "forgot to enable this one peripheral's interrupt" bug.
Try it: enabling several sources at once with a bitmask
Real hardware often packs many per-source enable bits into one register; source 1 (gpio1) stays disabled here since its bit was never set.
Quick check
1. Why is it common to need to enable interrupts at two separate levels?
Most chips have both an overall interrupt-enable switch and individual enable bits for each specific interrupt source — missing either one means that interrupt never fires.