esp32 interrupt firing occasionally on it's own

Imstarboard
Posts: 5
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: 4444
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: 5
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!

WardMas
Posts: 40
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 hardware tutorials
https://www.youtube.com/channel/UC5zdou ... subscriber

ESP_Sprite
Posts: 4444
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

Who is online

Users browsing this forum: No registered users and 49 guests