Page 1 of 1

esp32 interrupt firing occasionally on it's own

Posted: Tue Jan 12, 2021 3:06 am
by Imstarboard
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();
  }
...
)

Re: esp32 interrupt firing occasionally on it's own

Posted: Tue Jan 12, 2021 6:49 am
by ESP_Sprite
Possibly if you use a pullup that is too high and cabling/traces that are too long, you're picking up EMF spikes.

Re: esp32 interrupt firing occasionally on it's own

Posted: Fri Feb 19, 2021 9:14 pm
by Imstarboard
I have spent quite a bit of time troubleshooting this issue and I still am looking for suggestions. Here's what I have done:

I replaced the switch with the another more reliable one.

I have tried using a different GPIO port.

I replaced the internal pullup with an external resistor pullup, and also tried the pulldown configuration.

The wire to the pin is short, so I was not suspecting interference. Regardless, I tried reducing the resistance to 10k and also to 5k, and also later attached a 100 resistor to the positive lead, but none of that had any effect, so interference does not appear to be the issue.

I can't instigate false triggering by wiggling any of the connections, so I am pretty sure it is not the soldering. Another reason I don't suspect the soldering is that the false triggering happens when the unit has been on a solid, stable surface and not disrupted in any way.

I have also tried changing the function call:

Code: Select all

attachInterrupt(mySwitch.PIN, clickDetected, RISING);
to

Code: Select all

attachInterrupt(digitalPinToInterrupt(mySwitch.PIN), clickDetected, RISING);
I have tried with and without using these:

Code: Select all

volatile bool pressDetected = false;
  portMUX_TYPE synch = portMUX_INITIALIZER_UNLOCKED;

None of the things I have tried changes the false triggering pattern at all (they are random, sometimes not happening for hours or days, sometimes happening several times an hour, and when they happen, sometimes they happen in < 10ms, sometimes they occur over 400ms).

I am using ESP32 ESP-32S Dev Boards ( https://www.amazon.com/gp/product/B08BYJR9Y4 )

ANY other thoughts here?

Thanks!

Re: esp32 interrupt firing occasionally on it's own

Posted: Fri Feb 26, 2021 5:11 am
by WardMas
Hi,
I can suggest you applying button debounce algorithm inside your interrupt routine before taking any action. I know this sounds like a shady solution and not permanent.

Re: esp32 interrupt firing occasionally on it's own

Posted: Sun Mar 07, 2021 6:30 am
by ESP_Sprite
Moved documentation -> general discussion

Re: esp32 interrupt firing occasionally on it's own

Posted: Mon Apr 12, 2021 11:24 am
by mars000
I'm having same problem.
I find on PlatformIO ESP32 Arduino version 2.1.0 it works perfectly i.e. interrupt fires correctly
However, version 3.0.0 or > fire at random. I don't understand it - did some new code get included that changed things....its a big problem.

Re: esp32 interrupt firing occasionally on it's own

Posted: Mon Mar 14, 2022 10:01 am
by dynek=
Just had that very same issue, trying to investigate with a scope but either it's really random or as soon as I plug the scope it doesn't happen anymore :lol:

Edit: there we go!
SDS00022.png
SDS00022.png (14.85 KiB) Viewed 4945 times
SDS00023.png
SDS00023.png (15.84 KiB) Viewed 4945 times