problem about esp32 spi half duplex

szsheep
Posts: 3
Joined: Sat Mar 07, 2026 4:44 am

problem about esp32 spi half duplex

Postby szsheep » Wed Jun 03, 2026 2:56 am

### Background
An MCU is connected to the ESP32C3 via SPI (MOSI, MISO, CLK, CS) plus GPIO pins, with the ESP32 half-duplex SPI protocol adopted for communication.

### Phenomenon
I am using the segmented mode of half-duplex SPI. During initialization, 16 buffer buckets are initialized and consecutively enqueued via `spi_slave_hd_queue_trans`. After power-up, the master device first runs two successive transaction sequences consisting of (WRDMA + WR_DONE). Afterwards, the master repeats the identical two rounds of (WRDMA + WR_DONE) transactions again, with test results listed below:
- For the initial two transactions, the slave retrieves valid data consistently every time by calling `spi_slave_hd_get_trans_res`.
- For the subsequent two repeated transactions, the slave obtains incorrect data on the first read via `spi_slave_hd_get_trans_res`, while the second read returns correct data.

Moreover, after the initial batch of transactions, every subsequent continuous (WRDMA + WR_DONE) transaction sequence keeps showing faulty data at the first reception and valid readings from the second transfer onward.

I have failed to pinpoint the root cause of this issue. Is some DMA state recovery required after the first round of operations? Any suggestions would be highly appreciated.

molejnik_bct
Posts: 2
Joined: Tue Mar 31, 2026 2:55 pm

Re: problem about esp32 spi half duplex

Postby molejnik_bct » Wed Jun 03, 2026 7:43 am

Few suggestions from the top of my head. The are only to help to find the root of the issue (not meant as a permanent solution):
- double check Phase and Polarity of the clock matches between master and slave
- reduce SPI clock to minimum for verification purposes
- send smaller packets (worth of 1 or 2 bytes) for verification purposes to check the same fault pattern occurs (some packets OK, same faulty)
- send packets with identical contents for verification purposes to check the same fault pattern occurs
- verify signal integrity with oscilloscope, check the master sends correct signals in all instances. You did not mention whether MCU and C6 is on the same PCB or are interconnected via connector or even cables.
- if possible use a different MCU (not ESP) as a slave. Use Arduino based boards to verify it correctly receives the SPI transactions from your SPI master.
- bit bang your slave SPI implementation if all above seems to work fine

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 2 guests