MCP23017 - Unusual Behavior

I have a set of routines that I believe are easier to use than the library for multiple units.
I have 6 MCP23017's 4 SMD and 2 thru hole
The code I have included should set all the I/O to outputs and turn on all of the 'B' port outputs. It does this except for BO on every unit!,

I can understand one failing but not 6. The 'A' port works fine.
What is interesting that I can toggle B0 using the Adafruit library, but not my code.

Any suggestions

#include <Wire.h>

 byte MCP[6]= {0x20,0x21,0x22,0x23,0x24,0x25};      // for a many MCPs that you have
 
 /*Initialises the A and B port as outputs
  MCP Port A I/O register is 0x00
  MCP Port B I/O register is 0x01
======================================================*/
  void InitalizeMCP23017()
{
  Serial.println("Initialise");
    for(int i=0;i<6;i++)
      {
      Wire.beginTransmission(MCP[i]);
      Wire.write(0x00);                 //register 00
      Wire.write(0x00);                 //Set as Output
      Wire.write(0x01);                 //register 01
      Wire.write(0x00);                 //Set as Output  
      Wire.endTransmission();
      }
}


/*Turns on all of the outputs of a Port
======================================*/
void MCPPortOn(int MCPNo,char Port)
  {
  Serial.println("MCP Port ON");
  Wire.beginTransmission(MCP[MCPNo]);
  switch (Port)
    {
    case 'A':
      Wire.write(0x12);             //0x12
      Wire.write(0xFF);             //0xFF=11111111
      break;
    case 'B':
      Wire.write(0x13);            //0x13
      Wire.write(0xFF);            //0xFF=11111111
      break;
    }
   Wire.endTransmission();
  }


  void setup() 
{
  Wire.begin();
  Serial.begin(115200);
  
  InitalizeMCP23017();
 for(int i=0;i<6;i++)
  MCPPortOn(i,'B');
}

void loop() 
{
 

}

Can it deal with two commands in a single I2C session ? Those lines also contain the data 0x01. I was looking where you send 0x01 to the chip, because that would explain the problem.

It this enough information ?

Brilliant... Staring me in the face.... Thanks for that

By default, the mcp23017 operates in a sequential mode. You give a register address and the following byte is treated as the value which is to be written at that address, which is what you would expect. However, the next byte you write is taken as the value which is to be written at register address + 1. That is, there is an automatic increment of the address. So your code sequence would have done this:

{
      Wire.beginTransmission(MCP[i]);
      Wire.write(0x00);                 //register 00
      Wire.write(0x00);                 //Set as Output all port A (IODIRA)
      Wire.write(0x01);                 //Set as Output “most of” port B (IODIRB)
      Wire.write(0x00);                 //(IPOLA) input pin polarity (default setting)
      Wire.endTransmission();
  }

The data sheet explains this rather cryptically together with another weird mode which renumbers the registers to treat the device more like two 8 bit (mcp23008) devices loosely joined together. It is even more complicated because there is a mode to cycle within a corresponding register pair.