About I2C read
Posted: Sat Dec 10, 2016 2:39 am
Code: Select all
<esp32-hal-i2c.c>
On "i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data, uint8_t len, bool sendStop)"
while(len) {
cmdIdx = (index)?0:2;
willRead = (len > 32)?32:(len-1);
if(cmdIdx){
i2cResetFiFo(i2c);
}
+ 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);
}
}