I've got a block of code which is occasionally blocking one of my tasks for a full second, leading to horrible jitter. Upon further investigation it seems like i2c_master_cmd_begin(...) is blocking for a full second. I have the parameter ticks_to_wait set to be much lower, which according to documentation should set the maximum ticks to wait before issuing a timeout. The issue is intermittent, but leads to instability in my firmware.
Here is the code:
Code: Select all
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, AS5600_ADDRESS << 1 | I2C_MASTER_WRITE, 0x1);
i2c_master_write_byte(cmd, REGISTER_0, ACK_CHECK_EN);
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (AS5600_ADDRESS << 1) | READ_BIT, ACK_CHECK_EN);
i2c_master_read(cmd, (uint8_t*) &s.half_word, 2, I2C_MASTER_LAST_NACK);
i2c_master_stop(cmd);
TickType_t pre_ticks = xTaskGetTickCount();
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, 2);
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "READ FAILED, TICKS = %d, ERROR CODE = %s", xTaskGetTickCount() - pre_ticks, esp_err_to_name(ret));
}
i2c_cmd_link_delete(cmd);
READ FAILED, TICKS = 1000, ERROR CODE = ESP_ERR_TIMEOUT
Anyone seen this issue before?
Thanks