diff --git a/lib/i2cscan/i2cscan.cpp b/lib/i2cscan/i2cscan.cpp index 18793542b..5d8f22573 100644 --- a/lib/i2cscan/i2cscan.cpp +++ b/lib/i2cscan/i2cscan.cpp @@ -20,10 +20,10 @@ namespace I2CSCAN { uint8_t pickDevice(uint8_t addr1, uint8_t addr2, bool scanIfNotFound) { - if(I2CSCAN::isI2CExist(addr1)) { + if(I2CSCAN::hasDevOnBus(addr1)) { return addr1; } - if(I2CSCAN::isI2CExist(addr2)) { + if(I2CSCAN::hasDevOnBus(addr2)) { return addr2; } if (scanIfNotFound) { @@ -104,23 +104,25 @@ namespace I2CSCAN } else if (error == 4) { - Serial.printf("[ERR] I2C (@ %s(%d) : %s(%d)): Unknow error at address 0x%02x\n", + Serial.printf("[ERR] I2C (@ %s(%d) : %s(%d)): Unknown error at address 0x%02x\n", portMap[i].c_str(), portArray[i], portMap[j].c_str(), portArray[j], address); } } return found; } - bool isI2CExist(uint8_t addr) { + bool hasDevOnBus(uint8_t addr) { byte error; #if ESP32C3 + int retries = 1; do { #endif Wire.beginTransmission(addr); error = Wire.endTransmission(); + Wire.clearWriteError(); #if ESP32C3 } - while (error == 5); + while (error == 5 && retries--); #endif if(error == 0) return true; diff --git a/lib/i2cscan/i2cscan.h b/lib/i2cscan/i2cscan.h index 0ace23455..a0234db34 100644 --- a/lib/i2cscan/i2cscan.h +++ b/lib/i2cscan/i2cscan.h @@ -7,7 +7,7 @@ namespace I2CSCAN { void scani2cports(); bool checkI2C(uint8_t i, uint8_t j); - bool isI2CExist(uint8_t addr); + bool hasDevOnBus(uint8_t addr); uint8_t pickDevice(uint8_t addr1, uint8_t addr2, bool scanIfNotFound); int clearBus(uint8_t SDA, uint8_t SCL); boolean inArray(uint8_t value, uint8_t* arr, size_t arrSize);