Interrupts with the MCP23S17

I am having problems getting interrupts to work with the MCP23S17.

I have managed to get the GPIO pins working in a simple scenario driving LEDs both with and without Rob Tillaarts library. I am, however, struggling to get interrupts to work. The line stays either high or low and the interrupt does not fire.

I have set up a simple script to drive a LED on PORT A pin D7 and an input on PORT A pin D0. The Arduino has been set up to receive the signal from INTA on pin D2. When an interrupt is detected on D2, the INTCAPA register should get read and the LED toggled on or off. Having consulted the MCP23x17 datasheet, the various registers have been configured as follows:

  • INTPOL bit on IOCON set to 0 for active low
  • INTCON set to 0x00 so bit values (including bit 0) are compared to the previous setting
  • GPINTENA set to 0x01 to enable an interrupt to be triggered when GPIO port A bit 0 changes state

I am monitoring both the SPI bus and the INTA signal on an oscilloscope using its logic analyser feature. I can see the correct sequences being sent to the chip, but don't see the INTA signal changing at all. Consequently the INTCAPA register never gets read and the result acted upon.

There was a suggestion on another forum to set the ODR bit on the IOCON register. I tried this as well but the interrupt still does not fire:

https://forum.microchip.com/s/topic/a5C3l000000MLhbEAG/t313483?comment=P-2445112

I'm not sure whether there is something else I need to set?
MCP23S17-test.ino (7.6 KB)

Why didn't you post your code?

Sorry, have now attached it to the opening post.

Bad forum style to edit the initial post.

bool mcpIntA = false;

That variable should be declared "volatile".

  // Enable communication with MCP23S17
  digitalWrite(chipSelect, LOW);
  // Stop communication with MCP23S17
  digitalWrite(chipSelect, HIGH);

Remove these lines from setup() as the CS pin is handled in the mcpByteRead() and mcpByteWrite() subroutines.

Have you tried using the Adafruit_MCP23017 library to do the same? If it doesn't work with that library I would replace the hardware.

How do you trigger the interrupt?

Thank you. I have noted your points. The variable declaration has been changed to:

volatile bool mcpIntA = false;

The two lines you suggested have been removed as they are not needed.

I will have a play with the Adafruit library.

Unfortunataly I have so far been unable to get interrupts to work even with the Adafruit library so it looks like the hardware is suspect.

I ask again: How do you trigger the interrupt? Do you use a button, some other IC, a fly-by wire?

Fly-by-wire for now. 270ohm resistor to GND for low and 5V for high.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.