Espressif ESP32-S2 Programming Manual page 299

Table of Contents

Advertisement

Chapter 2. API Reference
• 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 to perform the transfer on
• device_address: I2C device's 7-bit address
• read_buffer: Buffer to store the bytes received on the bus
• read_size: Size, in bytes, of the read buffer
• ticks_to_wait: Maximum ticks to wait before issuing a timeout.
esp_err_t i2c_master_write_read_device(i2c_port_t
Perform a write followed by a read to a device on the I2C bus. A repeated start signal is used between the
write and read, thus, the bus is not released until the two transactions are finished. This function is a
wrapper to i2c_master_start(), i2c_master_write(), i2c_master_read(), etc...It 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 to perform the transfer on
• device_address: I2C device's 7-bit address
• write_buffer: Bytes to send on the bus
• write_size: Size, in bytes, of the write buffer
• read_buffer: Buffer to store the bytes received on the bus
• read_size: Size, in bytes, of the read buffer
• ticks_to_wait: Maximum ticks to wait before issuing a timeout.
i2c_cmd_handle_t
i2c_cmd_link_create_static(uint8_t *buffer, uint32_t size)
Create and initialize an I2C commands list with a given buffer. All the allocations for data or signals (START,
STOP, ACK, ...) will be performed within this buffer. This buffer must be valid during the whole transaction.
After finishing the I2C transactions, it is required to call i2c_cmd_link_delete_static().
Note It is highly advised to not allocate this buffer on the stack.
underneath may increase in the future, resulting in a possible stack overflow as the macro
I2C_LINK_RECOMMENDED_SIZE would also return a bigger value. A better option is to use a buffer
allocated statically or dynamically (with malloc).
Return Handle to the I2C command link or NULL if the buffer provided is too small, please use
I2C_LINK_RECOMMENDED_SIZE macro to get the recommended size for the buffer.
Parameters
• buffer: Buffer to use for commands allocations
• size: Size in bytes of the buffer
i2c_cmd_handle_t
i2c_cmd_link_create(void)
Create and initialize an I2C commands list with a given buffer. After finishing the I2C transactions, it is
required to call i2c_cmd_link_delete() to release and return the resources. The required bytes will
be dynamically allocated.
Return Handle to the I2C command link
void
i2c_cmd_link_delete_static(i2c_cmd_handle_t
Free the I2C commands list allocated statically with i2c_cmd_link_create_static.
Parameters
Espressif Systems
const uint8_t *write_buffer,
uint8_t *read_buffer, size_t read_size, TickType_t
ticks_to_wait)
cmd_handle)
288
Submit Document Feedback
i2c_num,
uint8_t
device_address,
size_t write_size,
The size of the data used
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Table of Contents

Save PDF