RS422/RS485 HAT
Application Note: How to use Modbus
1 Introduction
The RS422/RS485 HAT for the Raspberry Pi can be used for
Modbus systems. In Modbus RTU and Modbus ASCII RS485
is used as the physical layer.
Our RS422 / RS485 Serial HAT is a fully galvanic isolated serial
communication HAT designed for use with the Raspberry Pi and
the perfect choice for such kind of applications. The objective of
this document is to show how to configure the HAT and the
Raspberry Pi to be used for Modbus serial communication.
2 Bill of Material
●
Raspberry Pi B+, B2 or B3
●
RS422/RS485 serial HAT (available in our webstore)
3 Wiring
The wiring is very simple. You have to connect only the A and B
terminals of the HAT with the A and B line of the Modbus system.
Y and Z terminals are not used for this kind of application.
For long distances it is recommend to use twisted pairs for A and
B.
Application Note Modbus Rev B Page 1 of 5 02/2019
RS422/RS485 HAT
Application Note: How to use Modbus
5 DIP Switch Settings
The transmitting/receiving direction can be switched automaticaly:
SW1 SW2
1 OFF 1 OFF
2 ON 2 OFF
3 ON 3 ON
4 OFF 4 ON
Depending of the position of the RS422/RS485 HAT in the
Modbus line you have to switch the terminating resistor ON
or OFF. Please switch the resistor to ON position only if the
HAT is on one the end of the bus line. In all other cases
switch the terminating resistor OFF:
SW3
1 ON/OFF
2 OFF
3 ON
4 ON
Application Note Modbus Rev B Page 2 of 5 02/2019
RS422/RS485 HAT
Application Note: How to use Modbus
6 Free up Serial Line and Enable UART
6.1 Raspberry Pi 1 and 2 (old Raspbian Wheezy or Jessie)
On the Raspberry Pi 1 and 2 with an old Raspbian Wheezy or
Jessie ttyAMA0 might be used by the serial console.
To free it up do the following. Remove any references to
ttyAMA0 from /etc/inittab and /boot/[Link].
Our /boot/[Link] looks like this:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
Please follow this link for more information:
[Link]
If you want to run the latest version of Raspbian Stretch on
your old Raspberry Pi 1 or 2 please follow the tutorial for
Raspberry Pi 3 on the next page.
Application Note Modbus Rev B Page 3 of 5 02/2019
RS422/RS485 HAT
Application Note: How to use Modbus
6.2 Raspberry Pi 3A, 3B and 3B+ (Raspbian Stretch)
The easiest way is to use the raspi-config tool to switch the
UART to the GPIO14/15 pins.
●
take a fresh Raspbian image
●
sudo raspi-config
●
goto '5 Interfacing Options'
●
goto 'P6 Serial'
●
'Would you like a login shell to be accessible over serial?' --> NO
●
'Would you like the serial port hardware to be enabled?' --> YES
●
Finish raspi-config
●
reboot the Raspberry Pi
Now you can access the UART via /dev/serial0
Application Note Modbus Rev B Page 4 of 5 02/2019
RS422/RS485 HAT
Application Note: How to use Modbus
6.3 UART test
You can easily test the function of the internal UART with
Minicom or any other terminal program without a Modbus system.
If the UART /dev/serial0 is free and connected to the GPIO14/15
pins of the 2x20 header of the Raspberry Pi then the TX Led of the
HAT will blink when you send data from the terminal.
7 Software for Modbus
You will find an easy-to-use and tested Modbus RTU and Modbus
ASCII implementation for Python on:
MinimalModbus
Application Note Modbus Rev B Page 5 of 5 02/2019