walid yahia
Posts: 3
Joined: Thu Aug 19, 2021 8:48 am

Sending data using RS485

Tue Sep 14, 2021 4:47 pm

I have a solution which depend on RS485 to communicate with other device, I need some help for these questions:

How can I enable Rts and Cts pins on Raspberry pi4 ?
Also, How can implement RS485 communication using C#?
Last edited by walid yahia on Wed Sep 15, 2021 8:02 am, edited 2 times in total.

Heater
Posts: 18515
Joined: Tue Jul 17, 2012 3:02 pm

Re: Sending data using RS485

Tue Sep 14, 2021 8:42 pm

In linux one can control RTS/CTS and other serial port features using ioctl() system calls on the serial device.
https://man7.org/linux/man-pages/man2/ioctl_tty.2.html

I have only ever done this in C. You will find examples of doing that all over the net. For example: https://www.xanthium.in/Controlling-RTS ... t-in-Linux

Apparently it can be done in C# easily as well:
https://www.xanthium.in/Serial-Programm ... on-Windows
https://create.arduino.cc/projecthub/sx ... nux-0f2ed4
Memory in C++ is a leaky abstraction .

stevend
Posts: 399
Joined: Fri Oct 11, 2013 12:28 pm

Re: Sending data using RS485

Wed Sep 15, 2021 12:57 pm

Heater wrote:
Tue Sep 14, 2021 8:42 pm
I have only ever done this in C. You will find examples of doing that all over the net. For example: https://www.xanthium.in/Controlling-RTS ... t-in-Linux
But that doesn't work for the integral Pi serial ports - it's not implemented in the PL011 UART serial driver; nor does the driver support the type of RTS control needed to enable an RS485 transceiver.
I'm implementing a similar requirement (in C), and as far as I can tell there's little option but to configure the RTS pin as a simple output, and control it directly in code.

Heater
Posts: 18515
Joined: Tue Jul 17, 2012 3:02 pm

Re: Sending data using RS485

Wed Sep 15, 2021 3:01 pm

Good point. Everything depends on the serial port features the hardware supports.

Using a GPIO pin to get the job done will do it.
Memory in C++ is a leaky abstraction .

MiscBits
Posts: 267
Joined: Wed Jan 27, 2021 12:48 pm

Re: Sending data using RS485

Sun Sep 19, 2021 10:26 pm

Strange, the only RS/485 I've done is two wire simplex or four wire duplex and RTS/CTS has not been used.

Even 422 was two wire though the interface could not go tri-state.

A quick check on the pi hut website shows only the AB pins on the output (plus ground though not needed).

The main issue I remember is that some chip sets had a habit of inverting the signal voltage (grrr)...
Is a computer language with goto's totally Wirth-less?

Heater
Posts: 18515
Joined: Tue Jul 17, 2012 3:02 pm

Re: Sending data using RS485

Mon Sep 20, 2021 11:56 am

MiscBits wrote:
Sun Sep 19, 2021 10:26 pm
Strange, the only RS/485 I've done is two wire simplex or four wire duplex and RTS/CTS has not been used.
Not strange at all.

RS485 can transmit and receive over the same two wires. That means the transmitter has to be disabled when it is required to receive. That is to say the transmitter is a trigger-state output and requires an enable pin to control trigger-state.

This is not Request To Send (RTS) or Clear To Send (CTS) signalling as sometimes used for flow control in RS232 links. But presumably RTS can be used as the RS485 transmit buffer enable signal.

See: https://www.eeweb.com/rs-485-transceiver-tutorial/
Memory in C++ is a leaky abstraction .

stevend
Posts: 399
Joined: Fri Oct 11, 2013 12:28 pm

Re: Sending data using RS485

Mon Sep 20, 2021 12:29 pm

Heater wrote:
Mon Sep 20, 2021 11:56 am
MiscBits wrote:
Sun Sep 19, 2021 10:26 pm
Strange, the only RS/485 I've done is two wire simplex or four wire duplex and RTS/CTS has not been used.
Not strange at all.

RS485 can transmit and receive over the same two wires. That means the transmitter has to be disabled when it is required to receive. That is to say the transmitter is a trigger-state output and requires an enable pin to control trigger-state.

This is not Request To Send (RTS) or Clear To Send (CTS) signalling as sometimes used for flow control in RS232 links. But presumably RTS can be used as the RS485 transmit buffer enable signal.

See: https://www.eeweb.com/rs-485-transceiver-tutorial/
'RS-485' has come to mean 'multidrop bus with differential signalling' in some quarters. Certainly most of the RS-484 busses I've come across have been 4-wire, which is often easier to faultfind, and means that the master's transmitter can be left permanently enabled.

Some of the RS-485 interfaces on the market use a dreadful kludge (using a retriggerable timer) which enables the transmitter immediately a start bit is detected - so there's no setup time to help receiver noise immunity, but it does mean that you just need Tx and Rx from the UART.

Some modern embedded systems (e.g. STM32) can be configured to manage the RTS timings (and polarity) in hardware; otherwise it has to be done using software. Linux includes RS-485 mode capabilities (including control of RS-485 polarity) which need low-level (software) driver support; this isn't implemented for the Pi's embedded UARTs, but may be supported for some that you can add via SPI or I2C.

Return to “Other programming languages”