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();
}
...
)