EasyManuals Logo

Espressif ESP32-S2 User Manual

Espressif ESP32-S2
1695 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #401 background imageLoading...
Page #401 background image
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 spi_slave_hd_event_t type contains the information of the event, for example,
event type, the data descriptor just finished (The data argument will be very useful in this case!). The awoken
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 Call spi_slave_hd_write_buffer() to write the shared buffer, and
spi_slave_hd_read_buffer() to read the shared buffer.
Note: On ESP32-S2, the shared registers are read/written in words by the application, but read/written in bytes by
the master. Theres no guarantee four continuous bytes read from the master are from the same word written by the
slaves application. Its 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 hasnt 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 When the master sends CMD 0x08, 0x09 or 0x0A,
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 callbacks.
Application Example
The code example for Device/Host communication can be found in the peripherals/spi_slave_hd directory of ESP-
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 host_id, const spi_bus_config_t *bus_config, const
spi_slave_hd_slot_config_t *config)
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 390
Submit Document Feedback
Release v4.4

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

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

Espressif ESP32-S2 Specifications

General IconGeneral
BrandEspressif
ModelESP32-S2
CategorySingle board computers
LanguageEnglish