# How to use the RS485 on Aria module

<abstract>
This article illustrates how to use the serial ports of Aria 
to manage them as RS485 line
</abstract>

RS485 driver IC like [MAX485](https://datasheets.maximintegrated.com/en/ds/MAX1487-MAX491.pdf)
needs three signals to manage an RS485 bus. These lines are:

* TXD Transmit data
* RXD Receive data
* DE Driver Enable data

Some of the serial ports available on the AT91SAMG25 MPU used on Aria G25
can use the RTS line as a DE line to be used with a RS485 driver chip.

To set the serial ports to work as RS485 instead of RS232 in required to
tell to the Linux serial driver to work as RS485 trought the Device Tree
Binding definition as explayed below.

## Suitable signals

This is the list of suitable signal available on [Aria pinout](/pinout_aria) useful 
to implements up three RS485 lines.

### usart0 - /dev/ttyS1

| Signal | Description                        | MCU line    | Aria line |
|--------|------------------------------------|-------------|-----------|
| TXD0   | TX line (out)                      | PA0         | S23       |
| RXD0   | RX line (inp)                      | PA1         | S22       |
| RTS0   | DE/RTS Driver enable               | PA2         | S21       |

	usart0: serial@f801c000 {
		pinctrl-0 = <&pinctrl_usart0 &pinctrl_usart0_rts>;
	    linux,rs485-enabled-at-boot-time;
	    rs485-rts-delay = <0 20>;
		status = "okay";
	};


### usart1 - /dev/ttyS2

| Signal | Description                        | MCU line    | Aria line |
|--------|------------------------------------|-------------|-----------|
| TXD1   | TX line (out)                      | PA5         | S18       |
| RXD1   | RX line (inp)                      | PA6         | S17       |
| RTS1   | DE/RTS Driver enable               | PC27        | E7        |

	usart1: serial@f8020000 {
	    pinctrl-0 = <&pinctrl_usart1 &pinctrl_usart1_rts>;
	    linux,rs485-enabled-at-boot-time;
	    rs485-rts-delay = <0 20>;
	    status = "okay";
	};

### usart2 - /dev/ttyS3

The DE/RTS pin of usart2 (/dev/ttyS3) port is not available on Aria pinout so it can be used in RS485 mode

### usart3 - /dev/ttyS4

| Signal | Description                        | MCU line    | Aria line |
|--------|------------------------------------|-------------|-----------|
| TXD3   | TX line (out)                      | PC22        | E2        |
| RXD3   | RX line (inp)                      | PC23        | E3        |
| RTS3   | DE/RTS Driver enable               | PC24        | E4        |

To use the /dev/ttyS3 you have to include in your dts this file: 

	#include "at91sam9x5_usart3.dtsi"	

then use this definition:

	usart3: serial@f8028000 {
		pinctrl-0 = <&pinctrl_usart3 &pinctrl_usart3_rts>;
	    linux,rs485-enabled-at-boot-time;
	    rs485-rts-delay = <0 20>;
		status = "okay";
	};

## Links

* [Acme Systems dts repository](https://github.com/AcmeSystems/dts-archive)
* [Aria G25 pinout](/pinout_aria)
* @article='DAISY-10'

@include='bio_tanzilli'
