Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By eketjall
#57325 Don't know if I'm doing anything wrong or if it's a bug/feature.

I'm having a ESP-01 as i2c master and a Arduino Pro Mini 3.3V 8Mhz as slave.
I can scan the i2c bus and find the Pro Mini slave.
But when i request a response from the slave the bit order of the respons is reversed.

On the ESP-01 Master:
Code: Select all    Serial.print("Request from slave, ");
    err = Wire.requestFrom(i2cSlaveDeviceId, 2);    // request 2 bytes from slave device
    Serial.print(err);
    Serial.print(" bytes received: ");
    while(Wire.available()) {    // slave may send less than requested
      byte b = Wire.read();    // receive a byte as character
      Serial.print(b,DEC);     // print the character value
      Serial.print(" ");
    }

This outputs the bytes "0" and "127" on the serial monitor.

On the Arduino slave:
Code: Select all  byte buffer[] = {0,1};
  Serial.flush();
  Serial.print("i2c send: ");
  Serial.print(buffer[0],DEC);
  Serial.print(" ");
  Serial.println(buffer[1],DEC);
  Wire.write(buffer,2);

This of course outputs the bytes "0" and "1" on the serial monitor.

So basically, if the slave sends "00000001" but the master receives "10000000";

Is this a known fact or am I doing something wrong?
User avatar
By eketjall
#57361 Seems like I've found the problem.

The "reversed bit order" was just an unlucky coincident that made me go in the wrong direction.
I actually got some strange responses, not random, but strange. Like if some bits where missing.

This thread https://forum.arduino.cc/index.php?topic=336543.0 on Arduino.cc had what seems to be the solution.

Adding Wire.setClockStretchLimit(1500); after Wire.begin in the ESP-01 master did the trick.
The Pro Mini at 8MHz was to slow basically.