esp32 interrupt firing occasionally on it's own

Imstarboard
Posts: 4
Joined: Thu Sep 17, 2020 3:17 pm

esp32 interrupt firing occasionally on it's own

Postby Imstarboard » 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):

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

ESP_Sprite
Posts: 4260
Joined: Thu Nov 26, 2015 4:08 am

Re: esp32 interrupt firing occasionally on it's own

Postby ESP_Sprite » Tue Jan 12, 2021 6:49 am

Possibly if you use a pullup that is too high and cabling/traces that are too long, you're picking up EMF spikes.

Who is online

Users browsing this forum: No registered users and 4 guests