RS485 ESP32 half-duplex communication

peter1a
Posts: 3
Joined: Thu Dec 16, 2021 11:31 pm

RS485 ESP32 half-duplex communication

Postby peter1a » Mon Dec 20, 2021 12:09 pm

Hi, I have a question, so I have two identical devices that I would like to communicate via RX / TX (RS485). Both devices are exactly the same component, but as far as I know this is half-duplex mode, which means the first device sends, the second device receives and then again the second device receives and the first device sends. I have no idea how to write code for this communication. I found here as far as this chip is concerned https://github.com/nopnop2002/SC16IS752 also tried to load on both devices example code https://github.com/nopnop2002/SC16IS752 ... 2C_RECEIVE but nothing works. Some ideas?

Image

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

Re: RS485 ESP32 half-duplex communication

Postby ESP_Sprite » Tue Dec 21, 2021 1:41 am

Did you look at the examples included in esp-idf already?

peter1a
Posts: 3
Joined: Thu Dec 16, 2021 11:31 pm

Re: RS485 ESP32 half-duplex communication

Postby peter1a » Tue Dec 21, 2021 6:54 am

ESP_Sprite wrote:
Tue Dec 21, 2021 1:41 am
Did you look at the examples included in esp-idf already?
What about components which I use, should I also define them somehow? Uart expander (SC16IS752IPW) and RS485 (SN65HVD72D)?

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

Re: RS485 ESP32 half-duplex communication

Postby ESP_Sprite » Wed Dec 22, 2021 2:49 am

The RS485 chip is transparent; it should just work with the example to my knowledge. I don't think we have specific code for the UART expander chip you're using.

EDIT: Ah, the ESP32 is connected via SPI to the SC16IS752IPW, which is then connected to the RS485 chip? Sorry, then the example is useless (as it assumes you use the ESP32s internal UARTS) and we don't have a driver for the SC16IS752IPW (it seems like a fairly obscure chip)

Why don't you nix the SC16IS752IPW and simply connect the SN65HVD72D chip directly to the ESP32? The ESP32 has 3 UARTs, it's not like you're lacking that.

peter1a
Posts: 3
Joined: Thu Dec 16, 2021 11:31 pm

Re: RS485 ESP32 half-duplex communication

Postby peter1a » Wed Dec 22, 2021 6:39 am

After hours of reading I understand I need to set pin to low/high when receiving or transmiting. So I need to set pins (basically one pin for both on RS485 component DE & !RE) to high/low. Those pin is in my case connected to RTSA pin of UART which should do this job automatically based on datasheet, do I need to enable somehow auto RTS? In datasheet it says:
This pin only affects the transmit and receive operations when Auto-RTS function is enabled via the Enhanced Features Register (EFR[6]) for hardware flow control operation.

Would be better in my case if I use some of free GPIO pins from UART and manually changing pin to low/high?

Who is online

Users browsing this forum: zilizii and 162 guests