Skip to content

ESP32 Timer Interrupt ISR Causes Crash

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about ESP32 Timer Interrupt ISR Causes Crash. We cover key concepts, practical examples, and best practices.

The Problem

ESP32 timer ISR crashes the system due to long operations or missing IRAM attributes.

Quick Fix

Wrong

void onTimer(void* arg) {
  Serial.println("Tick");  // Serial not safe in ISR!
}
Guru Meditation Error. Core panic. CPU halted.
volatile bool timerFired = false;
void IRAM_ATTR onTimer(void* arg) {
  timerFired = true;
  timer_group_clr_intr_status_in_isr(TIMER_GROUP_0, TIMER_0);
  timer_ll_set_raw_counter_value(TIMER_GROUP_0, TIMER_0, 0);
}
void loop() {
  if (timerFired) {
    timerFired = false;
    Serial.println("Tick");  // Safe outside ISR
  }
}
Tick
Tick
Tick
(ISR fires every second without crashing)

Prevention

Declare ISR with IRAM_ATTR. Clear interrupt flag in ISR. Keep ISR minimal (set flag only). Handle data in main loop. Do NOT call Serial, delay, malloc, or WiFi in ISR.

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

FAQ

### Why does my timer ISR crash?

Missing IRAM_ATTR causes flash cache miss. Calling non-IRAM functions (Serial, WiFi, Flash reads) causes panic in ISR context.

What can I safely do in a timer ISR?

Set volatile flags, increment counters, read GPIO, clear interrupt status. Nothing that accesses flash (strings, printf, Serial).

How do I clear the timer interrupt?

Call timer_group_clr_intr_status_in_isr(group, timer) inside the ISR. Otherwise the interrupt fires continuously.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro