Not sure if this code helps you or not ... but you may just be off slightly on the protocol (unless I am misunderstanding). I use this code for multi-read from battery charger I2C interface. The difference between your code and mine is an additional register # and a master_start. I've only ever conducted multi-reads or multi-writes (not both in same request). And the protocol can sometimes be device specific. I do not reset the I2C interface driver after each request.
Code: Untitled.c Select all
// len = number of registers to read
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_ack_type_t nack = I2C_MASTER_NACK;
i2c_ack_type_t ack = I2C_MASTER_ACK;
i2c_master_start(cmd);
i2c_master_write_byte(cmd, i2c_addr << 1 | WRITE_BIT, ACK_CHECK_EN);
i2c_master_write_byte(cmd, starting_reg, ACK_CHECK_EN);
i2c_master_start(cmd);
// here ^
i2c_master_write_byte(cmd, i2c_addr << 1 | READ_BIT, ACK_CHECK_EN);
for (int i = 0; i < (len - 1); i++)
{
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_read_byte(cmd, &values[i], ack));
}
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_read_byte(cmd, &values[len-1], nack));
i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(i2c_num, cmd, 500 / portTICK_RATE_MS);
ESP_ERROR_CHECK_WITHOUT_ABORT(ret);
i2c_cmd_link_delete(cmd);