MCP23017 GPIO Pin Write Issues

I have wired 2 banks of 8 LEDs up to the output pins of an MCP23017. The attached code is what I have been running.

I know all LEDs work and wiring is correct as I can light them all up at once. However when I try and run the LEDs individually either on a single bank or both they don’t work.

On bank A Pins 0,5,6 & 7 work and 1,2,3 & 4 don’t.
On bank B Pins 0,1,2 & 7 work and 3,4,5 & 6 don’t

Any ideas where I am going wrong? is it the addresses I am using?

// Attempt to work MCP23017 
#include "Wire.h"

#define All   0b11111111
#define GPIO0 0b00000001
#define GPIO1 0b00000010
#define GPIO2 0b00000100
#define GPIO3 0b00001000
#define GPIO4 0b00010000
#define GPIO5 0b00100000
#define GPIO6 0b01000000
#define GPIO7 0b10000000


void setup()
{
  Serial.begin(9600);
  Wire.begin(); // Start I2C Bus
  
  Wire.beginTransmission(0x20);
  Wire.write(0x05); // Setup IOCON I/O Expander Configuration Register
  Wire.write(0b01100000); // Mirror Int on, Sequential Mode Off
  Wire.endTransmission();
  
  Wire.beginTransmission(0x20);
  Wire.write(0x00); // IODIR Register
  Wire.write(0x00); // Set all Bank A to outputs
  Wire.endTransmission();
  
  Wire.beginTransmission(0x20);
  Wire.write(0x01); // IODIR Register
  Wire.write(0x00); // Set B0, B1, B2, B3 Input
  Wire.endTransmission();
}

void loop()
{
  byte a [8] = {GPIO0, GPIO1, GPIO2, GPIO3, GPIO4, GPIO5, GPIO6, GPIO7};
  byte i = 0;
  
  for (i=0;i<8;i++)
  {
    Wire.beginTransmission(0x20);
    Wire.write(0x12);
    Wire.write(a[i]);
    //Wire.write(All); //All,0,5,6&7 working, 1,2,3&4 not working
    Wire.endTransmission();
    Serial.print(a[i]);
    
    Wire.beginTransmission(0x20);
    Wire.write(0x13);
    Wire.write(a[i]);
    //Wire.write(All); //All,0,1,2&7  working, 3,4,5&6 not working
    Wire.endTransmission();
    
    delay(1000);
    
    Wire.beginTransmission(0x20);
    Wire.write(0x12);
    Wire.write(0x00);
    Wire.endTransmission();
    
    Wire.beginTransmission(0x20);
    Wire.write(0x13);
    Wire.write(0x00);
    Wire.endTransmission();
    
    delay(1000); 
  }
}

Ok, I had another idea and I set each of the pins on Bank B to Input and attached a switch; these are the results:

Pin BIN
0 00000001
1 00000010
2 00000100
3 11110000
4 11110000
5 11110000
6 11110000
7 10000000

I take it this is a hardware issue?

I had the same problem. I ended up writing a sketch that monitored inputs to the MCP23017, and its interrupts. It writes to all the registers, and then reads them, displaying the results on the serial monitor. It let me solve this problem quite easily.

The results were that in its power up condition, only a write to IOCONB will modify the shared IOCON register. Writing to IOCONA does not change it.

Also, the address of 0x05 is for IOCONA with bit 7 of IOCON set to 1. On power up or reset this bit is 0, meaning that the address of IOCONA is 0x0A, and IOCONB is 0x0B.