Skip to content

Commit 7abb15c

Browse files
committed
reset i2c cmd buffer before read/write
related to [issue 53](espressif#53)
1 parent 6d097cd commit 7abb15c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cores/esp32/esp32-hal-i2c.c

+9
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ void i2cSetCmd(i2c_t * i2c, uint8_t index, uint8_t op_code, uint8_t byte_num, bo
112112
i2c->dev->command[index].op_code = op_code;
113113
}
114114

115+
void i2cResetCmd(i2c_t * i2c){
116+
int i;
117+
for(i=0;i<16;i++){
118+
i2c->dev->command[i].val = 0;
119+
}
120+
}
121+
115122
void i2cResetFiFo(i2c_t * i2c)
116123
{
117124
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
138145
uint8_t dataSend = willSend;
139146

140147
i2cResetFiFo(i2c);
148+
i2cResetCmd(i2c);
141149

142150
//CMD START
143151
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
222230
I2C_MUTEX_LOCK();
223231

224232
i2cResetFiFo(i2c);
233+
i2cResetCmd(i2c);
225234

226235
//CMD START
227236
i2cSetCmd(i2c, 0, I2C_CMD_RSTART, 0, false, false, false);

0 commit comments

Comments
 (0)