problem about esp32 spi half duplex
Posted: 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.
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.