-
Notifications
You must be signed in to change notification settings - Fork 39
[Observation] attachInterrupt reconfigures the pin, removing a pull-up and so triggers a falling interrupt #416
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
Comments
Hi Had a look at this issue and found the root cause and solution. Root cause Solution
At the end of routine gpio_irq_set(), around line 140, add after ap3_gpio_enable_interrupts(obj->control->pad, ap3_int_dir);
ADDITIONAL NOTE 1: The initialization is a bit chaotic. some routines are called multiple times ( e.g. irq_init(), direction setting, mode setting. They do not conflict, but are unnecessary. ADDITIONAL NOTE 2: There is no need to set the pullup/pulldown in the sketch. It is handled already on 2 places ( InterruptIn.CPP and in Commoninterrupt.cpp) regards, |
Thank you Paul - much appreciated! |
Hi Paul (@paulvha ), Thanks again for all the help you've given us on Artemis and Apollo3 - it is very much appreciated. Just looking at the interrupt pull-ups again, if you have a 10M resistor lying around, could you please try the following? Steps to reproduce:
With v1.2.1 of the core, interruptCounter remains zero. No interrupts are seen as the 10M resistor is too high to counteract the pull-up on Pin 1. With v2.1.1 of the core, I see interrupts: My thesis is that If I add a second Very best wishes, |
hi Paul You are right about removing the pull-up. test I have tried it on pin 10 and 8, put the 10M between the points and attached a scope. On V2.1.1 I get the same result as you. Given the pinmode(10, INPUT_PULLUP) set before this attachInterrupt I would not expect that to happen I see a start of 500mS the pulse going high and a print of interruptcounter of 0. If I then add pinMode(10, INPUT_PULLUP); after attachInterrupt() I get the nearly the same output as you, but it fires 1 time every time. (which I will explain later) Apollo3 Interrupt Pull-Up Test root cause When you call AttachInterrupt() it will call indexAttachInterruptParam(). Both are part of Commoninterrupt.cpp of the Sparkfun library. If there is no constructer yet with MBED-OS-interrupt it calls InterruptInParam(pinNameByIndex(index)), which is in the same file. From there it will call InterruptIn(pin), which is part of MBED-OS. As NO mode is passed in the previous calls we end up with PullDefault, which is NO pullup. As such it is removing the pull-up that was set before! Below is the sequence that is happening
The removing of the pullup on the pin is also the reason it is triggering Interrupt at least once even if we have pinMode(10, INPUT_PULLUP) before in the sketch. As indicated in Commoninterrupt.cpp : The solution Change the routine in indexAttachInterruptParam() in Commoninterrupt.cpp to :
Next to the earlier change in gpio_irq_api.c mentioned in an earlier post , this needs to change as well. regards, |
Thank you Paul - again, very much appreciated, |
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:
If the pull-up on pin 10 remains enabled, the interrupt should never trigger. However, we get not one but two interrupts:
If we add a second call to
pinMode(10, INPUT_PULLUP);
after theattachInterrupt
:Then we still get the first interrupt - but not the second one:
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:
Cheers,
Paul
The text was updated successfully, but these errors were encountered: