What seems to happen often is that an interrupt fires before mcp.clearInts(); happens or before it is complete.
The result is that the MCP won't fire off any more interrupts until I manually clear by typing 'c' in the serial monitor which results in mcp.clearInts(); being called again (that part of the loop() code is not included)
Then interrupts can occur again until it gets 'stuck' again.
The problem is that I can't put mcp.clearInts() inside a nointerrupts()/interrupts() pair.
So what is the best way to ensure that I clear the last interrupt on the MCP23017?
I can't seem to see any other way other than using nointerrupts() which causes the whole sketch to hang up.
void loop()
{
String strCmd;
int8_t nPinNum = 0, nVal1 = 0, nVal2 = 0, nVal3 = 0, nVal4 = 0;
int16_t nVal = 0;
uint8_t nI = 0;
char cCmd = 0, cBank = 0;
bool bVal = false;
void (* pointerISR)() = NULL;
if (nISRLEDPinNum > 0)
{
noInterrupts();
digitalWrite(nISRLEDPinNum, HIGH);
interrupts();
mcp.clearInts();
if (nISRLEDPinNum == nLEDISR1)
Serial.println(F("Interrupt 1 generated..."));
else if (nISRLEDPinNum == nLEDISR2)
Serial.println(F("Interrupt 2 generated..."));
nointerrupts();
nISRLEDPinNum = 0;
digitalWrite(nISRLEDPinNum, LOW);
interrupts();
}