esp32 interrupt firing occasionally on it's own
Posted: Tue Jan 12, 2021 3:06 am
I have assigned an interrupt to a switch, and the code works perfectly, except every few days the interrupt code gets triggered when the switch has not been pressed.
What could cause an interrupt to fire on it's own? I would think this might be hardware related, but it seems to be an issue on more than 1 dev board.
Here are the relevant snippets of code that handle the interrupt (using Arduino IDE):
What could cause an interrupt to fire on it's own? I would think this might be hardware related, but it seems to be an issue on more than 1 dev board.
Here are the relevant snippets of code that handle the interrupt (using Arduino IDE):
Code: Select all
const uint8_t PIN = 18;
volatile bool pressDetected = false;
portMUX_TYPE synch = portMUX_INITIALIZER_UNLOCKED;
...
// callback for switch - bound to hardware interrupt
void IRAM_ATTR clickDetected() {
portENTER_CRITICAL(&synch);
pressDetected = true;
portEXIT_CRITICAL(&synch);
}
...
setup(
...
// Init interrupt for button click
pinMode(PIN, INPUT_PULLUP);
attachInterrupt(PIN, clickDetected, CHANGE);
...
)
loop(
...
if (pressDetected) { // moving code from interrupt handler to main loop here
pressDetected = false;
mySwitch.newClick();
}
...
)