Espressif ESP32-S2 Programming Manual page 380

Table of Contents

Advertisement

Chapter 2. API Reference
Transactions with Data Not Exceeding 32 Bits
will be sub-optimal to allocate a buffer for the data. The data can be directly stored in the transaction struct instead. For
transmitted data, it can be achieved by using the tx_data member and setting the SPI_TRANS_USE_TXDATA
flag on the transmission. For received data, use rx_data and set SPI_TRANS_USE_RXDATA. In both cases, do
not touch the tx_buffer or rx_buffer members, because they use the same memory locations as tx_data
and rx_data.
Transactions with Integers Other Than uint8_t
By default, data is sent with the most significant bit (MSB) first, as LSB first used in rare cases. If a value less than 8
bits needs to be sent, the bits should be written into memory in the MSB first manner.
For example, if 0b00010 needs to be sent, it should be written into a uint8_t variable, and the length for reading
should be set to 5 bits. The Device will still receive 8 bits with 3 additional "random"bits, so the reading must be
performed correctly.
On top of that, ESP32-S2 is a little-endian chip, which means that the least significant byte of uint16_t and
uint32_t variables is stored at the smallest address. Hence, if uint16_t is stored in memory, bits [7:0] are sent
first, followed by bits [15:8].
For cases when the data to be transmitted has the size differing from uint8_t arrays, the following macros can be
used to transform data to the format that can be sent by the SPI driver directly:
SPI_SWAP_DATA_TX
SPI_SWAP_DATA_RX
Notes on Sending Mixed Transactions to the Same Device
transactions (interrupt or polling) to one Device. However, you still can send both interrupt and polling transactions
alternately. The notes below explain how to do this.
The polling transactions should be initiated only after all the polling and interrupt transactions are finished.
Since an unfinished polling transaction blocks other transactions, please do not forget to call the function
spi_device_polling_end()
allow other Devices to use the bus. Remember that if there is no need to switch to other tasks during your polling
transaction, you can initiate a transaction with
automatically.
In-flight
polling
transactions
transactions.
Always make sure that all the interrupt transactions sent to the ISR are fin-
ished before you call spi_device_polling_start().
spi_device_get_trans_result()
To have better control of the calling sequence of functions, send mixed transactions to the same Device only within
a single task.
Transfer Speed Considerations
There are three factors limiting the transfer speed:
• Transaction interval
• SPI clock frequency
• Cache miss of SPI functions, including callbacks
The main parameter that determines the transfer speed for large transactions is clock frequency. For multiple small
transactions, the transfer speed is mostly determined by the length of transaction intervals.
Transaction Duration
Transaction duration includes setting up SPI peripheral registers, copying data to FIFOs or
setting up DMA links, and the time for SPI transaction.
Interrupt transactions allow appending extra overhead to accommodate the cost of FreeRTOS queues and the time
needed for switching between tasks and the ISR.
Espressif Systems
When the transaction data size is equal to or less than 32 bits, it
An SPI Host reads and writes data into memory byte by byte.
for data to be transmitted
for data received
after
spi_device_polling_start()
spi_device_polling_transmit()
are
disturbed
by
until all the transactions are returned.
369
Submit Document Feedback
To reduce coding complexity, send only one type of
to allow other transactions or to
the
ISR
operation
to
To do that, you can keep calling
so that it will be ended
accommodate
interrupt
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?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF