From 7abb15ca6277d4fb7645a4c90641d4d40109a191 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Thu, 17 Nov 2016 00:46:56 +0200 Subject: [PATCH] reset i2c cmd buffer before read/write related to [issue 53](https://github.com/espressif/arduino-esp32/issues/53) --- cores/esp32/esp32-hal-i2c.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cores/esp32/esp32-hal-i2c.c b/cores/esp32/esp32-hal-i2c.c index d845bc09..fefd761a 100644 --- a/cores/esp32/esp32-hal-i2c.c +++ b/cores/esp32/esp32-hal-i2c.c @@ -112,6 +112,13 @@ void i2cSetCmd(i2c_t * i2c, uint8_t index, uint8_t op_code, uint8_t byte_num, bo i2c->dev->command[index].op_code = op_code; } +void i2cResetCmd(i2c_t * i2c){ + int i; + for(i=0;i<16;i++){ + i2c->dev->command[i].val = 0; + } +} + void i2cResetFiFo(i2c_t * i2c) { i2c->dev->fifo_conf.tx_fifo_rst = 1; @@ -138,6 +145,7 @@ i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * dat uint8_t dataSend = willSend; i2cResetFiFo(i2c); + i2cResetCmd(i2c); //CMD START i2cSetCmd(i2c, 0, I2C_CMD_RSTART, 0, false, false, false); @@ -222,6 +230,7 @@ i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data I2C_MUTEX_LOCK(); i2cResetFiFo(i2c); + i2cResetCmd(i2c); //CMD START i2cSetCmd(i2c, 0, I2C_CMD_RSTART, 0, false, false, false);