I'm working on a project that involves an ESP32 communicating with various I2C slave devices, such as a MCP23017.
This works as expected:
void MCP_writeA(uint8_t dat) {
Wire.beginTransmission(0x20);
Wire.write(0x12);
Wire.write(dat);
Wire.endTransmission();
}
This always returns 0 regardless of what the slave actually sent:
uint8_t MCP_readA() {
Wire.beginTransmission(0x20);
Wire.write(0x12);
Wire.endTransmission(false);
Wire.requestFrom(0x20, 1);
return Wire.read();
}
This, for reading the cell voltages from the BMS, also doesn't work:
void BMS_Vcell(uint16_t ret[]) {
Wire.beginTransmission(0x19);
Wire.write(0x00);
Wire.endTransmission(false);
Wire.requestFrom(0x19, 8);
ret[0] = (Wire.read() << 8) | Wire.read();
ret[1] = (Wire.read() << 8) | Wire.read();
ret[2] = (Wire.read() << 8) | Wire.read();
ret[3] = (Wire.read() << 8) | Wire.read();
}
In all cases, I have verified that the traffic on the bus is as expected with a logic analyzer. (As in the slaves are in fact returning data.) I'm using the stable (1.0.0) arduino-esp32 core on the Arduino 1.8.7 IDE. I'm simply calling Wire.begin() to initialize the I2C.