• sales

    +86-0755-88291180

2-CH RS485 HAT

Introduction


This is a dual-channel isolated RS485 extension board specially designed for raspberry PI, which adopts SC16IS752+SP3485 solution, embed with protection circuits such as power supply isolation, ADI magnetical isolation, and TVS diode, etc. It is easy to control the 2-channel RS485 for auto transceiving via SPI interface. Due to its fast communication, stability, reliability, and safety, it is an ideal choice for fields like industrial automation.

Interfaces

VCC3.3V
PINDescription
VCC3.3V/5V Power
GNDGround
SCLKSPI Clock input
MOSISPI Data input
MISOSPI Data output
CSSPI Chip Selection
IRQInterrupt output (Interrupt Request)
EN1Channel 1 output enable
EN2Channel 2 output enable


Working principle

Introduction



This product adopts SC16IS752 as controller. SC16IS752 is a dual-channel high-performance UART expansion chip that supports SPI and I2C interfaces communication. This module uses SPI interface. Onboard power isolation, ADI magnetic coupler isolation, onboard TVS (transient voltage suppression tube), self-recovery fuses, protection diodes, and automatic transceiver switching circuit. It can effectively suppress the surge voltage and transient peak voltage in the circuit, prevent lightning and static electricity, prevent over-voltage, improve the anti-impact ability, can conduct signal isolation, with high dependence, strong anti-interference, low power consumption advantages, etc.

Communication protocol





  • CS:Slave chip selection, when CS is low, the slave chip is enabled.
  • SCLK:SPI communication clock
  • MOSI/SI:SPI Communication master sends, slave receives
  • MOSI/SI:SPI Communication master receives, slave sends
  • Timing Sequence:CPHL=0, CPOL=0 (SPI0)

How to use

We provide C and Python demo codes for Raspberry Pi. A quick testing example is provided in python.

Hardware Connection

To run examples, you should prepare an external RS485 to UART module, connect it to Channel 1 of 2-CH RS485 HAT.

If you test the 2-CH RS485 HAT with the text.py example, you need to wire Channel 1 and Channel 2 of 2-CH RS485 HAT.

485 PINRaspberry Pi(BCM)
VCC5V
GNDGND
SCKP21 (SPI1 SCLK)
MOSIP20 (SPI1 MOSI)
MISOP19 (SPI1 MISO)
CSP18 (SPI1 CS)
IRQP24
EN1P27
EN2P22

Software setup

  • Open the terminal and modify config.txt file by commands:
sudo nano /boot/config.txt
  • Add the line below to the file, the int_pin should be set according to the actual welding:
dtoverlay=sc16is752-spi1,int_pin=24
  • Then restart Raspberry Pi
sudo reboot
  • After rebooting, the driver of SC16IS752 will be loaded into the system kernel. You can run command ls /dev to check the following devices:

Install Libraries

  • Install wiringpi
sudo apt-get install wiringpi
# An upgrade may be required for raspberry PI 4B:
cd /tmp
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v
# Running gpio-v to check if the version is 2.52, If it is not, you need to check the installation again.
  • Install the python2 library
sudo apt-get update
sudo apt-get install python-pip
sudo pip install RPi.GPIO
sudo apt-get install python-serial
  • Install the python3 library
sudo apt-get update
sudo apt-get install python3-pip
sudo pip3 install RPi.GPIO
sudo apt-get install python3-serial


Test

  • Download and run the examples:
sudo apt-get install p7zip-full
wget http://www.waveshare.net/w/upload/4/44/2-CH_RS485_HAT_code.7z
7z x 2-CH_RS485_HAT_code.7z
sudo chmod 777 -R  2-CH_RS485_HAT
cd 2-CH_RS485_HAT/
  • You can also clone the project from our Github:
sudo git clone https://github.com/waveshare/2-CH-RS485-HAT
cd 2-CH-RS485-HAT/
  • C program
cd c
make clean
make
sudo ./main
  • Python program
cd python 
cd examples
sudo python main.py

Hardware connection: Channel 1 of the 2-CH RS485 HAT is connected to the USB TO USB TO RS232/485/TTL

Connect USB TO USB TO RS232/485/TTL to the computer, open the serial port assistant software, select the corresponding serial port, and set the baud rate to 115200.

  • Run the C program, the data sent by computer will all be received by Raspberry Pi, as below:

Note: The path of the samples is based on the actual directory;

  • Run the main.py, the data sent by computer will all be received by Raspberry Pi, as below:

Note: The path of the samples is based on the actual directory;

If you don't have other RS485 devices, you can choose the test method as follow by connecting channel 1 with channel 2:



  • Running result of test.py :

TAG: Modbus RTU Relay 32CH ESP32 P4 Development Board 7inch Display 7 inch TouchScreen Onboard ESP32-C6/Camera-Port/Speaker-Port Raspberry Pi 1.54inch LCD Bookworm-Desktop Display and Touch Serial UART Bus Servo ST3215 30KG.CM/19.5KG.CM Magnetic Encoder 360° High Precision And Large Torque MPW7 Raspberry Pi 5 PCIe to WIFI7 Adapter Board HAT Pi5 For Google TPU BE200 AX210 AI Raspberry Pi PICO Raspberry Pi 5 Serial Milk-V R7FA4 Plus A Board Based on R7FA4M1AB3CFM Compatible with Arduino UNO For R4 Minima Raspberry Pi 5 PCIe to M.2 Multi Function Adapter Board Supports Dual 4K HDMI Output Raspberry Pi 5 Box Case Ki-A PCIe to RJ45 Gigabit Ethernet All Ports To Pi's USB Side Raspberry Pi 10.1 inch LCD HDM Display Capacitive TouchScreen 10.1EP-CAPLCD 1920x1200 For Jetson Nano/mini Computer PC JETSON NANO MINI Fan Pi5 Power ESP32 P4 Development Board WIFI6 4 inch LCD Round Display 4inch TouchScreen 720×720 Dual Microphones Milk-V Duo S Usage of USB Type A interface Image-Modulation-Tutorial User Guide NVIDIA Jetson TX2 NX Module Electronic EYE 0.71 inch Round Double LCD Display Dual Screen For Arduino Raspberry Pi ESP32 Pico ST LoRa32-Heltec V4 ESP32-S3 LoRa SX1262 Development Board 863-928MHz Meshtastic For Arduino