Hi
U try to connect a mcp 23017 to my ESP32 dev module board using
Adafruit_MCP23X17 library i wrote a simple demo base on their exam;le
but include an interrupt handler for the esp32 but
my problem is that the inferrupt fires all the time and not on change in input pin
Any help ?
Doron
#include <Adafruit_MCP23X17.h>
#define BUTTON_PIN 8 // MCP23XXX pin used for interrupt
#define INT_PIN 12 // microcontroller pin attached to INTA/B
bool intFlag = false;
Adafruit_MCP23X17 mcp;
type or paste code here
void setup() {
Serial.begin(115200);
//while (!Serial);
Serial.println("MCP23xxx Interrupt Test!");
// uncomment appropriate mcp.begin
if (!mcp.begin_I2C()) {
Serial.println("Error.");
while (1);
}
else (Serial.println("MCP found"));
// configure MCU pin that will read INTA/B state
pinMode(INT_PIN, INPUT);
attachInterrupt(INT_PIN, interruptHandler, CHANGE);
mcp.setupInterrupts(true, false,CHANGE);
// configure button pin for input with pull up
mcp.pinMode(BUTTON_PIN, INPUT_PULLUP);
// enable interrupt on button_pin
mcp.setupInterruptPin(BUTTON_PIN, LOW);
Serial.println("Looping...");
}
void loop() {
if (intFlag){
Serial.println("interrupt recived");
mcp.clearInterrupts(); // clear
intFlag = false;
}
delay(1000); // debounce
}
void IRAM_ATTR interruptHandler() {
intFlag = true;
}
Hi
thanks for response
The pin is high all time(checked with scope )
Do you have any sample or know where i can get one that connects the esp32 and 23017 using interrupt that works?
Doron
You should also look into INPUT_PULLUP or add pullup or pull down resistors. The most common is INPUT_PULLUP then a button press is going from HIGH (PULLED UP) to LOW.
The interrupt output can be configured to activate
under two conditions (mutually exclusive):
1. When any input state differs from its
corresponding Input Port register state. This is
used to indicate to the system host that an input
state has changed.
2. When an input state differs from a preconfigured
register value (DEFVAL register).
if the configuration is (2) and the DEFVAL register differs you would get continuous interrupts.
Would explain the observation.
There are two interrupt pins, INTA and INTB, that can
be associated with their respective ports, or can be
logically OR’ed together so that both pins will activate if
either port causes an interrupt.