Skip to content

Commit 04e0902

Browse files
committed
Wire: if we are reading only one byte, do not send empty read command
1 parent 917a4fd commit 04e0902

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cores/esp32/esp32-hal-i2c.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,17 @@ i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data
267267
i2cResetFiFo(i2c);
268268
}
269269

270-
i2cSetCmd(i2c, cmdIdx++, I2C_CMD_READ, willRead, false, false, false);
271-
if((len - willRead) > 1) {
272-
i2cSetCmd(i2c, cmdIdx++, I2C_CMD_END, 0, false, false, false);
270+
if(willRead){
271+
i2cSetCmd(i2c, cmdIdx++, I2C_CMD_READ, willRead, false, false, false);
272+
if((len - willRead) > 1) {
273+
i2cSetCmd(i2c, cmdIdx++, I2C_CMD_END, 0, false, false, false);
274+
} else {
275+
willRead++;
276+
i2cSetCmd(i2c, cmdIdx++, I2C_CMD_READ, 1, true, false, false);
277+
if(sendStop) {
278+
i2cSetCmd(i2c, cmdIdx++, I2C_CMD_STOP, 0, false, false, false);
279+
}
280+
}
273281
} else {
274282
willRead++;
275283
i2cSetCmd(i2c, cmdIdx++, I2C_CMD_READ, 1, true, false, false);

0 commit comments

Comments
 (0)