-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interrupt functions cause a double Arduino pin -> GPIO pin number conversion #10367
Closed
1 task done
Labels
Status: Awaiting triage
Issue is waiting for triage
Comments
pillo79
added a commit
to arduino/arduino-esp32
that referenced
this issue
Sep 23, 2024
The digitalPinToInterrupt() macro currently remaps the pin number to the GPIO number. This is not necessary, as most users will then use the returned value in attachInterrupt() or other similar API functions, which already perform the same remapping. The first half of the macro (the condition) does indeed require the remapping to ensure the check operates on GPIO numbers. Fixes espressif#10367.
pillo79
added a commit
to pillo79/arduino-esp32
that referenced
this issue
Sep 25, 2024
The digitalPinToInterrupt() macro currently remaps the pin number to the GPIO number. This is not necessary, as most users will then use the returned value in attachInterrupt() or other similar API functions, which already perform the same remapping. The first half of the macro (the condition) does indeed require the remapping to ensure the check operates on GPIO numbers. Fixes espressif#10367.
pillo79
added a commit
to pillo79/arduino-esp32
that referenced
this issue
Sep 25, 2024
The digitalPinToInterrupt() macro currently remaps the pin number to the GPIO number. This is not necessary, as most users will then use the returned value in attachInterrupt() or other similar API functions, which already perform the same remapping. The first half of the macro (the condition) does indeed require the remapping to ensure the check operates on GPIO numbers. Fixes espressif#10367.
This was referenced Sep 25, 2024
me-no-dev
pushed a commit
that referenced
this issue
Sep 25, 2024
The digitalPinToInterrupt() macro currently remaps the pin number to the GPIO number. This is not necessary, as most users will then use the returned value in attachInterrupt() or other similar API functions, which already perform the same remapping. The first half of the macro (the condition) does indeed require the remapping to ensure the check operates on GPIO numbers. Fixes #10367.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Board
Arduino Nano ESP32
Device Description
N/A
Hardware Configuration
N/A
Version
IDE Name
Arduino IDE, Arduino CLI
Operating System
N/A
Flash frequency
N/A
PSRAM enabled
yes
Upload speed
N/A
Description
The first parameter of the
attachInterrupt
function is an interrupt number. ThedigitalPinToInterrupt
function can be used to derive the interrupt number from the Arduino pin number. So it is common to use the two functions together. For example:attachInterrupt(digitalPinToInterrupt(interruptPin), interruptISR, CHANGE);
Arduino pin numbers are arbitrary integers used to reference an I/O pin in Arduino code. The Arduino pin number has traditionally been mapped to the low level pin identifiers (which won't necessarily have any direct correlation to the pin number) by the core variant. When this platform was created, that standard approach was abandoned and the low level GPIO numbers were used as Arduino pin numbers, forcing any mapping to be done via macros (e.g.,
D2
). When support for the Nano ESP32 board was added to the platform, it was necessary to implement support for true Arduino pin numbers, while also retaining the GPIO system. This was done in some cases by passing the pin number argument of functions through adigitalPinToGPIONumber
conversion function.The
digitalPinToInterrupt
function passes the pin number argument todigitalPinToGPIONumber
, which is appropriate:arduino-esp32/cores/esp32/Arduino.h
Line 145 in 7018cd1
The
attachInterrupt
function passes the interrupt number argument todigitalPinToGPIONumber
:arduino-esp32/cores/esp32/io_pin_remap.h
Line 44 in 7018cd1
🐛 This causes the interrupt number to be treated as an Arduino pin number, and that pin number converted to a GPIO number. In the case where the Arduino pin number is different from the GPIO number, this causes the interrupt to be attached to a different pin than the one the user intended.
Sketch
🐛 Nothing is printed in Serial Monitor, indicating that the interrupt was not triggered even though the sketch code should have attached it to Arduino pin 2.
🐛 "
interrupt triggered
" is printed in Serial Monitor, even though the sketch code should not have attached the interrupt to Arduino pin 5.Debug Message
N/A
Other Steps to Reproduce
I provided instructions for reproducing the fault in the "Sketch" section above.
Additional context
This was previously reported at #10209, but the reporter closed that issue after they found a workaround, even though the bug was not fixed.
CC: @pillo79
Additional reports
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: