1# SPI Slave Halfduplex: Segment Mode Examples
2
3(See the README.md file in the 'examples' directory for more information about IDF examples.)
4
5These two projects illustrate the SPI Slave Halfduplex Segment Mode.
6* ``seg_slave`` shows one of the ways to use the SPI Slave Halfduplex driver. There are 2 tasks repeating to receive/send transactions from/to SPI Master respectively.
7* ``seg_master`` shows how to use the ESP Serial Slave Link APIs to communicate with SPI Slave Halfduplex driver. It receives/sends transactions from/to slave a few times.
8
9## How to use example
10
11### Hardware Required
12
13These two projects are supposed to be flashed onto two seperate boards and jumped together via correctly connected SPI pins defined in both of the ``app_main.c`` files. For the ``seg_master`` project, it could be flashed onto all the ESP Chips. Whereas the ``seg_slave`` currently could be flashed onto ESP32-S2. Once they are connected and flashed, they will use the SPI Master and SPI Slave Halfduplex drivers to communicate with each other.
14
15Following is the connection between 2 ESP32S2 boards:
16
17| Signal    | Master | Slave  |
18|-----------|--------|--------|
19| MOSI      | GPIO11 | GPIO11 |
20| MISO      | GPIO13 | GPIO13 |
21| SCLK      | GPIO12 | GPIO12 |
22| CS        | GPIO10 | GPIO10 |
23
24(Feel free to change the GPIO settings by editing the macro definations at the top of ``app_main.c`` files.)
25
26### Build and Flash
27
28Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
29
30(To exit the serial monitor, type ``Ctrl-]``.)
31
32See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for full steps to build, flash and monitor projects.
33
34## Example Output
35
36``seg_master``
37```
38---------SLAVE INFO---------
39
40Slave MAX Send Buffer Size:       5000
41Slave MAX Receive Buffer Size:    120
42I (328) SEG_MASTER: RECEIVING......
43Transaction No.0 from slave, length: 4640
44I (338) SEG_MASTER: SENDING......
45I (348) SEG_MASTER: RECEIVING......
46Transaction No.1 from slave, length: 3299
47I (348) SEG_MASTER: SENDING......
48I (358) SEG_MASTER: RECEIVING......
49Transaction No.2 from slave, length: 4836
50I (368) SEG_MASTER: SENDING......
51I (368) SEG_MASTER: RECEIVING......
52Transaction No.3 from slave, length: 3333
53I (378) SEG_MASTER: SENDING......
54I (378) SEG_MASTER: RECEIVING......
55Transaction No.4 from slave, length: 4965
56I (388) SEG_MASTER: SENDING......
57I (388) SEG_MASTER: RECEIVING......
58Transaction No.5 from slave, length: 3042
59I (398) SEG_MASTER: SENDING......
60I (408) SEG_MASTER: RECEIVING......
61Transaction No.6 from slave, length: 4892
62I (408) SEG_MASTER: SENDING......
63I (418) SEG_MASTER: RECEIVING......
64Transaction No.7 from slave, length: 3585
65I (428) SEG_MASTER: SENDING......
66I (428) SEG_MASTER: RECEIVING......
67Transaction No.8 from slave, length: 3348
68I (438) SEG_MASTER: SENDING......
69I (438) SEG_MASTER: RECEIVING......
70Transaction No.9 from slave, length: 4985
71I (448) SEG_MASTER: SENDING......
72I (448) SEG_MASTER: RECEIVING......
73Transaction No.10 from slave, length: 3710
74...
75```
76
77``seg_slave``
78```
7977 bytes are received:
80this is master's transaction 0
81109 bytes are received:
82this is master's transaction 1
8383 bytes are received:
84this is master's transaction 2
8597 bytes are received:
86this is master's transaction 3
8747 bytes are received:
88this is master's transaction 4
8989 bytes are received:
90this is master's transaction 5
9180 bytes are received:
92this is master's transaction 6
9396 bytes are received:
94this is master's transaction 7
9583 bytes are received:
96this is master's transaction 8
97110 bytes are received:
98this is master's transaction 9
99113 bytes are received:
100this is master's transaction 10
101...
102```
103
104## Troubleshooting
105
106For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you.
107