esp32 interrupt firing occasionally on it's own

Imstarboard
Posts: 6
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: 9715
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.

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

Re: esp32 interrupt firing occasionally on it's own

Postby Imstarboard » Fri Feb 19, 2021 9:14 pm

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!

User avatar
WardMas
Posts: 75
Joined: Fri Jun 19, 2020 9:09 am

Re: esp32 interrupt firing occasionally on it's own

Postby WardMas » Fri Feb 26, 2021 5:11 am

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.
You can always visit my YouTube channel for embedded systems related tutorials
https://youtube.com/user/wardzx1

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

Re: esp32 interrupt firing occasionally on it's own

Postby ESP_Sprite » Sun Mar 07, 2021 6:30 am

Moved documentation -> general discussion

mars000
Posts: 1
Joined: Mon Apr 12, 2021 11:20 am

Re: esp32 interrupt firing occasionally on it's own

Postby mars000 » Mon Apr 12, 2021 11:24 am

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.

dynek=
Posts: 7
Joined: Thu Aug 27, 2020 11:28 am

Re: esp32 interrupt firing occasionally on it's own

Postby dynek= » Mon Mar 14, 2022 10:01 am

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 4935 times
SDS00023.png
SDS00023.png (15.84 KiB) Viewed 4935 times

Who is online

Users browsing this forum: Baidu [Spider] and 289 guests