These MCP23017 interrupts just don’t make sense.
The idea of the code below is to have the MCP23017 trigger int0/dp2 and int1/dp3 on a nano separately, with 2 separate ISRs turning on dp11 and dp12 separately, each attached to a different color LED.
Each ISR has its own flag which is set in the ISR.
The loop function then resets those flags and turns off the appropriate dp and attached LED - causing a different color flash according to which ISR was triggered from the MCP.
However if I disconnect either one of the wires connecting the MCP int pins from the nano then touching both mcp portA 0 and mcp portA 1 with a wire connected to 5V both cause nano int0 to trigger or both cause nano int1 to trigger.
In other words the mcp int pins still seemed to be in mirror mode despite this: mcp.setupInterrupts(false, false, HIGH);
And with this code I can only trigger and interrupt once. In order to trigger it gain I have to reset the arduino. Digital pin 6 on the nano is connected to the rest pin of the mcp so that I can manually reset it in code so that I could continually trigger interrupts with the interrupt example that came with the library - it seemed to work, but not with my code below.
Is there a problem with the adafruit library?
Is there a problem with my MCP23017?
Is there a problem with my breadbaord setup?
Is there another library for this device that people have used and found to be reliable?
Adafruit-MCP23017 library files attached.
// Install the LowPower library for optional sleeping support.
// See loop() function comments for details on usage.
uint8_t nArdLEDPin1 = 12, nArdLEDPin2 = 11, nMCPResetPin = 6;
volatile bool bISR1Flag = false, bISR2Flag = false;
bISR1Flag = true;
bISR2Flag = true;
// We mirror INTA and INTB, so that only one line is required between MCP and Arduino for int reporting
// The INTA/B will not be Floating
// INTs will be signaled with a LOW
mcp.setupInterrupts(false, false, HIGH);
// configuration for a button on port A
// interrupt will triger when the pin is taken to ground by a pushbutton
//mcp.pullUp(0, HIGH); // turn on a 100K pullup internally
// similar, but on port B.
//mcp.pullUp(1, HIGH); // turn on a 100K pullup internall
//Serial.println("MCP23007 Interrupt Test");
mcp.begin(); // use default address 0
attachInterrupt(0, MCPInt1ISR, RISING);
attachInterrupt(1, MCPInt2ISR, RISING);
* main routine: sleep the arduino, and wake up on Interrups.
* the LowPower library, or similar is required for sleeping, but sleep is simulated here.
* It is actually posible to get the MCP to draw only 1uA while in standby as the datasheet claims,
* however there is no stadndby mode. Its all down to seting up each pin in a way that current does not flow.
* and you can wait for interrupts while waiting.
bISR1Flag = false;
bISR2Flag = false;
if (bISR1Flag || bISR2Flag)
Adafruit_MCP23017.h (2.91 KB)
Adafruit_MCP23017.cpp (7.06 KB)