1
\$\begingroup\$

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/blob/master/Arduino%20%26%20ESP8266/example/I2C_RECEIVE/I2C_RECEIVE.ino but nothing works. Some ideas?

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ There are some open inputs of U3 SC16IS752IPW, pin2 CTSA,, pin 28 CTSA, pin 27 CDA, pin 26 DTRA, pin25 DTSA. You should read the datasheet of this IC very carefully if it is possible to leave them open. \$\endgroup\$
    – Uwe
    Commented Dec 20, 2021 at 16:35

2 Answers 2

1
\$\begingroup\$

You need a lot of experience when working with asynchronos serial transmission using RS485. You need also some test equipment. A terminal program for windows using a serial interface of the PC would help to see what is send by the ESP32. You may also send from the terminal program to the ESP32.

terminal program

If the serial interface of the PC uses RS232 you need a converter to RS485. You need to know how to set the RS485 converter for sending or receiving.

RS232 converter to RS485

You should know the UART signals RXD, TXD, RTS, CTS, DTR, DSR, DCD and RI. You should know how to set and align baud rate, number of data bits, parity, and number of stop bits. I recommend using a signal indicator for the UART signals with LEDs.

signal indicator

Start small, take two PCs, run a terminal programm on both, connect the serial interfaces of both and send and receive data between them. You should be able to type some characters on one PC and read them on the other one. You should try it at first using RS232, if everything is ok, try RS485.

IF you are able to exchange serial data between the PCs using RS485, you may connect one PC to one ESP32. You should test output of the ESP32 and see the characters on the PC. Next is ouput from the PC to input into the ESP32.

If you are able to exchange data between PC and ESP32 in both directions you may try the connection of two ESP32. But you should use the PCs now as passive observers to the ESP32.

I do recommend to start with a very small and simple test. There is the BEEPER X1 controlled by the signal DTRB at pin 19 of U3. You should be able to set the beeper on and off with your test program. It is not useful do other more complex tests with U3 if this very basic test does not work.

\$\endgroup\$
10
  • \$\begingroup\$ Is this something like here mischianti.org/2020/05/11/…? \$\endgroup\$
    – noname
    Commented Dec 20, 2021 at 16:11
  • \$\begingroup\$ Some good information at mischanti, but a bad typo: RS458. \$\endgroup\$
    – Uwe
    Commented Dec 20, 2021 at 16:16
  • \$\begingroup\$ Ok I order few stuffs so I could make tests... few more things if I have data send on one side via RS485 can I simply read it on another side on ESP32 via RX pin witouht any components? So in my case I'm using device from schematic for sending data to pure ESP32 device? And how is with oposite, if I send from ESP32 to device which have RS485? Hope you understand what I'm asking. \$\endgroup\$
    – noname
    Commented Dec 21, 2021 at 12:15
  • 1
    \$\begingroup\$ 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 if I use some of free GPIO pins from UART? \$\endgroup\$
    – noname
    Commented Dec 22, 2021 at 6:40
  • 1
    \$\begingroup\$ RS485 direction control should be set before the first bit of the first serial character is send. It should be reset after the last bit of the last character. So this timing depends on baud rate and the number of all bits per character. I recommend to use hardware RTSA control. Don't use some of free GPIO pins from UART under software control. Check the description of all register bits. It may be possible you need a combination of several bits to be set and cleared. Have you tested the beeper with success? \$\endgroup\$
    – Uwe
    Commented Dec 22, 2021 at 8:13
0
\$\begingroup\$

Generally you keep the RS485 transceiver in receive mode and when you want to transmit you set it to transmit mode for the duration of the transmission.

\$\endgroup\$
8
  • \$\begingroup\$ Where I can see some example, how this should be done? I try for example with this code, but doesn't work: pastebin.com/3GqXRtNv \$\endgroup\$
    – noname
    Commented Dec 20, 2021 at 11:51
  • \$\begingroup\$ There is no info where and how you connected the RS485 transceiver transmit enable pin. \$\endgroup\$
    – Justme
    Commented Dec 20, 2021 at 12:26
  • \$\begingroup\$ How should I define that? \$\endgroup\$
    – noname
    Commented Dec 20, 2021 at 12:29
  • \$\begingroup\$ I don't even which RS485 transceiver you are using, or anything else about your hardware and how they are connected together, except the things you have mentioned. With the scarce information given it is hard to say anything specific. \$\endgroup\$
    – Justme
    Commented Dec 20, 2021 at 12:32
  • \$\begingroup\$ I append schematic in post, haven't you see it? SC16IS752 (IO expander) and SN65HVD72 (RS485) \$\endgroup\$
    – noname
    Commented Dec 20, 2021 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.