Chapter 2. API Reference
There are two other arguments: the event and the awoken. The event passes the information of the current
event to the callback. The
event type, the data descriptor just finished (The
argument is an output one, telling the ISR there are tasks are awoken after this callback, and the ISR should call
portYIELD_FROM_ISR() to do task scheduling. Just pass the awoken argument to all FreeRTOS APIs which may
unblock tasks, and the awoken will be returned to the ISR.
Writing/Reading Shared Registers
spi_slave_hd_read_buffer()
Note: On ESP32-S2, the shared registers are read/written in words by the application, but read/written in bytes by
the master. There's no guarantee four continuous bytes read from the master are from the same word written by the
slave's application. It's also possible that if the slave reads a word while the master is writing bytes of the word,
the slave may get one word with half of them just written by the master, and the other half hasn't been written into.
The master can confirm that the word is not in transition by reading the word twice and comparing the values.
For the slave, it will be more difficult to ensure the word is not in transition because the process of master writing
four bytes can be very long (32 SPI clocks). You can put some CRC in the last (largest address) byte of a word so
that when the byte is written, the word is sure to be all written.
Due to the conflicts there may be among read/write from SW (worse if there are multi cores) and master, it is suggested
that a word is only used in one direction (only written by master or only written by the slave).
Receiving General Purpose Interrupts From the Master
the slave corresponding will be triggered. Currently the CMD8 is permanently used to indicate the termination of
RDDMA segments. To receiving general purpose interrupts, register callbacks for CMD 0x09 and 0x0A when the
slave is initialized, see
Using
Application Example
The code example for Device/Host communication can be found in the
IDF examples.
API reference
Header File
•
components/driver/include/driver/spi_slave_hd.h
Functions
esp_err_t spi_slave_hd_init(spi_host_device_t
Initialize the SPI Slave HD driver.
Return
• ESP_OK: on success
• ESP_ERR_INVALID_ARG: invalid argument given
• ESP_ERR_INVALID_STATE: function called in invalid state, may be some resources are already
in use
• ESP_ERR_NOT_FOUND if there is no available DMA channel
• ESP_ERR_NO_MEM: memory allocation failed
• or other return value from esp_intr_alloc
Parameters
• host_id: The host to use
• bus_config: Bus configuration for the bus used
Espressif Systems
spi_slave_hd_event_t
data argument
Call
spi_slave_hd_write_buffer()
to read the shared buffer.
callbacks.
spi_slave_hd_slot_config_t
Submit Document Feedback
type contains the information of the event, for example,
will be very useful in this case!). The awoken
When the master sends CMD 0x08, 0x09 or 0x0A,
peripherals/spi_slave_hd
host_id, const
spi_bus_config_t
*config)
390
to write the shared buffer, and
directory of ESP-
*bus_config, const
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?
Questions and answers