I2C conflict between devices


I have a 0.96" I2C screen, and an MCP23017 multiplexer IC on the same I2C bus.

Both devices are visible on the bus, as I have checked with an I2C sniffer.

The screen will not initialise and the code hangs when the line 'Wire.requestFrom(0x24,1);' is called to retrieve data from the MCP23017.

I am at work, so don't have the code to hand... but I have been messing around with this for a few evening now and not fixed it yet. From memory and Google...

  Wire.begin();                                                                       //Set this Arduino as master I2c device
  Wire.beginTransmission(0x24);                                                       //Setup MCP23016 controller for inputs 1-16
  Wire.write(0x06);                                                                   //Set to pin direction setting mode
  Wire.write(0xFF);                                                                   //Set controller IODIR0 to all input
  Wire.write(0xFF);                                                                   //Set controller IODIR1 to all input

This sets up the MCP23017 to read all 16 input pins. I know this is correct, as i have used this before in several other projects (in fact, I lifted it directly from a working routine).

display.begin(SSD1306_SWITCHCAPVCC, 0x3c);                                       //Initialize the display with the I2C addr 0x3c

I set up the screen (using the Adafruit_SSD1306.h library).

Next would come the code to display my screen. This all works fine if I never call the line 'Wire.requestFrom(0x24,1);'.

Later in the code, I request the data from the MCP23017

    Wire.beginTransmission(0x24);                                                   // Select MCP23017 device
    Wire.write(0x00);                                                               // Select bank GP0   
    Wire.requestFrom(0x24,1);                                                       // Request the state of the GP0 inputs   
    B0to8_state = Wire.read();

This is the routine I always use to read the MCP23017.... but in this case, it's clashing with the screen comms.
If I comment out the line 'Wire.requestFrom(0x24,1);', then the issue goes away (but obviously I don't get my byte from the MCP23017).
With this line in place anywhere in the code, the routine will not run at all.

I have tried all manner of Wire.ends, I2C read loops to clear the bus, Wire.requestFrom(0x24,1,false); etc to try and clear the problem. No luck.

Any ideas?

Can you make a MCVE of the problem?

Try here for info and a library to do most of the work.
[MCP23017 arduino library](http://MCP23017 arduino library)

Tom... :slight_smile:

check post #5

check post #5

This thread suggests using the WSwire library.
However the zip file for that library doesn’t install properly, and every combination of manually un-zipped folders or sub folders of that library that I try in the Arduino directory (or library sub-folder), results in ‘Cannot find <WSWire.h>’ or a compile error.

Further investigation… contrary to what the help file says, it will not install alongside the original Wire.h library.
Not uninstalling that, as I have too many other projects that need it.

Will move this over to another platform and see if I get more luck

What model Arduino are you using?

Tom... :slight_smile:
PS Did you check post #2?