I am trying to add interrupt with my esp32 and came across the following example from Arduino IDE (under esp32 section)
Here is the example code
#include <Arduino.h>
struct Button {
const uint8_t PIN;
uint32_t numberKeyPresses;
bool pressed;
};
Button button1 = {23, 0, false};
Button button2 = {18, 0, false};
void IRAM_ATTR isr(void* arg) {
Button* s = static_cast<Button*>(arg);
s->numberKeyPresses += 1;
s->pressed = true;
}
void IRAM_ATTR isr() {
button2.numberKeyPresses += 1;
button2.pressed = true;
}
void setup() {
Serial.begin(115200);
pinMode(button1.PIN, INPUT_PULLUP);
attachInterruptArg(button1.PIN, isr, &button1, FALLING);
pinMode(button2.PIN, INPUT_PULLUP);
attachInterrupt(button2.PIN, isr, FALLING);
}
void loop() {
if (button1.pressed) {
Serial.printf("Button 1 has been pressed %u times\n", button1.numberKeyPresses);
button1.pressed = false;
}
if (button2.pressed) {
Serial.printf("Button 2 has been pressed %u times\n", button2.numberKeyPresses);
button2.pressed = false;
}
static uint32_t lastMillis = 0;
if (millis() - lastMillis > 10000) {
lastMillis = millis();
detachInterrupt(button1.PIN);
}
}
Guru Meditation Error: Core 1 panic'ed (Coprocessor exception)
Core 1 register dump:
PC : 0x40080f72 PS : 0x00060231 A0 : 0x800810f8 A1 : 0x3ffbeab0
A2 : 0x3ffbff14 A3 : 0x00000001 A4 : 0x00000000 A5 : 0x00000000
A6 : 0x00000003 A7 : 0x3ffb83ac A8 : 0x80080f6f A9 : 0x3ffbeb50
A10 : 0x0000000c A11 : 0x00000005 A12 : 0x8008a2b5 A13 : 0x3ffb1e40
A14 : 0x3ffb8000 A15 : 0x00000000 SAR : 0x0000000a EXCCAUSE: 0x00000004
EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff
Core 1 was running in ISR context:
EPC1 : 0x40080f72 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x400844bb
ELF file SHA256: 0000000000000000
Backtrace: 0x40080f72:0x3ffbeab0 0x400810f5:0x3ffbeb70 0x400810f5:0x3ffbeba0 0x400842a1:0x3ffbebc0 0x4000bfed:0x3ffb1ee0 0x40087da1:0x3ffb1ef0 0x40082cc7:0x3ffb1f10 0x400d3382:0x3ffb1f30 0x400d3399:0x3ffb1f60 0x400d1143:0x3ffb1f80 0x400d49be:0x3ffb1fb0 0x40086c69:0x3ffb1fd0
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
-spd-
Guru Meditation Error: Core 1 panic'ed (Coprocessor exception)
Core 1 register dump:
PC : 0x40080f72 PS : 0x00060231 A0 : 0x800810f8 A1 : 0x3ffbeab0
A2 : 0x3ffbff14 A3 : 0x00000001 A4 : 0x00000000 A5 : 0x00000000
A6 : 0x00000003 A7 : 0x3ffb83ac A8 : 0x80080f6f A9 : 0x3ffbeb50
A10 : 0x0000000c A11 : 0x00000005 A12 : 0x8008a2b5 A13 : 0x3ffb1e40
A14 : 0x3ffb8000 A15 : 0x00000000 SAR : 0x0000000a EXCCAUSE: 0x00000004
EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff
Core 1 was running in ISR context:
EPC1 : 0x40080f72 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x400844bb
ELF file SHA256: 0000000000000000
Backtrace: 0x40080f72:0x3ffbeab0 0x400810f5:0x3ffbeb70 0x400810f5:0x3ffbeba0 0x400842a1:0x3ffbebc0 0x4000bfed:0x3ffb1ee0 0x40087da1:0x3ffb1ef0 0x40082cc7:0x3ffb1f10 0x400d3382:0x3ffb1f30 0x400d3399:0x3ffb1f60 0x400d1143:0x3ffb1f80 0x400d49be:0x3ffb1fb0 0x40086c69:0x3ffb1fd0
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8```
type or paste code here