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.

The short versionControlling whether a specific interrupt source (or all interrupts) can fire at all.

Theory in plain words

Two levels of interrupt enablingGlobal interruptenable (the whole…Per-source enable bit(this specific…Both must be enabledfor that specific…
Two levels of interrupt enabling

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

Checking both enable levels before concluding an interrupt should fireC: edit and run

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

Checking enable bits for 3 peripherals via one registerC: edit and run

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?