Skip to content
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

attachInterrupt() should clear EIC INTFLAG or prior events will cause an interrupt #348

Open
mweber-ovt opened this issue Aug 16, 2018 · 1 comment

Comments

@mweber-ovt
Copy link

Consider the following pseudocode:
attachInterrupt()....enable interrupts on a pin on falling edge
...
ISR: deal with an interrupt and clear INTFLAG
...
detachInterrupt()...disable interrupt on the pin
...
there is a falling edge on the pin while interrupts are disabled
...
attachInterrupt()...enable interrupts again

An interrupt will be generated, even if the interrupt flag was cleared in the ISR!

This doesn't happen if the interrupt flag is cleared immediately before attachInterrupt() is called:
e.g. for EXTINT[6]
REG_EIC_INTFLAG = EIC_INTFLAG_EXTINT6; // Clear the EXTINT6 flag

It seems to make sense to modify attachInterrupt() to clear the interrupt flag before enabling the interrupt, and/or add a function to clear the interrupt that doesn't require the user to go into the spec sheet and Google and figure everything out by themselves.

@matthijskooijman
Copy link
Collaborator

This is somewhat intentional, to allow temporarily disabling such an interrupt without losing events (at least that's how the current behaviour is being used by some).

See arduino/ArduinoCore-avr#244 for the same issue on the AVR core and arduino/Arduino#2159 for a (stale) PR to fix this on AVR and SAM.

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

2 participants