I different interrupt problem with arduino interfaced with MCP23017

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();
	}

http://snippets-r-us.com/

Post the whole code. Especially the interrupt handlers.

Delta_G:
http://snippets-r-us.com/

Post the whole code. Especially the interrupt handlers.

This is all of it, including the library.

MCP23017.cpp (12.2 KB)

MCP23017.h (11.8 KB)

test.ino (12.1 KB)

I figured out what I was doing wrong.

This call mcp.clearInts(); needs to be at the bottom of all my ISR handling code in the loop() function - it has nothing to do with arduino interrupts.

If the MCP cannot generate interrupts then nothing can interfere with turning the LEDs on and off resetting flags etc.

if (nISRLEDPinNum > 0)
	{
		digitalWrite(nISRLEDPinNum, HIGH);
		delay(200);
		digitalWrite(nISRLEDPinNum, LOW);
		if (nISRLEDPinNum == nLEDISR1)
			Serial.println(F("Interrupt 1 generated..."));
		else if (nISRLEDPinNum == nLEDISR2)
			Serial.println(F("Interrupt 2 generated..."));
        nISRLEDPinNum = 0;
		mcp.clearInts();
	}