arduino / arduino/ArduinoCore-samd
lost Interrupts for Digital Pin and attached ISR function
- Dominant language
- C
- Stars
- 502
- Forks
- 740
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I have a Push Button with pullup connected to digital in pin. I'm reading from digital Pin having attached an IRQ routing
attachInterrupt(digitalPinToInterrupt(pin), IRQ_ForPin, CHANGE)
In the Interrupt routing I read the value of the pin
value = DigitalReal(pin)
My problem is, that sometimes the value read is not the value of the pin. So there was a PIN change, but no further call to the ISR routine. Thats why I call this a lost interrupt.
Looking at the IRQ handling shows, that IRQ routing is called before interrupt is cleared. So pin may change after I read and before IRQ is cleared. Thats seems to be the problem. I fixed by clearing IRQ after call attached function.
After doing this change, this issue is gone:
From WInterrupts.c:
void EIC_Handler(void)
{
[...]
{
if ((EIC->INTFLAG.reg & ISRlist[i]) != 0)
{
// interted here by me
// Clear the interrupt
EIC->INTFLAG.reg = ISRlist[i];
// Call the callback function
ISRcallback[i]();
// commented out here by me
// Clear the interrupt
// EIC->INTFLAG.reg = ISRlist[i];
}
}
}
I can not see any advantage of clearing IRQ after calling the attached function. So I assume, that is a bug.
What are your thoughts?
Can this be fixed?
Thanks and best regards
Achim
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading WInterrupts.c, focusing on EIC_Handler and the attachInterrupt path described in the issue. Compare the interrupt-flag clearing order around ISRcallback[i] and verify the behavior with a CHANGE-triggered digital pin; done means the interrupt handling no longer loses a subsequent pin change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100