arduino / arduino/ArduinoCore-mbed
Arduino Giga attachInterrupt() resets pinMode Pullup/Pulldown
- Dominant language
- C
- Stars
- 411
- Forks
- 225
- PR merge metrics
- No merged PRs in 30d
Description
When using the attachInterrupt() function set Pullups/Pulldowns are reset, the Pin is left floating.
When setting the pinMode after attaching the interrupt, it does work fine. However this is inconsistent with most examples which set the pinMode before attaching the Interrupt (e.g. https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/; also on the Arduino Giga Cheat Sheet)
It is also inconsistent with Arduino Mega, where the pinMode does not get reset after the attachInterrupt() call.
Example Code:
``` cpp
volatile int count = 0;
const byte pin = 2;
void setup() {
Serial.begin(9600);
//pinMode(pin, INPUT_PULLDOWN); // Setting the Pin Mode here does not work!
attachInterrupt(digitalPinToInterrupt(pin), ISR_count, RISING);
pinMode(pin, INPUT_PULLDOWN); // Pin Mode has to be set after the attachInterrupt()
delay(100);
Serial.println("Start");
}
void loop() {
Serial.println(String("Pin State: ") + digitalRead(pin) + String(" Interrupt Count: ") + count);
}
void ISR_count() {
count++;
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the provided Arduino Giga sketch, focusing on the order of attachInterrupt() and pinMode() with INPUT_PULLDOWN. Trace the attachInterrupt() and pinMode() entry points used by this core and compare the behavior with Arduino Mega. Done means pull-up and pull-down settings remain intact when pinMode() is called before attachInterrupt().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100