Chapter 2. API Reference
• cmd_handle: I2C commands list allocated statically. This handle should be created thanks to
i2c_cmd_link_create_static() function
void i2c_cmd_link_delete(i2c_cmd_handle_t cmd_handle)
Free the I2C commands list.
Parameters
• cmd_handle: I2C commands list. This handle should be created thanks to
i2c_cmd_link_create() function
esp_err_t i2c_master_start(i2c_cmd_handle_t cmd_handle)
Queue a“START signal”to the given commands list. This function shall only be called in I2C master mode.
Call i2c_master_cmd_begin() to send all the queued commands.
Return
• ESP_OK Success
• ESP_ERR_INVALID_ARG Parameter error
• ESP_ERR_NO_MEM The static buffer used to create cmd_handler is too small
• ESP_FAIL No more memory left on the heap
Parameters
• cmd_handle: I2C commands list
esp_err_t i2c_master_write_byte(i2c_cmd_handle_t cmd_handle, uint8_t data, bool ack_en)
Queue a“write byte”command to the commands list. A single byte will be sent on the I2C port. This function
shall only be called in I2C master mode. Call i2c_master_cmd_begin() to send all queued commands.
Return
• ESP_OK Success
• ESP_ERR_INVALID_ARG Parameter error
• ESP_ERR_NO_MEM The static buffer used to create cmd_handler is too small
• ESP_FAIL No more memory left on the heap
Parameters
• cmd_handle: I2C commands list
• data: Byte to send on the port
• ack_en: Enable ACK signal
esp_err_t i2c_master_write(i2c_cmd_handle_t cmd_handle, const uint8_t *data, size_t data_len,
bool ack_en)
Queue a “write (multiple) bytes”command to the commands list. This function shall only be called in I2C
master mode. Call i2c_master_cmd_begin() to send all queued commands.
Return
• ESP_OK Success
• ESP_ERR_INVALID_ARG Parameter error
• ESP_ERR_NO_MEM The static buffer used to create cmd_handler is too small
• ESP_FAIL No more memory left on the heap
Parameters
• cmd_handle: I2C commands list
• data: Bytes to send. This buffer shall remain valid until the transaction is finished. If the PSRAM
is enabled and intr_flag is set to ESP_INTR_FLAG_IRAM, data should be allocated from
internal RAM.
• data_len: Length, in bytes, of the data buffer
• ack_en: Enable ACK signal
esp_err_t i2c_master_read_byte(i2c_cmd_handle_t cmd_handle, uint8_t *data, i2c_ack_type_t ack)
Queue a“read byte”command to the commands list. A single byte will be read on the I2C bus. This function
shall only be called in I2C master mode. Call i2c_master_cmd_begin() to send all queued commands.
Return
• ESP_OK Success
• ESP_ERR_INVALID_ARG Parameter error
• ESP_ERR_NO_MEM The static buffer used to create cmd_handler is too small
• ESP_FAIL No more memory left on the heap
Espressif Systems 289
Submit Document Feedback
Release v4.4