I examined the example of the esp-idf, I looked at "ESP-IDF Progamming Guide" (https://esp-idf.readthedocs.io/en/latest/index.html) and "don't understand"/miss one thing in the handling/programming "i2c bus":
During the initialization of the i2c I have to say "I'm the master of the bus" and which i2c bus ("I2C_NUM_0" or "I2C_NUM_1") to use (aka "/dev/i2c-1" under linux). So far so good...
Code: Select all
static esp_err_t i2c_example_master_read_slave(i2c_port_t i2c_num, 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, ( ESP_SLAVE_ADDR << 1 ) | READ_BIT, ACK_CHECK_EN);
if (size > 1) {
i2c_master_read(cmd, data_rd, size - 1, ACK_VAL);
}
i2c_master_read_byte(cmd, data_rd + size - 1, NACK_VAL);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
return ret;
}
The first call "i2c_master_write_byte" in the example above sends the "command direction" and the client's address on the bus. Right?
But how to address the the register address/offset/index inside the client's address? Should I place it in the first byte of the data array?
I examined the include "driver/i2c.h" and didn't find any help, it caused confusion only: the data type "i2c_cmd_handle_t" is defined as
Code: Select all
typedef void* i2c_cmd_handle_t; /*!< I2C command handle */
Thanks in advance,
Michael