ESP32S2 can't read data in duplex mode

Charles_Wen
Posts: 13
Joined: Fri Aug 06, 2021 1:39 am

ESP32S2 can't read data in duplex mode

Postby Charles_Wen » Thu Jun 02, 2022 12:19 pm

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?

ESP_Sprite
Posts: 9745
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32S2 can't read data in duplex mode

Postby ESP_Sprite » 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.

Charles_Wen
Posts: 13
Joined: Fri Aug 06, 2021 1:39 am

Re: ESP32S2 can't read data in duplex mode

Postby Charles_Wen » Mon Jun 06, 2022 3:04 am

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.

ESP_Sprite
Posts: 9745
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32S2 can't read data in duplex mode

Postby ESP_Sprite » Mon Jun 06, 2022 6:52 am

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.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 103 guests