Skip to content
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 Scans for all! (S2 users having ESP_ERR_TIMEOUT: I2C Bus Busy) #710

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/components/i2c/WipperSnapper_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,37 @@ WipperSnapper_Component_I2C::scanAddresses() {

// Scan all I2C addresses between 0x08 and 0x7F inclusive and return a list of
// those that respond.
uint8_t addresses_failed_count = 0, current_failed_count = 0;
WS_DEBUG_PRINTLN("EXEC: I2C Scan");
for (address = 0x08; address < 0x7F; address++) {
start_scan:
current_failed_count = 0;
_i2c->beginTransmission(address);
endTransmissionRC = _i2c->endTransmission();

#if defined(ARDUINO_ARCH_ESP32)
// Check endTransmission()'s return code (Arduino-ESP32 ONLY)
// https://github.com/espressif/arduino-esp32/blob/master/libraries/Wire/src/Wire.cpp
if (endTransmissionRC == 5) {
WS_DEBUG_PRINTLN("ESP_ERR_TIMEOUT: I2C Bus Busy");
addresses_failed_count++;
current_failed_count++;
WS_DEBUG_PRINT("ESP_ERR_TIMEOUT: I2C Bus Busy - (Address: 0x");
WS_DEBUG_PRINT(address, HEX);
WS_DEBUG_PRINT(" - Error Count: ");
WS_DEBUG_PRINT(current_failed_count);
WS_DEBUG_PRINT(" of ");
WS_DEBUG_PRINT(addresses_failed_count);
WS_DEBUG_PRINT(")");
scanResp.bus_response =
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_ERROR_HANG;
// NOTE: ESP-IDF appears to handle this "behind the scenes" by
// resetting/clearing the bus. The user should be prompted to
// perform a bus scan again.
break;
// perform a bus scan again. This is a workaround for the ESP32s2 in v3.1.x
if (current_failed_count > 5 || addresses_failed_count > 100) {
WS_DEBUG_PRINTLN("ESP_ERR_TIMEOUT: Too many bus hangs");
break;
}
goto start_scan;
} else if (endTransmissionRC == 7) {
WS_DEBUG_PRINT("I2C_ESP_ERR: SDA/SCL shorted, requests queued: ");
WS_DEBUG_PRINTLN(endTransmissionRC);
Expand Down
Loading