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. There's no notable delay on chips other than ESP32.
- ESP_ERR_INVALID_ARG if parameter is invalid or configuration combination is not supported (e.g. `dev_config->post_cb` isn't set while flag `SPI_DEVICE_NO_RETURN_RESULT` is enabled) - ESP_ERR_INVALID_STATE if selected clock source is unavailable or spi bus not initialized - 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
Notes
On ESP32, due to the delay of GPIO matrix, the maximum frequency SPI Master can correctly samples the slave's output is lower than the case using IOMUX. Typical maximum frequency communicating with an ideal slave without data output delay: 80MHz (IOMUX pins) and 26MHz (GPIO matrix pins). With the help of extra dummy cycles in half-duplex mode, the delay can be compensated by setting `input_delay_ns` in `dev_config` structure correctly.
Examples
spi_bus_add_device() is referenced by 20 libraries and example projects: