Arduino-esp32: analogRead() triggers unrelated interrupt

Created on 28 Jul 2017  路  2Comments  路  Source: espressif/arduino-esp32

I am experiencing a strange bug:

Whenever i use analogRead(), an unrelated interrupt will also trigger, and by changing around a little i could even get 2 interrupts to trigger with every analogRead().

I have not testet every analog pin, but so far this bug happens with A0, A3, A4, A5, A6, A7, but not A10, A11, A12, A13, A14.

I can reproduce the issue with the code below - every 2 seconds it will trigger AnalogRead() and this will trigger one of the button Interrupts. I have have multiple components hooked up as well, but this did not seem to change anything when i tried removing some of them, or having the button GPIOs unconnected.

const int BUTTON_1 = 25;
const int BUTTON_2 = 26;

void setup() 
{
  pinMode(BUTTON_1, INPUT_PULLUP);  
  pinMode(BUTTON_2, INPUT_PULLUP);

  attachInterrupt(BUTTON_1, int1, FALLING);
  attachInterrupt(BUTTON_2, int2, FALLING);

  Serial.begin(115200);
}

void loop() 
{
  delay(2000);  
  float derp = analogRead(A3);  
  Serial.println(derp);
}

void int1() 
{
  Serial.println("1 Interrupt triggered");
}

void int2() 
{
  Serial.println("2 Interrupt triggered");
}
for reference

Most helpful comment

Hey
Tried the code you posted along with just the board, and yes, the interrupts are being triggered.
If you're looking for a workaround
Change the Pull type to PULLDOWN (and of course you should change the button trigger from GND to Vcc since it's pulled down)

I tried with Pulldown and the problem is solved.

  pinMode(BUTTON_1, INPUT_PULLDOWN);
  pinMode(BUTTON_2, INPUT_PULLDOWN);

Also, maybe you already know this , but just in case, it's never good to Serial.println() inside of an ISR. The best idea would be to update a volatile bool inside of ISR and based on the bool, print in void loop()

All 2 comments

Hey
Tried the code you posted along with just the board, and yes, the interrupts are being triggered.
If you're looking for a workaround
Change the Pull type to PULLDOWN (and of course you should change the button trigger from GND to Vcc since it's pulled down)

I tried with Pulldown and the problem is solved.

  pinMode(BUTTON_1, INPUT_PULLDOWN);
  pinMode(BUTTON_2, INPUT_PULLDOWN);

Also, maybe you already know this , but just in case, it's never good to Serial.println() inside of an ISR. The best idea would be to update a volatile bool inside of ISR and based on the bool, print in void loop()

Had this issue as well, the workaround works 馃憤 Very weird that this is still happening though

Was this page helpful?
0 / 5 - 0 ratings