Skip to content

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

Open
@N9W9

Description

@N9W9

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++;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions