|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | - | - |
| master/ | | 11-Mar-2024 | - | 190 | 132 |
| slave/ | | 11-Mar-2024 | - | 268 | 180 |
| README.md | D | 11-Mar-2024 | 4.7 KiB | 107 | 83 |
README.md
1# SPI Halfduplex Slave Append Mode Example
2
3(See the README.md file in the upper level 'examples' directory for more information about examples.)
4
5This example demonstrates how to use the SPI Slave HD driver and ESSL driver in IDF to communicate:
6(ESSL driver is an encapsulated layer based on SPI Master driver to communicate with halfduplex mode SPI Slave.)
7* Slave waits for Master to initiate ESSL SPI send and receive request using the SPI Slave HD driver.
8
9* Slave will continuously prepare TX / RX buffers to the HW for Master to read / write. It will always load its buffer to the HW when the internal queue (see `queue_size` in `spi_slave_hd_slot_config_t`) is not full. It doesn't need to wait until a transaction finishes to prepare next buffer to the HW, so as to increase the transaction speed.
10* Master will receive a bunch of packets from the slave for a fixed number of iterations, then send a bunch of packets for a fixed number of iterations.
11
12If you have your own Master, please follow the [Espressif ESP32-S2 Technical Reference Manual-SPI Slave Halfduplex](https://www.espressif.com/sites/default/files/documentation/esp32-s2_technical_reference_manual_en.pdf) for the data format.
13
14
15**Suggest building/flashing/monitoring Slave example first**
16Usually SPI Slave will try to make its buffer ready to be able to respond immediately. In this example, you could run Slave code first to prepare more buffer to the HW. Therefore you will have `queue_size` number of buffers which are ready for the transaction. And each time there is a vacancy, Slave can load its buffer to the HW.
17
18## How to use example
19
20### Hardware Required
21
22This example requires 2 targets. Here we use 2 ESP32S2 DevKits to act as the SPI Master and SPI Slave respectively. Suggested pin connections are here:
23
24| Signal | Master | Slave |
25|-----------|--------|--------|
26| CS | GPIO10 | GPIO10 |
27| SCLK | GPIO12 | GPIO12 |
28| MOSI | GPIO11 | GPIO11 |
29| MISO | GPIO13 | GPIO13 |
30| GND | GND | GND |
31
32Feel free to modify the pin setting defined on the top of the ``app_main.c``.
33
34### Configure the project
35
36* Set the target of the build (where `{IDF_TARGET}` stands for the target chip such as `esp32s2`).
37
38```
39idf.py set-target {IDF_TARGET}
40```
41
42### Build and Flash
43
44For each target, build the project and flash it to the board, then run monitor tool to view the output:
45
46```
47idf.py -p PORT flash monitor
48```
49
50(Replace PORT with the name of the serial port to use.)
51
52(To exit the serial monitor, type ``Ctrl-]``.)
53
54See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
55
56## Example Output
57
58SPI Master
59```
60I (320) Master: Receiver
61I (470) Receiver: 8 bytes are actually received:
62I (470) Receiver: 21 22 23 24 25 26 27 28
63I (560) Receiver: 8 bytes are actually received:
64I (560) Receiver: 29 2a 2b 2c 2d 2e 2f 30
65I (650) Receiver: 8 bytes are actually received:
66I (650) Receiver: 2b 2c 2d 2e 2f 30 31 32
67I (740) Receiver: 8 bytes are actually received:
68I (740) Receiver: 33 34 35 36 37 38 39 3a
69I (830) Receiver: 8 bytes are actually received:
70I (830) Receiver: 0c 0d 0e 0f 10 11 12 13
71I (920) Receiver: 8 bytes are actually received:
72I (920) Receiver: 14 15 16 17 18 19 1a 1b
73I (1010) Receiver: 8 bytes are actually received:
74I (1010) Receiver: 1d 1e 1f 20 21 22 23 24
75I (1100) Receiver: 8 bytes are actually received:
76I (1100) Receiver: 25 26 27 28 29 2a 2b 2c
77I (1190) Receiver: 8 bytes are actually received:
78I (1190) Receiver: 00 01 02 03 04 05 06 07
79I (1280) Receiver: 8 bytes are actually received:
80I (1280) Receiver: 08 09 0a 0b 0c 0d 0e 0f
81I (1280) Master: Sender
82```
83
84SPI Slave
85```
86I (6343) Receiver: 16 bytes are actually received:
87I (6343) slave RX:: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
88I (6523) Receiver: 16 bytes are actually received:
89I (6523) slave RX:: 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10
90I (6703) Receiver: 16 bytes are actually received:
91I (6703) slave RX:: 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11
92I (6883) Receiver: 16 bytes are actually received:
93I (6883) slave RX:: 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12
94I (7063) Receiver: 16 bytes are actually received:
95I (7063) slave RX:: 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13
96I (7243) Receiver: 16 bytes are actually received:
97I (7243) slave RX:: 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14
98I (7473) Receiver: 16 bytes are actually received:
99I (7473) slave RX:: 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15
100I (7653) Receiver: 16 bytes are actually received:
101I (7653) slave RX:: 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16
102I (7833) Receiver: 16 bytes are actually received:
103I (7833) slave RX:: 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17
104I (8013) Receiver: 16 bytes are actually received:
105I (8013) slave RX:: 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18
106```
107