ESP32 Interrupt stops working while loop() code executes
Posted: Fri Feb 06, 2026 10:25 am
I use a ESP32 WROOM Devkit board using Arduino. The ESP32 is connected to a DS3231 RTC that interrupts the ESP once per second. However, if any procedure is called from the loop(), then the interrupt stops until the procedure has been completed. I am not sure if this is a coding problem or whether task priorities have not been defined sufficiently. For test purposes, I toggle a LED each time when the ISR is called. While the loop is executed, the LED flashes at the expected rate. No interrupt disable code is coded anywhere. However, as an example, when executing the kbGetMonth() procedure below, the LED stops blinking while that code is running, and resumes blinking when returning to the loop(). I am sure the presence of the LED code within the ISR does not create issues in itself. If I remove the LED code and print the seconds of the clock from within the loop(), the clock stops while executing any of the options within the switch{}. Code size is around 700 lines but here are some code snippets:
I have done extensive searches and reading around ESP32 interrupts, but I have not come across any useful knowledge. If anyone as any suggestion on how to fix the interrupt, I would be extremely thankful.
Thank you for your time, will
Code: Select all
#define Timer_int_PIN 13 // GPIO13
volatile bool timer_int = false; // DS3231 Timer 1 Hz interrupt signalling flag
volatile int seconds_since_interrupt = 0;
volatile bool LED_state;
void IRAM_ATTR isr_Timer1() { // This interrupt fires at a 1Hz rate
timer_int = true; // The IRAM_ATR neither causes or resolves the problem.
seconds_since_interrupt++;
LED_state = !LED_state;
digitalWrite(LED,LED_state);
return;
setup() {
attachInterrupt(Timer_int_PIN, isr_Timer1, FALLING);
}
void loop() { // Top section maintains an internal 24h clock
if (timer_int) { // If RTC 1Hz clock interrupt has been triggered then do timer service
DS3231RTC.checkIfAlarm(1); // Clear Alarm 1 flag in the RTC chip
timer_int = false; // reset timer interrupt flag
seconds_since_interrupt = 0;
if (tminfo.tm_sec > 59) { // each minute
tminfo.tm_sec = tminfo.tm_sec - 60; // in case the delay from interrupt to this code was > 1 sec and < 60 sec
tminfo.tm_min++;
if (tminfo.tm_min > 59) { // each hour
tminfo.tm_min = 0;
tminfo.tm_hour++;
if (tminfo.tm_hour > 23) { // each day at midnight
tminfo.tm_hour = 0; // Run a local 24h clock, updated from the RTC once a day
get_RTC_time(); // i.e. the RTC is only called once a day at midnight to update the time
}
}
}
} // end of timer interrupt service
if(BTPort.available()) { // BTPort is a serial connection over Bluetooth classic.
c = BTPort.read();
switch (c) {
// several other cases..... Here is one:
case 'm': kbGetMonth(); // Get month and year from BT terminal
extractMonthData(); // extract data from SD card
break;
} // switch
} // if BTPort
} // loop
Thank you for your time, will