I’m trying to reproduce your problem in a minimal example but it won’t crash.
#include <Arduino.h>
#include <ESP32TimerInterrupt.h>
#define TIMER0_INTERVAL_MS 1
volatile int32_t encoderValueleft;
volatile int32_t encoderValueright;
ESP32Timer ITimer0(0);
void IRAM_ATTR sub_function_1() {
encoderValueleft += 1;
}
void IRAM_ATTR sub_function_2() {
encoderValueright += 1;
}
void IRAM_ATTR TimerHandler0(void)
{
sub_function_1();
sub_function_2();
}
void setup()
{
Serial.begin(115200);
Serial.println("CPU Frequency in MHZ:");
Serial.println(getCpuFrequencyMhz());
// Timer setup
ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0);
}
void loop()
{
Serial.println("Still alive, left = " + String(encoderValueleft) + " right = " + String(encoderValueright));
delay(1000);
}
has serial output
CPU Frequency in MHZ:
240
Still alive, left = 0 right = 0
Still alive, left = 1000 right = 1000
Still alive, left = 2000 right = 2000
Still alive, left = 3000 right = 3000
Exactly as I expect.
That is, I can call sub-functions from the ISR just fine when they’re marked with IRAM_ATTR
.
Let me try reconstructing your code.