Open nneonneo opened 2 years ago
Hi @nneonneo , some time ago I prepared a hacky PR to target this issue https://github.com/arduino/ArduinoCore-mbed/pull/256 . Would you mind testing it and reporting if it could work for you?
@facchinm Tested - looks like it works for me. It'd be nice to have that merged!
Platform: Nano 33 BLE Sense Version: Arduino IDE 1.8.19, Arduino Mbed OS Nano Boards 2.8.0
attachInterrupt
incorrectly resets the mode of an input pin back to the default pull mode (INPUT_PULLUP
). This silently overrides an existingpinMode
declaration.This occurs because
attachInterrupt
callsattachInterruptParam
, which constructs anInterruptIn
object. Thembed::InterruptIn::InterruptIn(PinName)
constructor callsgpio_init_in
at the end, which reinitializes the target pin toPullDefault
.Steps to reproduce
Attach an input to pin 2 (e.g. button) which is high when active and high-z (disconnected) when inactive. Run the following sketch:
Expected behaviour: clicking or releasing the button toggles the builtin LED state Observed behaviour: clicking the button does nothing (because the input is now
INPUT_PULLUP
, so the active-high input of the button does nothing).Possible fix
One possible fix would be to simply reset the pin to the configured pin mode, if set, in
attachInterrupt
after using theInterruptIn
object. (If unset,attachInterrupt
already configures the pin with a default configuration).A workaround is to simply call
pinMode
afterattachInterrupt
; however, this goes against the usual way thatattachInterrupt
is used (even theattachInterrupt
example on the official documentation putspinMode
beforeattachInterrupt
).