Half-duplex RMT help

Brief background:

I'm currenty trying to write code to handle the peculiar protocol of cs1237. The protocol requires two wires, one for clock signal and one for data. The clock signal is controlled by the esp32, but the data line is half-duplex, the length of the read and write periods of the data line is known.

So the main problem I'm stuck with is switching direction quickly while staying in sync, after some research, I've determined that RMT or bit-bang could do what I need.

However, with bit-bang, since a clock cycle could be as low as 1us, busy wait seems to be the only way, which I would prefer to avoid unless necessary.

Main Problem / TLDR:

Thus RMT is what I'm considering currently. I need help with hooking RMT TX and RX to the same data wire, while being in sync with another RMT TX on a seperate clock wire. The TX for data would start after a determined length of time (clock cycles). Before and after that, the data wire would be controlled and written by cs1237 (the target), so it should somehow be at high-z. Far as I'm aware, the cs1237 (the target) isn't open-drain.

Thanks in advance.

3 comments · 100% upvoted · other discussions

comments

BadVoices

RMT wont work, the turnaround time on switching the GPIO matrix isnt fast enough.

Bitbanging solves the issue in like, 15 minutes.

ooooooor.. use a resistor. connect the RS pin direct to the CS1237 data pin, then put a 1k or 2.2k resistor on the data line and connect it to the tx pin. Set the TX pin to high. When the CS1237 wants to send a 0, it pulls it low. When its done talking, it sets the line to high impedance and tx can pull low to send zeros. At this point, you just use 4 wire spi on the esp32 side (SCLK for clock, MISO, and MOSI) start at 100khz and work from there. Mode 1 probably will work. since hardware handles it, the cpu doesnt do anything really.

timothee_64 [OP]

Understood, thanks.

Plastic_Fig9225

Use SPI instead of the RMT. Route MISO and MOSI to the same pin and put the pin into input+output+open drain mode with pull-up enabled; an additional external pull-up may be required. Make the ESP send 1 bits whenever it's receiving data.