-
-
Notifications
You must be signed in to change notification settings - Fork 709
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
External interrupts flags are not cleared before enabling the interrupt #532
Comments
A related issue for the AVR core is here: arduino/ArduinoCore-avr#244 (with a very old PR to fix it: arduino/Arduino#2159). Note that a complication is that some code actually relies on this behaviour when temporarily disabling an interrupt (with no alternative because of the lack of explicit disable/enableInterrupt functions), so this is not entirely as trivial as it seems (see also the linked issue and PR for more discussion). |
First of all thanks for your comment. In my opinion this is a bug and not a feature. It looks something like the wrong position of one of the connector on the Ardino boards: it was a mistake, of course, but when the Arduino team discovered it, the first batch of 100 boards had already been made and so they didn't have the guts to fix it. Marco |
Yeah it is, it's just that fixing the bug will break some existing code, so this must be done carefully. Especially since those libraries that rely on this bug have no other way to implement this currently (they cannot be fixed right now), so maybe some 2-step process (introducing enable/disableInterrupt, then later fix attachInterrupt) would be appropriate. |
Ok I understand your worries. What about adding a default parameter to the attachinterrupt function? void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode, bool clear = false); This will mantain full compatibility with the current implementation if we call the function with just three parameters, but, if we call it setting the last parameter to true, the interrupt flag will be cleared before enabling the interrupt. |
Hm, I think this could maybe work. However:
Maybe all of these could be solved by instead adding a A further extension (that would also work with your optional argument approach, btw) could be to add I haven't thought this true completely, but at first glance, this sounds like a reasonable approach. Note that this change would need to be implemented across all cores to remain portable, so this might be something to be discussed in the ArduinoCore-API repository (which is slowly becoming the home of portable API changes). Also note that I think there have been some changes to |
You are right, I missed that attachInterrupt is a C function :-( |
Hi everybody,
Bug description:
If we generate a falling edge on an interrupt source pin when the interrupt is disabled, when we enable the interrupt the interrupt service is triggered immediately.
(This has been tested with falling edge mode, but it should happen with every external interrupt mode)
Setup description to reproduce the bug:
Arduino Zero with two N.O. momentary switches connected on pins D2 and D3 to GND.
Sketch used to show up the bug:
Procedure description:
Bug analysis:
the external interrupt flag in register EIC->INTFLAG is not cleared before enabling the interrupt.
Any comment is welcome.
Marco
The text was updated successfully, but these errors were encountered: