Skip to content

Commit 97c00f1

Browse files
committed
Fix I2CEEBlockDevice read()
When reading a data block, the returned error codes from the I2C subsystem are different from normal single byte operations. We have to verify that the read-function for multiple bytes does return zero, because it returns "readBytes != expectedLength". Additionally, sync before trying to read from the eeprom as slow devices may not yet be ready to return data, especially with low-priced ones used with fast controllers.
1 parent d847f9f commit 97c00f1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ int I2CEEBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
6868

6969
_i2c->stop();
7070

71-
if (_i2c->read(_i2c_addr, static_cast<char *>(buffer), size) < 0) {
71+
_sync();
72+
73+
if (0 != _i2c->read(_i2c_addr, static_cast<char *>(buffer), size)) {
7274
return BD_ERROR_DEVICE_ERROR;
7375
}
7476

0 commit comments

Comments
 (0)