Chapter 2. API Reference
The driver supports two types of transactions: the interrupt transactions and polling transactions. The programmer
can choose to use a different transaction type per Device. If your Device requires both transaction types, see
on Sending Mixed Transactions to the Same
Interrupt Transactions
Interrupt transactions will block the transaction routine until the transaction completes,
thus allowing the CPU to run other tasks.
An application task can queue multiple transactions, and the driver will automatically handle them one-by-one in the
interrupt service routine (ISR). It allows the task to switch to other procedures until all the transactions complete.
Polling Transactions
Polling transactions do not use interrupts. The routine keeps polling the SPI Host's status
bit until the transaction is finished.
All the tasks that use interrupt transactions can be blocked by the queue. At this point, they will need to wait for the
ISR to run twice before the transaction is finished. Polling transactions save time otherwise spent on queue handling
and context switching, which results in smaller transaction duration. The disadvantage is that the CPU is busy while
these transactions are in progress.
The
spi_device_polling_end()
the transaction is finished. It is strongly recommended to wrap a series of polling transactions using the functions
spi_device_acquire_bus()
formation, see
Bus
Acquiring.
Transaction Line Mode
Supported line modes for ESP32-S2 are listed as follows, to make use of these modes,
set the member flags in the struct
to check if corresponding IO pins are set or not, set the member flags in the
Bus IO setting Flag column.
Mode
Com-
Address
name
mand
Line
Line
Width
Width
Nor-
1
1
mal
SPI
Dual
1
1
Out-
put
Dual
1
2
I/O
Quad
1
1
Out-
put
Quad
1
4
I/O
Octal
1
1
Out-
put
OPI
8
8
Command and Address Phases
struct
spi_transaction_t
and address phases are set in
If the flags SPI_TRANS_VARIABLE_CMD and SPI_TRANS_VARIABLE_ADDR in the member
Espressif Systems
Device.
routine needs an overhead of at least 1 us to unblock other tasks when
and
spi_device_release_bus()
spi_transaction_t
Data
Transaction Flag
Line
Width
1
0
2
SPI_TRANS_MODE_DIO
2
SPI_TRANS_MODE_DIO
SPI_TRANS_MULTILINE_ADDR
4
SPI_TRANS_MODE_QIO
4
SPI_TRANS_MODE_QIO
SPI_TRANS_MULTILINE_ADDR
8
SPI_TRANS_MODE_OCT
8
SPI_TRANS_MODE_OCT
SPI_TRANS_MULTILINE_ADDR
SPI_TRANS_MULTILINE_CMD
During the command and address phases, the members cmd and addr in the
are sent to the bus, nothing is read at this time. The default lengths of the command
spi_device_interface_config_t
367
Submit Document Feedback
to avoid the overhead. For more in-
as shown in the Transaction Flag column. If you want
spi_bus_config_t
by calling spi_bus_add_device().
Notes
as shown in the
Bus IO setting
Flag
0
SPICOM-
MON_BUSFLAG_DUAL
|
SPICOMMON_BUSFLAG_QUAD
|
SPICOMMON_BUSFLAG_OCTAL
|
|
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?