Some invalid I2C register reads
Posted: Thu Aug 31, 2023 6:05 am
ESP32 Wrover-E
IDF 4.4
ADF 2.4
Hi,
I'm currently facing some problems when reading registers from an IC via I2C.
I'm getting like hundres of correct reads, but at some point I get an incorrect one.
I've watched the I2C lines with an oscilloscope and the data looks fine, so the problem happens internally. This is 78 (0x4E) as expected, but in the code I get 163 (0xA3). The picture shows exactly that register read, that returns an invalid value.
My code to read registers (This functions returns no errors, but a wrong reading at some point):
I also tested another one with the same result:
I think it is an internal timing issue. It is only happening when A2DP sink (https://github.com/espressif/esp-adf/bl ... _example.c) is active and music is playing (via bluetooth). Only when playing music. If bluetooth and A2DP are enabled without playing music from the connected device, everything is fine.
I'm reading the register every 100ms and after like 5-20min I'm getting one incorrect reading.
I'n every case I've watched, the wrong reading was 163 (0xA3). The datasheet of the IC says, that the 7bit (MSB) always reads 0.
Normally I expect values like 80(0x50) or 78(0x4E). Something below 128 (0x80).
There are 10k pullup resistors on SDA and SCL. Internal pullups disabled.
I2C config:
I don't know what to do in that case. Maybe something with task priorities? Does I2C have a priority?
Thank you!
IDF 4.4
ADF 2.4
Hi,
I'm currently facing some problems when reading registers from an IC via I2C.
I'm getting like hundres of correct reads, but at some point I get an incorrect one.
I've watched the I2C lines with an oscilloscope and the data looks fine, so the problem happens internally. This is 78 (0x4E) as expected, but in the code I get 163 (0xA3). The picture shows exactly that register read, that returns an invalid value.
My code to read registers (This functions returns no errors, but a wrong reading at some point):
Code: Select all
esp_err_t i2c_ex_masterReadSlaveReg(i2c_port_t i2c_num, uint8_t i2c_addr, uint8_t i2c_reg, uint8_t *data_rd, size_t size)
{
return i2c_master_write_read_device(i2c_num, i2c_addr, &i2c_reg, 1, data_rd, size, (1000 / portTICK_RATE_MS));
}
Code: Select all
esp_err_t i2c_ex_masterReadSlaveReg(i2c_port_t i2c_num, uint8_t i2c_addr, uint8_t i2c_reg, uint8_t *data_rd, size_t size)
{
if (size == 0)
{
return ESP_OK;
}
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (i2c_addr << 1), I2C_EX_ACK_CHECK_EN);
i2c_master_write_byte(cmd, i2c_reg, I2C_EX_ACK_CHECK_EN);
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (i2c_addr << 1) | I2C_MASTER_READ, I2C_EX_ACK_CHECK_EN);
if (size > 1)
{
i2c_master_read(cmd, data_rd, size - 1, I2C_MASTER_ACK);
}
i2c_master_read_byte(cmd, data_rd + size - 1, I2C_MASTER_NACK);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(i2c_num, cmd, I2C_EX_TICKS_TO_WAIT);
i2c_cmd_link_delete(cmd);
return ret;
}
I think it is an internal timing issue. It is only happening when A2DP sink (https://github.com/espressif/esp-adf/bl ... _example.c) is active and music is playing (via bluetooth). Only when playing music. If bluetooth and A2DP are enabled without playing music from the connected device, everything is fine.
I'm reading the register every 100ms and after like 5-20min I'm getting one incorrect reading.
I'n every case I've watched, the wrong reading was 163 (0xA3). The datasheet of the IC says, that the 7bit (MSB) always reads 0.
Normally I expect values like 80(0x50) or 78(0x4E). Something below 128 (0x80).
There are 10k pullup resistors on SDA and SCL. Internal pullups disabled.
I2C config:
Code: Select all
.mode = I2C_MODE_MASTER,
.sda_io_num = IIM42652_SDA_GPIO,
.sda_pullup_en = GPIO_PULLUP_DISABLE,
.scl_io_num = IIM42652_SCL_GPIO,
.scl_pullup_en = GPIO_PULLUP_DISABLE,
.master.clk_speed = 100000
Thank you!