MCP23017 expander control via Wire library - I2C within a Task - Failure

This is just a general FYI. It required a couple of days of troubleshooting; so this may save some time for another user.

I have an ESP32 connected to a MCP23017 expander, as I need another 16 I/O points. This is controlled via the I2C buss (GPIO22 and GPIO21).

Running under both Visual Micro and the Arduino IDE.

Reading or writing to a single port or register on the 23017 works correctly in any task (including loop() )

Reading both A and B registers (16 bits) works correctly on any task if you use the following:

Wire.beginTransmission (MCP_PORT);
Wire.write (GPIOA);
Wire.endTransmission (true);
Wire.requestFrom(MCP_PORT, 2);
portA = Wire.read();
portB = Wire.read();

This requires ~ 125µsec at 1MHz clock.

Setting - Wire.endTransmission (false); // keep the I2C bus open

results in a 70µsec transmission, but the data returned is all 0. You can see on a logic analyzer that the data is never returned on the buss. I can share screenshots if desired.

However, running this command in loop() works perfectly. It fails in any other defined task.

I will use the working model to finish my project, but I would like to understand the issue if possible.

Regards, David

Thank you for sharing this issue. Have you also tried posting it in Espressif forums?