Skip to content

ESP32 GPIO Interrupt Not Firing

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about ESP32 GPIO Interrupt Not Firing. We cover key concepts, practical examples, and best practices.

The Problem

ESP32 GPIO interrupt attached to a pin does not trigger the ISR function.

Quick Fix

Wrong

attachInterrupt(4, myISR, RISING);  // ISR does nothing
No interrupt fires even when pin 4 sees rising edges.
volatile bool triggered = false;
void IRAM_ATTR myISR() {
  triggered = true;
}
pinMode(4, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(4), myISR, FALLING);
void loop() {
  if (triggered) {
    triggered = false;
    Serial.println("Interrupt fired");
  }
}
Interrupt fired
(Triggered on every falling edge at GPIO 4)

Prevention

Declare ISR as IRAM_ATTR to place in IRAM. Use digitalPinToInterrupt() to get the correct interrupt number. Keep ISR short and set a volatile flag. Use FALLING/RISING/CHANGE for edge detection. Avoid Serial.print() inside ISR.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### Why does my ISR crash the ESP32?

ISRs run in IRAM. Without IRAM_ATTR, the ISR may be placed in flash, causing cache miss crashes. Always add IRAM_ATTR to ISR functions.

What functions can I call in an ISR?

Only IRAM-safe functions: digitalWrite(), millis(), micros(). Do NOT call Serial, delay, yield, or malloc from ISR.

How many GPIO interrupts can I use?

ESP32 supports interrupts on all GPIOs. However, all GPIO interrupts share one interrupt slot. Use ESP_INTR_FLAG_IRAM for performance.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro