Page 1 of 1

ESP32S2 can't read data in duplex mode

Posted: Thu Jun 02, 2022 12:19 pm
by Charles_Wen
When use ESP32 conmmunicate with RC522 (NFC Controller), the SPI bus work ok, it can read and write RC522's register.
But when set the target to ESP32S3, the code complie fail. The error is:
SPI half duplex mode is not supported when both MOSI and MISO phases are enabled

Then find this in ESP32S3's programming guide:
Half-duplex transactions with both read and write phases are not supported. Please use full duplex mode.

Then comment this line :
.flags = SPI_DEVICE_HALFDUPLEX

It can complie success, can send data to SPI bus, but when reading data from the RC522, after send the register address which want read, the SPI bus hang up: the "CS"(chip select) line has been pull up, and no clock output on "clk" line.

What's wrong?

Re: ESP32S2 can't read data in duplex mode

Posted: Fri Jun 03, 2022 2:54 am
by ESP_Sprite
In full-duplex mode, the ESP starts reading in bytes while it is sending data: if you want to abuse this, you would need to make your rx_data buffer large enough to receive both the dummy bytes that are received while sending the address etc as well as the actual data you need to receive.

It's likely better to enable the built-in address field support: keep the SPI at half-duplex, but add a '.address_bits=8' to it. Then, when sending/receiving data, don't add a tx_data field but instead set the address using '.addr=xx' in the transaction descriptor.

Re: ESP32S2 can't read data in duplex mode

Posted: Mon Jun 06, 2022 3:04 am
by Charles_Wen
ESP_Sprite wrote:
Fri Jun 03, 2022 2:54 am
In full-duplex mode, the ESP starts reading in bytes while it is sending data: if you want to abuse this, you would need to make your rx_data buffer large enough to receive both the dummy bytes that are received while sending the address etc as well as the actual data you need to receive.

It's likely better to enable the built-in address field support: keep the SPI at half-duplex, but add a '.address_bits=8' to it. Then, when sending/receiving data, don't add a tx_data field but instead set the address using '.addr=xx' in the transaction descriptor.
Thank you very much. With the built-in address field suport, the problem is solved. But not keep the SPI at half-duplex, must keep it at full-duplex, otherwise, it will still throwout the error like this:
E (304) spi_master: check_trans_valid(703): SPI half duplex mode is not supported when both MOSI and MISO phases are enabled.

Re: ESP32S2 can't read data in duplex mode

Posted: Mon Jun 06, 2022 6:52 am
by ESP_Sprite
Yeah, the idea about the address is that you do not need the MOSI phase anymore to set the address. If you don't use that, you can do half-duplex.