Commit 0488d6f5 authored by Carlo Guarnieri Calo' Carducci's avatar Carlo Guarnieri Calo' Carducci
Browse files

repo: fix esp32 reboot if i2c slave does not aknowledge

parent 5ce820bd
......@@ -48,10 +48,10 @@ static void i2c_write(uint8_t reg, uint8_t *data, uint8_t N)
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
ESP_ERROR_CHECK(i2c_master_start(cmd));
ESP_ERROR_CHECK(i2c_master_write_byte(cmd, (i2c_address << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN));
ESP_ERROR_CHECK(i2c_master_write(cmd, &reg, 1, ACK_CHECK_EN));
ESP_ERROR_CHECK(i2c_master_write_byte(cmd, (i2c_address << 1) | I2C_MASTER_WRITE, ACK_CHECK_DIS));
ESP_ERROR_CHECK(i2c_master_write(cmd, &reg, 1, ACK_CHECK_DIS));
for (i = 0; i < N; i++)
ESP_ERROR_CHECK(i2c_master_write(cmd, &data[i], 1, ACK_CHECK_EN));
ESP_ERROR_CHECK(i2c_master_write(cmd, &data[i], 1, ACK_CHECK_DIS));
ESP_ERROR_CHECK(i2c_master_stop(cmd));
ESP_ERROR_CHECK(i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS));
i2c_cmd_link_delete(cmd);
......@@ -79,7 +79,7 @@ static void i2c_read(uint8_t reg, uint8_t *data, uint8_t size)
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
ESP_ERROR_CHECK(i2c_master_start(cmd));
ESP_ERROR_CHECK(i2c_master_write_byte(cmd, (i2c_address << 1) | I2C_MASTER_READ, ACK_CHECK_EN));
ESP_ERROR_CHECK(i2c_master_write_byte(cmd, (i2c_address << 1) | I2C_MASTER_READ, ACK_CHECK_DIS));
if (size>2)
ESP_ERROR_CHECK(i2c_master_read_byte(cmd, &block_size, ACK_VAL));
for (i = 0; i < size-1; i++)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment