Chapter 2. API Reference
Functions
esp_err_t spi_bus_add_device(spi_host_device_t host_id, const spi_device_interface_config_t
*dev_config, spi_device_handle_t *handle)
Allocate a device on a SPI bus.
This initializes the internal structures for a device, plus allocates a CS pin on the indicated SPI master peripheral
and routes it to the indicated GPIO. All SPI master devices have three CS pins and can thus control up to three
devices.
Note While in general, speeds up to 80MHz on the dedicated SPI pins and 40MHz on GPIO-matrix-routed
pins are supported, full-duplex transfers routed over the GPIO matrix only support speeds up to 26MHz.
Return
• ESP_ERR_INVALID_ARG if parameter is invalid
• ESP_ERR_NOT_FOUND if host doesn’t have any free CS slots
• ESP_ERR_NO_MEM if out of memory
• ESP_OK on success
Parameters
• host_id: SPI peripheral to allocate device on
• dev_config: SPI interface protocol config for the device
• handle: Pointer to variable to hold the device handle
esp_err_t spi_bus_remove_device(spi_device_handle_t handle)
Remove a device from the SPI bus.
Return
• ESP_ERR_INVALID_ARG if parameter is invalid
• ESP_ERR_INVALID_STATE if device already is freed
• ESP_OK on success
Parameters
• handle: Device handle to free
esp_err_t spi_device_queue_trans(spi_device_handle_t handle, spi_transaction_t *trans_desc, Tick-
Type_t ticks_to_wait)
Queue a SPI transaction for interrupt transaction execution. Get the result by
spi_device_get_trans_result.
Note Normally a device cannot start (queue) polling and interrupt transactions simultaneously.
Return
• ESP_ERR_INVALID_ARG if parameter is invalid. This can happen if
SPI_TRANS_CS_KEEP_ACTIVE flag is specified while the bus was not acquired
(spi_device_acquire_bus() should be called first)
• ESP_ERR_TIMEOUT if there was no room in the queue before ticks_to_wait expired
• ESP_ERR_NO_MEM if allocating DMA-capable temporary buffer failed
• ESP_ERR_INVALID_STATE if previous transactions are not finished
• ESP_OK on success
Parameters
• handle: Device handle obtained using spi_host_add_dev
• trans_desc: Description of transaction to execute
• ticks_to_wait: Ticks to wait until there’s room in the queue; use portMAX_DELAY to never
time out.
esp_err_t spi_device_get_trans_result(spi_device_handle_t handle, spi_transaction_t
**trans_desc, TickType_t ticks_to_wait)
Get the result of a SPI transaction queued earlier by spi_device_queue_trans.
This routine will wait until a transaction to the given device succesfully completed. It will then return the
description of the completed transaction so software can inspect the result and e.g. free the memory or re-use
the buffers.
Return
• ESP_ERR_INVALID_ARG if parameter is invalid
• ESP_ERR_TIMEOUT if there was no completed transaction before ticks_to_wait expired
• ESP_OK on success
Parameters
Espressif Systems 375
Submit Document Feedback
Release v4.4