Interrupts RISING/FALLING/CHANGE/MCP23017

After writing my MCP23017 library I can't really see any reason why you need RISING and FALLING as interrupt types on an arduino.

When configuring the arduino interrupt in my MCP23017 library it was more convenient to use CHANGE as it mean I did not have to do separate calls to attachInterrupt depending on whether the MCP INT pins were being configured as HIGH or LOW.

And CHANGE works just as well with either MCP INT pin configuration.

What exactly is the the purpose of having these options for attachInterrupt?
For example does using CHANGE mean that you will get two interrupts on the pin, one as the voltage rises and another as it falls?

Also with the MCP interrupt configuration via INTCON where the interrupt keeps triggers if the pin value is different from its last value. Does that also mean you get two interrupts, one as the voltage on the pin rises and one as the pin falls. And if so what stops the MCP from falling into an endless loop of interrupts?

Yes, if you use change then you get an interrupt on the rising and falling edges of the signal. So for a square pulse for instance you get two interrupts, one at the beginning and one at the end.

There is much usefulness in the FALLING and RISING options if you are only interested in firing an interrupt on one edge or the other. For example when counting pulses if you use CHANGE then you get two interrupts per pulse where you really only want one.

Delta_G:
So for a square pulse for instance you get two interrupts, one at the beginning and one at the end.

Does that also apply to the on the MCP23017 when you have it configured to fire interrupts when the pin value is different from the last time it was saved in the INTCAP register?

If so I am not sure I can see what stops it from a endless interrupt loop.

I don't understand your question. It would fire when the pin goes HIGH and when the pin goes LOW but if the pin doesn't change it wouldn't fire. I'm not following where you are getting the endless loop from. Can you expand on that?

Delta_G:
I don't understand your question. It would fire when the pin goes HIGH and when the pin goes LOW but if the pin doesn't change it wouldn't fire. I'm not following where you are getting the endless loop from. Can you expand on that?

  1. INTCAP register contains 0 for pin0.
  2. Pin0 goes from 0 to 1 due to conditions on external circuit connected to pin0.
  3. 1 is different from contents of INTCAP for pin0 so an interrupt is generated on the INT pin.
  4. 1 is stored in NTCAP register for pin0.
  5. Interrupt is serviced on the arduino MCP interrupt cleared.
  6. Conditions on external circuit connected to pin0 cause it to fall back to 0.
  7. 0 is different from the from contents of INTCAP for pin0 so an interrupt is generated on the INT pin.
  8. 0 is stored in INTCAP register for pin0.
  9. Conditions on external circuit connected to pin0 cause it to rise back to 1.
  10. 1 is different from contents of INTCAP for pin0 so an interrupt is generated on the INT pin.
  11. 1 is stored in NTCAP register for pin0.
  12. Interrupt is serviced on the arduino MCP interrupt cleared.
    13)...........

That could easily happen with the way I am testing it, i.e. by touching a GNDed or VCCed wire on pin0.
I can't necessarily remove the wire from the pin in time before a value is stored in the INTCAP register.

May be that is the cause of the problem I am having with the MCP getting 'stuck' because my function clearInts() does not have enough time to execute before the next interrupt is triggered.