|
|
@@ -9,7 +9,7 @@ Overview of {IDF_TARGET_NAME}'s SPI peripherals
|
|
|
|
|
|
.. only:: esp32 or esp32s2 or esp32s3
|
|
|
|
|
|
- {IDF_TARGET_NAME} integrates two general purpose SPI controllers which can be used as slave nodes driven by an off-chip SPI master
|
|
|
+ {IDF_TARGET_NAME} integrates two general purpose SPI controllers which can be used as slave nodes driven by an off-chip SPI master.
|
|
|
|
|
|
.. only:: esp32
|
|
|
|
|
|
@@ -20,7 +20,7 @@ Overview of {IDF_TARGET_NAME}'s SPI peripherals
|
|
|
|
|
|
.. only:: esp32c3 or esp32c2
|
|
|
|
|
|
- {IDF_TARGET_NAME} integrates one general purpose SPI controller which can be used as slave node driven by an off-chip SPI master. The controller is called SPI2 and has an independent signal bus with the same name.
|
|
|
+ {IDF_TARGET_NAME} integrates one general purpose SPI controller which can be used as a slave node driven by an off-chip SPI master. The controller is called SPI2 and has an independent signal bus with the same name.
|
|
|
|
|
|
|
|
|
Terminology
|
|
|
@@ -28,24 +28,38 @@ Terminology
|
|
|
|
|
|
The terms used in relation to the SPI slave driver are given in the table below.
|
|
|
|
|
|
-================= =========================================================================================
|
|
|
-Term Definition
|
|
|
-================= =========================================================================================
|
|
|
-**Host** The SPI controller peripheral external to {IDF_TARGET_NAME} that initiates SPI transmissions over the bus, and acts as an SPI Master.
|
|
|
-**Device** SPI slave device (general purpose SPI controller). Each Device shares the MOSI, MISO and SCLK signals but is only active on the bus when the Host asserts the Device's individual CS line.
|
|
|
-**Bus** A signal bus, common to all Devices connected to one Host. In general, a bus includes the following lines: MISO, MOSI, SCLK, one or more CS lines, and, optionally, QUADWP and QUADHD. So Devices are connected to the same lines, with the exception that each Device has its own CS line. Several Devices can also share one CS line if connected in the daisy-chain manner.
|
|
|
-- **MISO** Master In, Slave Out, a.k.a. Q. Data transmission from a Device to Host.
|
|
|
-- **MOSI** Master Out, Slave in, a.k.a. D. Data transmission from a Host to Device.
|
|
|
-- **SCLK** Serial Clock. Oscillating signal generated by a Host that keeps the transmission of data bits in sync.
|
|
|
-- **CS** Chip Select. Allows a Host to select individual Device(s) connected to the bus in order to send or receive data.
|
|
|
-- **QUADWP** Write Protect signal. Only used for 4-bit (qio/qout) transactions.
|
|
|
-- **QUADHD** Hold signal. Only used for 4-bit (qio/qout) transactions.
|
|
|
-- **Assertion** The action of activating a line. The opposite action of returning the line back to inactive (back to idle) is called *de-assertion*.
|
|
|
-**Transaction** One instance of a Host asserting a CS line, transferring data to and from a Device, and de-asserting the CS line. Transactions are atomic, which means they can never be interrupted by another transaction.
|
|
|
-**Launch edge** Edge of the clock at which the source register *launches* the signal onto the line.
|
|
|
-**Latch edge** Edge of the clock at which the destination register *latches in* the signal.
|
|
|
-================= =========================================================================================
|
|
|
-
|
|
|
+.. list-table::
|
|
|
+ :widths: 30 70
|
|
|
+ :header-rows: 1
|
|
|
+
|
|
|
+ * - Term
|
|
|
+ - Definition
|
|
|
+ * - Host
|
|
|
+ - The SPI controller peripheral external to {IDF_TARGET_NAME} that initiates SPI transmissions over the bus, and acts as an SPI Master.
|
|
|
+ * - Device
|
|
|
+ - SPI slave device (general purpose SPI controller). Each Device shares the MOSI, MISO and SCLK signals but is only active on the bus when the Host asserts the Device's individual CS line.
|
|
|
+ * - Bus
|
|
|
+ - A signal bus, common to all Devices connected to one Host. In general, a bus includes the following lines: MISO, MOSI, SCLK, one or more CS lines, and, optionally, QUADWP and QUADHD. So Devices are connected to the same lines, with the exception that each Device has its own CS line. Several Devices can also share one CS line if connected in the daisy-chain manner.
|
|
|
+ * - MISO
|
|
|
+ - Master In, Slave Out, a.k.a. Q. Data transmission from a Device to Host.
|
|
|
+ * - MOSI
|
|
|
+ - Master Out, Slave In, a.k.a. D. Data transmission from a Host to Device.
|
|
|
+ * - SCLK
|
|
|
+ - Serial Clock. Oscillating signal generated by a Host that keeps the transmission of data bits in sync.
|
|
|
+ * - CS
|
|
|
+ - Chip Select. Allows a Host to select individual Device(s) connected to the bus in order to send or receive data.
|
|
|
+ * - QUADWP
|
|
|
+ - Write Protect signal. Only used for 4-bit (qio/qout) transactions.
|
|
|
+ * - QUADHD
|
|
|
+ - Hold signal. Only used for 4-bit (qio/qout) transactions.
|
|
|
+ * - Assertion
|
|
|
+ - The action of activating a line. The opposite action of returning the line back to inactive (back to idle) is called *de-assertion*.
|
|
|
+ * - Transaction
|
|
|
+ - One instance of a Host asserting a CS line, transferring data to and from a Device, and de-asserting the CS line. Transactions are atomic, which means they can never be interrupted by another transaction.
|
|
|
+ * - Launch Edge
|
|
|
+ - Edge of the clock at which the source register *launches* the signal onto the line.
|
|
|
+ * - Latch Edge
|
|
|
+ - Edge of the clock at which the destination register *latches in* the signal.
|
|
|
|
|
|
|
|
|
Driver Features
|
|
|
@@ -61,7 +75,7 @@ SPI Transactions
|
|
|
|
|
|
A full-duplex SPI transaction begins when the Host asserts the CS line and starts sending out clock pulses on the SCLK line. Every clock pulse, a data bit is shifted from the Host to the Device on the MOSI line and back on the MISO line at the same time. At the end of the transaction, the Host de-asserts the CS line.
|
|
|
|
|
|
-The attributes of a transaction are determined by the configuration structure for an SPI host acting as a slave device :cpp:type:`spi_slave_interface_config_t`, and transaction configuration structure :cpp:type:`spi_slave_transaction_t`.
|
|
|
+The attributes of a transaction are determined by the configuration structure for an SPI peripheral acting as a slave device :cpp:type:`spi_slave_interface_config_t`, and transaction configuration structure :cpp:type:`spi_slave_transaction_t`.
|
|
|
|
|
|
As not every transaction requires both writing and reading data, you have a choice to configure the :cpp:type:`spi_transaction_t` structure for TX only, RX only, or TX and RX transactions. If :cpp:member:`spi_slave_transaction_t::rx_buffer` is set to NULL, the read phase will be skipped. If :cpp:member:`spi_slave_transaction_t::tx_buffer` is set to NULL, the write phase will be skipped.
|
|
|
|
|
|
@@ -93,7 +107,7 @@ Transaction Data and Master/Slave Length Mismatches
|
|
|
|
|
|
Normally, the data that needs to be transferred to or from a Device is read or written to a chunk of memory indicated by the :cpp:member:`spi_slave_transaction_t::rx_buffer` and :cpp:member:`spi_slave_transaction_t::tx_buffer`. The SPI driver can be configured to use DMA for transfers, in which case these buffers must be allocated in DMA-capable memory using ``pvPortMallocCaps(size, MALLOC_CAP_DMA)``.
|
|
|
|
|
|
-The amount of data that the driver can read or write to the buffers is limited by :cpp:member:`spi_slave_transaction_t::length`. However, this member does not define the actual length of an SPI transaction. A transaction's length is determined by a Host which drives the clock and CS lines. The actual length of the transmission can be read only after a transaction is finished from the member :cpp:member:`spi_slave_transaction_t::trans_len`.
|
|
|
+The amount of data that the driver can read or write to the buffers is limited by :cpp:member:`spi_slave_transaction_t::length`. However, this member does not define the actual length of an SPI transaction. A transaction's length is determined by the clock and CS lines driven by the Host. The actual length of the transmission can be read only after a transaction is finished from the member :cpp:member:`spi_slave_transaction_t::trans_len`.
|
|
|
|
|
|
If the length of the transmission is greater than the buffer length, only the initial number of bits specified in the :cpp:member:`spi_slave_transaction_t::length` member will be sent and received. In this case, :cpp:member:`spi_slave_transaction_t::trans_len` is set to :cpp:member:`spi_slave_transaction_t::length` instead of the actual transaction length. To meet the actual transaction length requirements, set :cpp:member:`spi_slave_transaction_t::length` to a value greater than the maximum :cpp:member:`spi_slave_transaction_t::trans_len` expected. If the transmission length is shorter than the buffer length, only the data equal to the length of the buffer will be transmitted.
|
|
|
|
|
|
@@ -118,24 +132,31 @@ If the length of the transmission is greater than the buffer length, only the in
|
|
|
|
|
|
.. only:: esp32
|
|
|
|
|
|
- +----------+------+------+
|
|
|
- | Pin Name | SPI2 | SPI3 |
|
|
|
- + +------+------+
|
|
|
- | | GPIO Number |
|
|
|
- +==========+======+======+
|
|
|
- | CS0* | 15 | 5 |
|
|
|
- +----------+------+------+
|
|
|
- | SCLK | 14 | 18 |
|
|
|
- +----------+------+------+
|
|
|
- | MISO | 12 | 19 |
|
|
|
- +----------+------+------+
|
|
|
- | MOSI | 13 | 23 |
|
|
|
- +----------+------+------+
|
|
|
- | QUADWP | 2 | 22 |
|
|
|
- +----------+------+------+
|
|
|
- | QUADHD | 4 | 21 |
|
|
|
- +----------+------+------+
|
|
|
-
|
|
|
+ .. list-table::
|
|
|
+ :widths: 40 30 30
|
|
|
+ :header-rows: 1
|
|
|
+
|
|
|
+ * - Pin Name
|
|
|
+ - GPIO Number (SPI2)
|
|
|
+ - GPIO Number (SPI3)
|
|
|
+ * - CS0*
|
|
|
+ - 15
|
|
|
+ - 5
|
|
|
+ * - SCLK
|
|
|
+ - 14
|
|
|
+ - 18
|
|
|
+ * - MISO
|
|
|
+ - 12
|
|
|
+ - 19
|
|
|
+ * - MOSI
|
|
|
+ - 13
|
|
|
+ - 23
|
|
|
+ * - QUADWP
|
|
|
+ - 2
|
|
|
+ - 22
|
|
|
+ * - QUADHD
|
|
|
+ - 4
|
|
|
+ - 21
|
|
|
|
|
|
* Only the first Device attached to the bus can use the CS0 pin.
|
|
|
|
|
|
@@ -172,17 +193,23 @@ The SPI slaves are designed to operate at up to {IDF_TARGET_MAX_FREQ} MHz. The d
|
|
|
- Write (MISO):
|
|
|
The output delay of the MISO signal needs to be shorter than half of a clock cycle period so that the MISO line is stable before the next latch edge. Given that the clock is balanced, the output delay and frequency limitations in different cases are given below.
|
|
|
|
|
|
- +-------------+---------------------------+------------------------+
|
|
|
- | | Output delay of MISO (ns) | Freq. limit (MHz) |
|
|
|
- +=============+===========================+========================+
|
|
|
- | IO_MUX | 43.75 | <11.4 |
|
|
|
- +-------------+---------------------------+------------------------+
|
|
|
- | GPIO matrix | 68.75 | <7.2 |
|
|
|
- +-------------+---------------------------+------------------------+
|
|
|
+ .. list-table::
|
|
|
+ :widths: 30 40 40
|
|
|
+ :header-rows: 1
|
|
|
+
|
|
|
+ * - /
|
|
|
+ - Output delay of MISO (ns)
|
|
|
+ - Freq. limit (MHz)
|
|
|
+ * - IO_MUX
|
|
|
+ - 43.75
|
|
|
+ - <11.4
|
|
|
+ * - GPIO matrix
|
|
|
+ - 68.75
|
|
|
+ - <7.2
|
|
|
|
|
|
Note:
|
|
|
- 1. If the frequency is equal to the limitation, it can lead to random errors.
|
|
|
- 2. The clock uncertainty between Host and Device (12.5ns) is included.
|
|
|
+ 1. If the frequency reaches the maximum limitation, random errors may occur.
|
|
|
+ 2. The clock uncertainty between the Host and the Device (12.5 ns) is included.
|
|
|
3. The output delay is measured under ideal circumstances (no load). If the MISO pin is heavily loaded, the output delay will be longer, and the maximum allowed frequency will be lower.
|
|
|
|
|
|
Exception: The frequency is allowed to be higher if the master has more tolerance for the MISO setup time, e.g., latch data at the next edge, or configurable latching time.
|