understanding I2C
Posted: Sun Mar 07, 2021 9:57 am
Hello!
After starting with Arduino boards and Arduino IDE I'm now using ESP32-boards and VS Code/PlatformIO with ESP-IDF. So I read I2C-chapter of ESP-IDF programming guide/API reference and want to have a better understanding of these functions.
A typical code from GitHub looks like this (and it works):
My questions:
1. i2c_master_read() is reading several bytes at once?
2. But for the last byte a NACK is mandatory, so that's the reason, why there is an additional i2c_master_read_byte()?
3. What is the meaning of i2c_master_cmd_begin()-function? Are the master_read calls only a kind of preparation and the data transmission from slave to master really starts with the master_cmd_begin?
Kind regards
Jürgen
After starting with Arduino boards and Arduino IDE I'm now using ESP32-boards and VS Code/PlatformIO with ESP-IDF. So I read I2C-chapter of ESP-IDF programming guide/API reference and want to have a better understanding of these functions.
A typical code from GitHub looks like this (and it works):
Code: Select all
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);
1. i2c_master_read() is reading several bytes at once?
2. But for the last byte a NACK is mandatory, so that's the reason, why there is an additional i2c_master_read_byte()?
3. What is the meaning of i2c_master_cmd_begin()-function? Are the master_read calls only a kind of preparation and the data transmission from slave to master really starts with the master_cmd_begin?
Kind regards
Jürgen