Site icon Elektrologi

Error pada ESP32: Guru Meditation Error: Core 1 panic’ed (Interrupt wdt timeout on CPU1).

Salah satu pesan kesalahan yang dapat muncul pada ESP32 adalah “Guru Meditation Error: Core 1 panic’ed (Interrupt wdt timeout on CPU1)”. Salah satu penyebabnya adalah memanggil Serial.print() dari interupsi

Berikut ini pesan kesalahan yang muncul pada ESP32

Guru Meditation Error: Core  1 panic'ed (Interrupt wdt timeout on CPU1). 
 
Core  1 register dump:
 PC      : 0x4008ab86  PS      : 0x00060535  A0      : 0x80089afe  A1      : 0x3ffbf19c  
 A2      : 0x3ffbd448  A3      : 0x3ffbd2d8  A4      : 0x00000004  A5      : 0x00060523  
 A6      : 0x00060523  A7      : 0x00000001  A8      : 0x3ffbd2d8  A9      : 0x00000018  
 A10     : 0x3ffbd2d8  A11     : 0x00000018  A12     : 0x00000004  A13     : 0x00060523  
 A14     : 0x007bf318  A15     : 0x003fffff  SAR     : 0x0000000a  EXCCAUSE: 0x00000006  
 EXCVADDR: 0x00000000  LBEG    : 0x400863f9  LEND    : 0x40086409  LCOUNT  : 0xfffffffe  
 Core  1 was running in ISR context:
 EPC1    : 0x400db223  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x00000000
 
 
 Backtrace: 0x4008ab83:0x3ffbf19c |<-CORRUPTED
 
 
 Core  0 register dump:
 PC      : 0x4008ad1b  PS      : 0x00060035  A0      : 0x80089727  A1      : 0x3ffbea3c  
 A2      : 0x3ffbf318  A3      : 0xb33fffff  A4      : 0x0000abab  A5      : 0x00060023  
 A6      : 0x00060021  A7      : 0x0000cdcd  A8      : 0x0000abab  A9      : 0xffffffff  
 A10     : 0x3ffc1f58  A11     : 0x00000000  A12     : 0x3ffc1f54  A13     : 0x00000007  
 A14     : 0x007bf318  A15     : 0x003fffff  SAR     : 0x0000001d  EXCCAUSE: 0x00000006  
 EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  
 
 
 Backtrace: 0x4008ad18:0x3ffbea3c |<-CORRUPTED
 
 
 
 
 ELF file SHA256: e85d33667e5fa1a7
 
 Rebooting...

Berikut ini contoh program yang menyebabkan kesalahan tersebut.

// https://www.arduino.cc/reference/en/libraries/esp32timerinterrupt/
#define LED_BUILTIN 22

hw_timer_t *My_timer = NULL;

int kerja_counter = 0;
int print_job = 0;
long int timer_delay = 1000000L;  // clock timer= 1 MHz

void IRAM_ATTR onTimer() {
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  kerja_counter++;
  Serial.print("Test ");
  Serial.println(kerja_counter); // bad practice
}

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  Serial.begin(115200);
  Serial.print(__FILE__);
  Serial.print(F("\nStarting TimerInterruptTest on "));
  Serial.println(ARDUINO_BOARD);
  Serial.print(F("CPU Frequency = "));
  Serial.print(F_CPU / 1000000);
  Serial.println(F(" MHz"));
  pinMode(LED_BUILTIN, OUTPUT);
  My_timer = timerBegin(0, 80, true);  // prescaler
  timerAttachInterrupt(My_timer, &onTimer, true);
  timerAlarmWrite(My_timer, timer_delay, true);
  timerAlarmEnable(My_timer);  //Just Enable
}

// the loop function runs over and over again forever
void loop() {
}

Solusi: Serial.print() dipanggil dari fungsi loop(), sedangkan interupsi hanya mempersiapkan datanya saja, atau menaruh data ke dalam suatu FIFO buffer.

Berikut ini contoh hasil modifikasi program di atas.

// https://www.arduino.cc/reference/en/libraries/esp32timerinterrupt/
#define LED_BUILTIN 22

hw_timer_t *My_timer = NULL;

int kerja_counter = 0;
int print_job = 0;
long int timer_delay = 1000000L;  // clock timer= 1 MHz

void IRAM_ATTR onTimer() {
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  kerja_counter++;
  print_job=1;
}

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  Serial.begin(115200);
  Serial.print(__FILE__);
  Serial.print(F("\nStarting TimerInterruptTest on "));
  Serial.println(ARDUINO_BOARD);
  Serial.print(F("CPU Frequency = "));
  Serial.print(F_CPU / 1000000);
  Serial.println(F(" MHz"));

  pinMode(LED_BUILTIN, OUTPUT);

  My_timer = timerBegin(0, 80, true);  // prescaler
  timerAttachInterrupt(My_timer, &onTimer, true);
  timerAlarmWrite(My_timer, timer_delay, true);
  timerAlarmEnable(My_timer);  //Just Enable
  sei();
}

// the loop function runs over and over again forever
void loop() {
  if (print_job == 1) {
    print_job = 0;
    Serial.print("Test ");
    Serial.println(kerja_counter);   
  }
}
Exit mobile version