batt61
Posts: 4
Joined: Tue Nov 26, 2019 8:03 pm

RS485 and RTS support in Raspberry Pi 4

Tue Nov 26, 2019 8:24 pm

Hello,
I am trying to use a Raspberry Pi 4 model B to drive the DE enable signal of a MAX485 for half-duplex RS485 communication.

I have connected the UART0 data signals (GPIO 14 & 15) and am trying to use RTS (GPIO 17) to enable the TX section of MAX485.

I was able to enable the RTS signal by writing this device tree overlay:

Code: Select all

/dts-v1/;
/plugin/;

/{
	compatible = "brcm,bcm2835";

	fragment@0 {
		target = <&uart0>;
		__overlay__ {
			pinctrl-names = "default";
			pinctrl-0 = <&uart0_pins>;
			status = "okay";
		};
	};

	fragment@1 {
		target = <&gpio>;
		__overlay__ {
			uart0_pins: uart0_pins {
				brcm,pins = <14 15 17>;
				brcm,function = <4 4 7>; //alt0 alt0 alt3
				brcm,pull = <0 2 0>;
			};
		};
	};
};

Using an oscilloscope, I checked the TX (CH2) and RTS signal (CH1):
IMG_1315.jpeg
IMG_1315.jpeg (171.18 KiB) Viewed 2480 times
As you can see, while the TX line transmits a byte, the RTS signal has a negative pulse.
The pulse is slightly longer than the transmitted data, but the actual problem is that the MAX485 (and almost all other RS485 signal translators) needs a HIGH signal to enable the TX.

Do you know if/how I can invert the RTS?

--
Francesco

batt61
Posts: 4
Joined: Tue Nov 26, 2019 8:03 pm

Re: RS485 and RTS support in Raspberry Pi 4

Wed Nov 27, 2019 10:10 am

I have also tried to add

Code: Select all

linux,rs485-enabled-at-boot-time; 
in the Device Tree as specified in this post:

https://www.raspberrypi.org/forums/view ... p?t=234478

But the behaviour of the RTS line is the same: it stays HIGH and goes LOW during transmission.

Anyone have any idea on how to reverse this?

--
Francesco

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 12850
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: RS485 and RTS support in Raspberry Pi 4

Wed Nov 27, 2019 12:54 pm

Read the RS485 device tree binding docs and you'd see "rs485-rts-active-low: drive RTS low when sending (default is high)."
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

batt61
Posts: 4
Joined: Tue Nov 26, 2019 8:03 pm

Re: RS485 and RTS support in Raspberry Pi 4

Wed Nov 27, 2019 5:55 pm

Thank you for your reply, I've already tried with and without the 'rs485-rts-active-low' option, and the behaviour is unchanged :(

danjperron
Posts: 3976
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: RS485 and RTS support in Raspberry Pi 4

Wed Nov 27, 2019 7:00 pm

Hi Batt61,

If I understand you did an overlay to enable RTS. You have link to Hiassoft github and it is more or less the same than yours.

But enable RTS to be available is just the first part. The other part is to use it.


I don't see in your comment the application you are using to communicate via rs-485.

Check
Pyserial with the rs_485_mode

https://pyserial.readthedocs.io/en/late ... 85Settings

In C , via termios, RTS will be space signal if something need to be send. Space signal is TTL 0 Volt. This mean you can't enable the RTS handshake.


If you are using C you need to create your own function to Turn RTS ON/OFF before sending anything. The other possibility is to invert the signal going throught DE.

Rs-485 dongle are so cheap that using an MAX-485 is more expensive.

batt61
Posts: 4
Joined: Tue Nov 26, 2019 8:03 pm

Re: RS485 and RTS support in Raspberry Pi 4

Wed Nov 27, 2019 7:54 pm

Hi Danjperron,

My test is:

Code: Select all

echo -n "0" > /dev/ttyAMA0
The whole issue is here: I cannot move manually (or through a specific library) the RTS line because in my application I cannot change the sender/receiver code. it's not under my control.

In the past, I have used the device tree RS485 options on another CPU (Atmel SAM A5) and it worked automatically without any special program.

danjperron
Posts: 3976
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: RS485 and RTS support in Raspberry Pi 4

Wed Nov 27, 2019 8:21 pm

In the past, I have used the device tree RS485 options on another CPU (Atmel SAM A5) and it worked automatically without any special program.
You are correct a lot of those chips are connected directly to the RS-232 which has the signal inverted (TTL 0 = +(12/15V), TTL 1 = -(12/15V).

The only thing I could think of is to invert the DE signal using a simple transistor with two resistors. or use a small cpu to handle the direction.
https://github.com/danjperron/RS485swit ... switch.jpg

Return to “Troubleshooting”