Skip to content

[Observation] attachInterrupt reconfigures the pin, removing a pull-up and so triggers a falling interrupt #416

Open
@PaulZC

Description

@PaulZC

Sorry Kyle...

With v2.1.1 of the core, attachInterrupt re-configures the pin, removing a pull-up if one was present. If you're using a FALLING interrupt, then removing the pull-up causes the interrupt to trigger immediately.

Steps to reproduce:
RedBoard Artemis ATP.
Apollo3 v2.1.1.
Don't connect anything to pin 10. Leave it floating.
Run the following example:

void setup() {
  Serial.begin(115200);
  Serial.println(F("Apollo3 Interrupt Pull-Up Test"));

  pinMode(10, INPUT_PULLUP); // Put a pull-up on pin 10

  //Attach a falling interrupt to pin 10
  //This should never trigger thanks to the pull-up on pin 10 right?
  attachInterrupt(10, interruptHandler, FALLING);
}

void loop() {
}

void interruptHandler(void) {
  Serial.println(F("Interrupt!"));
}

If the pull-up on pin 10 remains enabled, the interrupt should never trigger. However, we get not one but two interrupts:

image

If we add a second call to pinMode(10, INPUT_PULLUP); after the attachInterrupt:

void setup() {
  Serial.begin(115200);
  Serial.println(F("Apollo3 Interrupt Pull-Up Test"));

  pinMode(10, INPUT_PULLUP); // Put a pull-up on pin 10

  //Attach a falling interrupt to pin 10
  //This should never trigger thanks to the pull-up on pin 10 right?
  attachInterrupt(10, interruptHandler, FALLING);

  pinMode(10, INPUT_PULLUP); // Re-enable the pull-up on pin 10
}

void loop() {
}

void interruptHandler(void) {
  Serial.println(F("Interrupt!"));
}

Then we still get the first interrupt - but not the second one:

image

I've got a work-around for this on OpenLog Artemis, which involves using the ISR to set a flag. I clear the flag after manually re-enabling the pull-up.

With v1.2.1, the first example does not trigger an interrupt:

image

Cheers,
Paul

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