-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i2c speed dropping down #1563
Comments
@xiruilin What problems are you seeing? Error Messages? What is your Circuit? I need more Info before I can diagnose your problem. Chuck. |
Error Messages: [E][esp32-hal-i2c.c:1113] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init [E][esp32-hal-i2c.c:1113] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init [E][esp32-hal-i2c.c:1113] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init [E][esp32-hal-i2c.c:1113] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init |
@xiruilin ok,
This sequence of error messages is telling you:
The i2c hardware peripheral saw someone else using the bus, it waited 50ms, but the bus was never released.
You were sending a Write command equivalent to: Wire.beginTransmission(0x3e);
Wire.write(0x01);
Wire.write(0x02);
Wire.endTransmission(true);
This is the interrupt sequence received by the ISR handler: Then it received a second interrupt, the START at millisecond: 0x0000cfed: [02] 0x0001 0x0200 0x0000 0x0000 0x0000cfed Then the default 50ms timeout expired, and it exited with a Bus Busy error. It then tried to clear the bus by manually stimulating it:
but failed. the SDA gpio pin was held LOW and did not respond to the manual bus clearing cycle. This is the code from /cores/esp32/esp32-hal-i2c.c: static bool i2cCheckLineState(int8_t sda, int8_t scl){
if(sda < 0 || scl < 0){
return true;//return true since there is nothing to do
}
// if the bus is not 'clear' try the recommended recovery sequence, START, 9 Clocks, STOP
digitalWrite(sda, HIGH);
digitalWrite(scl, HIGH);
pinMode(sda, PULLUP|OPEN_DRAIN|OUTPUT|INPUT);
pinMode(scl, PULLUP|OPEN_DRAIN|OUTPUT|INPUT);
if(!digitalRead(sda) || !digitalRead(scl)) { // bus in busy state
log_w("invalid state sda=%d, scl=%d\n", digitalRead(sda), digitalRead(scl));
digitalWrite(sda, HIGH);
digitalWrite(scl, HIGH);
delayMicroseconds(5);
digitalWrite(sda, LOW);
for(uint8_t a=0; a<9; a++) {
delayMicroseconds(5);
digitalWrite(scl, LOW);
delayMicroseconds(5);
digitalWrite(scl, HIGH);
}
delayMicroseconds(5);
digitalWrite(sda, HIGH);
}
if(!digitalRead(sda) || !digitalRead(scl)) { // bus in busy state
log_e("Bus Invalid State, TwoWire() Can't init");
return false; // bus is busy
}
return true;
} These error message are telling me that you have a hardware fault, the SDA pin is LOW. Chuck. |
Thanks @stickbreaker for your detailed answers. The same device,use old Wire library, it works good at 100kHz, Because our application needs to transmit a lot of data through i2c, so the speed of using 50kHz is much slower than that of 100kHz. May I trouble you to see if there is any solution? Thanks again! |
@xiruilin what i2c device are you using? Chuck. |
Fixed with #1767 =) |
My i2c device is support high speed to 1MHz, it works good in 100kHz.
When update to new Wire library, it only work down to 50kHz, Why?
The text was updated successfully, but these errors were encountered: