Skip to content

Arduino Giga attachInterrupt() resets pinMode Pullup/Pulldown #780

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

Open
N9W9 opened this issue Nov 28, 2023 · 2 comments
Open

Arduino Giga attachInterrupt() resets pinMode Pullup/Pulldown #780

N9W9 opened this issue Nov 28, 2023 · 2 comments

Comments

@N9W9
Copy link

N9W9 commented Nov 28, 2023

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:

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++;
}
@rchesterr
Copy link

Hit the same issue, as above moving pinmode after attachinterrupt fixes this pullup issue, but means the activation of the pull-up (or down) can cause an interrupt.

@facchinm
Copy link
Member

This is being tackled by this PR #256 , but was never merged due to the inefficiency of the solution. Any idea is appreciated 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants