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.
//#include <LowPower.h>
#include <Wire.h>
#include <Adafruit_MCP23017.h>
CMCP23017 mcp;
uint8_t nArdLEDPin1 = 12, nArdLEDPin2 = 11, nMCPResetPin = 6;
volatile bool bISR1Flag = false, bISR2Flag = false;
void MCPInt1ISR()
{
digitalWrite(nArdLEDPin1, HIGH);
bISR1Flag = true;
}
void MCPInt2ISR()
{
digitalWrite(nArdLEDPin2, HIGH);
bISR2Flag = true;
}
void setupMCPInterrupts()
{
// 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.pinMode(0, INPUT);
//mcp.pullUp(0, HIGH); // turn on a 100K pullup internally
mcp.setupInterruptPin(0, RISING);
// similar, but on port B.
mcp.pinMode(1, INPUT);
//mcp.pullUp(1, HIGH); // turn on a 100K pullup internall
mcp.setupInterruptPin(1, RISING);
}
void setup()
{
Serial.begin(115200);
//Serial.println("MCP23007 Interrupt Test");
mcp.begin(); // use default address 0
pinMode(nMCPResetPin, OUTPUT);
digitalWrite(nMCPResetPin, HIGH);
pinMode(nArdLEDPin1, OUTPUT);
pinMode(nArdLEDPin2, OUTPUT);
digitalWrite(nArdLEDPin1, LOW);
digitalWrite(nArdLEDPin2, LOW);
setupMCPInterrupts();
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.
*/
void loop()
{
delay(200);
if (bISR1Flag)
{
digitalWrite(nArdLEDPin1, LOW);
Serial.println("XXXXXXXXX");
bISR1Flag = false;
}
if (bISR2Flag)
{
digitalWrite(nArdLEDPin2, LOW);
Serial.println("YYYYYYYYY");
bISR2Flag = false;
}
if (bISR1Flag || bISR2Flag)
{
Serial.println("ZZZZZZZZZ");
digitalWrite(nMCPResetPin, LOW);
delay(10);
digitalWrite(nMCPResetPin, HIGH);
setupMCPInterrupts();
}
}
Adafruit_MCP23017.h (2.91 KB)
Adafruit_MCP23017.cpp (7.06 KB)