Skip to content

Interrupt example is bad #58

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

Closed
lamello opened this issue Mar 27, 2021 · 6 comments
Closed

Interrupt example is bad #58

lamello opened this issue Mar 27, 2021 · 6 comments

Comments

@lamello
Copy link

lamello commented Mar 27, 2021

I have spend the day with the interrupt example and now i finally know whats the problem is.

In the example the commando is used:
mcp.setupInterruptPin(pin,FALLEN);

This is really bad. The correct mode in this example is "CHANGE".
FALLING or RISING modes will not work with this code without instabilities.

What i see, is that with CHANGE a interrupt goes active with a change of the pin and the interrupt can be reset with readGPIOAB();
With FALLING it is different, The interrupt goes aktive when the pin goes LOW AND the interrupt STAYS active as long as the pin is low.
While the pin is low the interrupt signal can't be reset !!!.

This solved in the code by looping until the pin (or button) is released.

This has as consequent that the code will hang ( no loop () ) until the user releases the button.

It would be nice that the examples have a standard that they always loop().

@caternuson
Copy link
Contributor

Yah, the MCP really only supports LOW/HIGH and not RISING/FALLING, since you can't clear the interrupt in that mode. It's a simple assert-if-comparison-true logic:

image

The changes in #64 include switching to LOW/HIGH.

@caternuson
Copy link
Contributor

Please checkout the new 2.0.0 release:
https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library/releases/tag/2.0.0
FALLING/RISING have been replaced with HIGH/LOW. CHANGE remains the same. These are (hopefully) inline with the Arduino spec:
https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/

@lamello
Copy link
Author

lamello commented Jun 27, 2021

Thank you for the announcement.

The interrupt example is different, but is now good?
I don't think so. What's the value of an interrupt example which don't use the interrupt?
The interrupt example is to simplistic to be really helpful or practical.

@caternuson
Copy link
Contributor

What would you suggest? The example can be updated. Idea with current one is it's very simple - just shows how to generally configure the INTA/B pin to fire.

@caternuson
Copy link
Contributor

Closing due to lack of response. Can reopen if needed. Not really a library issue, just commentary about existing example.

@kenttsai
Copy link

kenttsai commented Aug 5, 2022

The example can be updated with an interrupt service routine so that it is more useful to general folks.

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

3 participants