2-CH RS485 HAT

From Waveshare Wiki
Jump to: navigation, search

2-CH RS485 HAT
2-CH-RS485-HAT-1.jpg

2-CH RS485 HAT for Raspberry Pi
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

Overview

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.

More

Feature

  • Standard Raspberry Pi 40PIN GPIO extension header, supports Raspberry Pi series boards.
  • Adopts SC16IS752 + SP3485 dual-chip combination, converts SPI to RS232, data rate up to 921600bps.
  • Supports manual or automatic data sending and receiving, which can be set by a DIP switch.
  • Onboard TVS (Transient Voltage Suppressor), effectively suppresses surge voltage and transient spike voltage in the circuit, lightning proof & anti-electrostatic.
  • Onboard resettable fuses and protection diodes ensure a stable output of current and voltage, prevent overcurrent and overvoltage and improve shock resistance.
  • Onboard power indicator and serial port transceiver indicator for checking the module power and communication status.
  • With SPI control pins, for connecting with host control boards like Arduino.
  • Comes with online development resources and a manual (examples in C and Python).

Parameter

  • UART expansion chip: SC16IS752
  • RS485 transceiver: SP3485
  • Communication interface: SPI
  • Data rate: 300 ~ 921600 bps
  • Operating voltage: 3.3V / 5V
  • Dimensions: 65mm × 56.5mm
  • Mounting hole size: 3.0mm

Interfaces

PIN SYMBOL Description
1 VCC 3.3V/5V Power
2 GND Ground
3 SCLK SPI Clock input
4 MOSI SPI Data input
5 MISO SPI Data output
6 CS SPI Chip Selection
7 IRQ Interrupt output (Interrupt Request)
8 EN1 Enable Channel 1
9 EN2 Enable Channel 2

Working principle

Introduction

This product adopts SC16IS752 as a controller. SC16IS752 is a dual-channel high-performance UART expansion chip that supports SPI and I2C. This module adopts the SPI interface and onboard power isolation, ADI magnetic coupler isolation. It also onboards TVS (transient voltage suppression tube), self-recovery fuses, protection diodes, and an 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, and can conduct signal isolation with high dependence, strong anti-interference, and low power consumption advantages, etc.

Communication protocol

2-CH-RS485 -HAT-2.png

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

Working with RPI

How to use

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

Hardware Connection

232 PIN Raspberry Pi(BCM) Description
VCC 5V 3.3/5V Power Input
GND GND Ground
SCLK P21 (SPI1 SCLK) SPI Clock Signal Input
MOSI P20 (SPI1 MOSI) SPI Data Input
MISO P19 (SPI1 MISO) SPI Data Output
CS P18 (SPI1 CS) SPI Chip Select
IRQ P24 Interrupt Output
EN1 P27 Channel 1 transceiver enable: high level transmit enable, low level receive enable
EN2 P22 Channel 2 transceiver enable: high level transmit enable, low level receive enable

Software setup

  • Open the terminal and modify the 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 the command ls /dev to check the following devices:

2-CH-RS485-HAT-3.png
In the Raspberry Pi system on May 27, 2020, gpiochip3 was no longer available and became gpiochip2.

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 https://files.waveshare.com/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 demo:
cd c
make clean
make
sudo ./main
  • Python demo:
cd python 
cd examples
sudo python main.py

Hardware connection: Channel 1 of the 2-CH RS485 HAT is connected to USB TO RS232/485/TTL:
2-CH-RS485-HAT-7 (3).png

Connect 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:

2-CH-RS485 -HAT-4.png
Note: You need to press Enter for a line feed, otherwise the data will not be returned; the program directory of the example is based on the actual.

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

2-CH-RS485 -HAT-5.png
Note: You need to press Enter for a line feed, otherwise the data will not be returned; the program directory of the example is based on the actual.

If you don't have other RS485 devices, you can choose the test method as follow by connecting channel 1 with channel 2:
2-CH-RS485-HAT-8 (3).png

  • Running result of test.py :

2-CH-RS485 -HAT-6.png

Resources

Documentation

Demo code

Datasheets

FAQ

 Answer:
If the automatic transceiver is used, you will find that it can only reach 921600 bps at most, and the manual transceiver can reach 2M when testing.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:
In the semi-automatic mode, the voltage on the EN pin determines whether RS485 is transmitted or received. In the transmit mode, the RXD green light may be always on. In the receive mode, the TXD green light may be always on, which is normal.
{{{3}}}
{{{4}}}

{{{5}}}


 Answer:

1. Check whether A and B of 485 correspond to the controlled devices.
2. You can use the USB to 485 device to communicate with the module first to ensure that there is no problem with the settings of the Raspberry Pi;
3. Check the setting of odd and even bit parity of serial communication parameters.

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:

1. The Raspberry Pi is installed with the mainstream Ubuntu system and can be used.
2. Ubuntu's config.txt file is usually in the /boot/firmware folder.
3. You also can use the SD card of the Raspberry Pi to read and change the config.txt file under the computer (or other hosts that can recognize the SD card) through a card reader.

{{{3}}}
{{{4}}}

{{{5}}}


 Answer:

1. Raspberry Pi is installed with the mainstream Ubuntu system.
2. The config.txt file for Ubuntu is usually located in the /boot/firmware folder.
3. The Raspberry Pi version of the Ubuntu system is generally 64-bit, and you can install the WiringPi library using the following command.

Download 64-bit Arm wiringpi
wget https://gitee.com/LJYSCIENTIST/raspberry-pi-software-storage/raw/master/wiringpi-2.60-1_arm64.deb 
Install 64-bit Arm wiringpi
sudo dpkg -i wiringpi-2.60-1_arm64.deb 

{{{5}}}


 Answer:

The data sent from the sensor may be in Hex format (sometimes you need to send the data in hex to the sensor to request the data). Please transmit and receive the HEX data according to the following steps:

wget https://files.waveshare.com/upload/0/00/RS485-CAN-HAT-For-Hex.zip
unzip RS485-CAN-HAT-For-Hex.zip 
sudo chmod 777 RS485-CAN-HAT-For-Hex.zip
cd RS485-CAN-HAT-For-Hex
sudo python3 RS485-CAN-HAT-send-hex.py  

{{{5}}}


Support



Technical Support

If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 AM GMT+8 (Monday to Friday)