I2C: One byte is changing during transfer!

Hi!

I am using an Arduino Nano and a NodeMCU, communicating via I2C bus. But I cannot establish a working connection.

The ESP8266 sends a "Status request" [Wire.write(0x00)] to the Arduino and it sends a 0x6F as answer [Wire.write(0x6F);] (decimal 111), but on the ESP side the received byte is not 0x6F but 0x37 (decimal 55). Can't figure out whre the problem is. :frowning:

Arduino Nano:

// Not configured yet
Wire.write(0x6F);

ESP:

Wire.requestFrom(8, 1); 
while (Wire.available()) 
{
    char c = Wire.read(); 
...
    else
        {
            char answer[2];
            sprintf(answer, "0x%02X", c);
            Serial.print(answer);
        }
...

The output is"0x37" :frowning:

In your ESP code you're trying to sprintf a hex character (byte) into the character string "0x6F"; that needs a character array of five chars including a null terminator, not two.

Is the NodeMCU using a software I2C ? Perhaps the clock stretching is not fully working.

Aaaaaaaargh!!!! Thank you very much! :smiley:

julianop:
In your ESP code you're trying to sprintf a hex character (byte) into the character string "0x6F"; that needs a character array of five chars including a null terminator, not two.