Chapter 2. API Reference
Parameters
• cmd_handle: I2C commands list
• data: Pointer where the received byte will the stored. This buffer shall remain valid until the
transaction is finished.
• ack: ACK signal
esp_err_t i2c_master_read(i2c_cmd_handle_t cmd_handle, uint8_t *data, size_t data_len,
i2c_ack_type_t ack)
Queue a “read (multiple) bytes”command to the commands list. Multiple bytes 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
Parameters
• cmd_handle: I2C commands list
• data: Pointer where the received bytes will the stored. This buffer shall remain valid until the
transaction is finished.
• data_len: Size, in bytes, of the data buffer
• ack: ACK signal
esp_err_t i2c_master_stop(i2c_cmd_handle_t cmd_handle)
Queue a “STOP 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_cmd_begin(i2c_port_t i2c_num, i2c_cmd_handle_t cmd_handle, TickType_t
ticks_to_wait)
Send all the queued commands on the I2C bus, in master mode. The task will be blocked until all the commands
have been sent out. The I2C APIs are not thread-safe, if you want to use one I2C port in different tasks, you
need to take care of the multi-thread issue. This function shall only be called in I2C master mode.
Return
• ESP_OK Success
• ESP_ERR_INVALID_ARG Parameter error
• ESP_FAIL Sending command error, slave hasn’t ACK the transfer.
• ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode.
• ESP_ERR_TIMEOUT Operation timeout because the bus is busy.
Parameters
• i2c_num: I2C port number
• cmd_handle: I2C commands list
• ticks_to_wait: Maximum ticks to wait before issuing a timeout.
int i2c_slave_write_buffer(i2c_port_t i2c_num, const uint8_t *data, int size, TickType_t
ticks_to_wait)
Write bytes to internal ringbuffer of the I2C slave data. When the TX fifo empty, the ISR will fill the hardware
FIFO with the internal ringbuffer’s data.
Note This function shall only be called in I2C slave mode.
Return
• ESP_FAIL (-1) Parameter error
• Other (>=0) The number of data bytes pushed to the I2C slave buffer.
Parameters
Espressif Systems 290
Submit Document Feedback
Release v4.4