Serial Interface

There is a setting in sudo raspi-config that connects the serial interface to the login shell.

Connect a second Linux computer having a USB to serial 3V3 cable and appearing as /dev/ttyUSB0 then type screen /dev/ttyUSB0 115200

If it is desired to use a regular application for it, use sudo raspi-config to disable the console on the serial interface but enable to use the serial interface and sudo reboot

Important

There are two UARTs Mini-UART (ttyS0) and PL011 UART (ttyAMA0). Since the serial interfaces is usually not used the better UART PL011 is used for the bluetooth module. However this can be reconfigured, therefore use /dev/serial0 since it is a link to the UART used for the serial interface. ls -la /dev/serial0 will show which UART is used.

The Mini-UART has a side effect of not having a stable frequency under heavy CPU load, this might cause communication problems on the serial interface. To have a stable serail interface those UARTs can be switched by adding to /boot/firmware/config.txt

dtoverlay=miniuart-bt

Now do on the Raspberry sudo screen /dev/serial0 115200 and both computers can exchange data via the serial interface.

Serial with RS485

For regular RS485 driver chips an driver enable signal is required. The Raspberries UART can not create this RTS signal for that.

However pyserial can do this. To have the signal appear:

sudo pinctrl set 17 a3

And to verify

sudo pinctrl 17

17: a3 -- | lo // GPIO17 = RTS0

One way to have this persistent is creating a systemd service /etc/systemd/system/uart-rts-pin.service

[Unit]
Description=Set GPIO17 to ALT3 (UART0 RTS) for RS485
DefaultDependencies=no
Before=sysinit.target

[Service]
Type=oneshot
ExecStart=/usr/bin/pinctrl set 17 a3
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

When the application is started as systemd service then a dependency has to be added:

[Unit]
Requires=uart-rts-pin.service


Linurs startpage