From 04e0902ca6c0e817bd88d53a510a03935e3d6fc7 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Wed, 14 Dec 2016 18:43:32 +0200 Subject: [PATCH] Wire: if we are reading only one byte, do not send empty read command --- cores/esp32/esp32-hal-i2c.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cores/esp32/esp32-hal-i2c.c b/cores/esp32/esp32-hal-i2c.c index d11add60..a6cd5b58 100644 --- a/cores/esp32/esp32-hal-i2c.c +++ b/cores/esp32/esp32-hal-i2c.c @@ -267,9 +267,17 @@ i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data i2cResetFiFo(i2c); } - i2cSetCmd(i2c, cmdIdx++, I2C_CMD_READ, willRead, false, false, false); - if((len - willRead) > 1) { - i2cSetCmd(i2c, cmdIdx++, I2C_CMD_END, 0, false, false, false); + if(willRead){ + i2cSetCmd(i2c, cmdIdx++, I2C_CMD_READ, willRead, false, false, false); + if((len - willRead) > 1) { + i2cSetCmd(i2c, cmdIdx++, I2C_CMD_END, 0, false, false, false); + } else { + willRead++; + i2cSetCmd(i2c, cmdIdx++, I2C_CMD_READ, 1, true, false, false); + if(sendStop) { + i2cSetCmd(i2c, cmdIdx++, I2C_CMD_STOP, 0, false, false, false); + } + } } else { willRead++; i2cSetCmd(i2c, cmdIdx++, I2C_CMD_READ, 1, true, false, false);