Difference between revisions of "2-CH RS485 HAT"

From Waveshare Wiki
Jump to: navigation, search
(17 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
<font size="4px">
 
{{Infobox item
 
{{Infobox item
 
|name=2-CH RS485 HAT
 
|name=2-CH RS485 HAT
 
|img=[[File:2-CH-RS485-HAT-1.jpg|300px|link=https://www.waveshare.com/2-ch-rs485-hat.htm]]
 
|img=[[File:2-CH-RS485-HAT-1.jpg|300px|link=https://www.waveshare.com/2-ch-rs485-hat.htm]]
 
|caption=2-CH RS485 HAT for Raspberry Pi
 
|caption=2-CH RS485 HAT for Raspberry Pi
|category=[[:Category:Modules|Modules]], [[:Category:Ethernet|Ethernet]]
+
|category=[[:Category:Modules|Modules]], [[:Category:Raspberry Pi|Raspberry Pi]]
 
|brand=Waveshare
 
|brand=Waveshare
 
|{{#urlget:amazon|default}}=display
 
|{{#urlget:amazon|default}}=display
Line 13: Line 14:
 
{{Product List|Mini PC / Raspberry  Pi/Expansions}}
 
{{Product List|Mini PC / Raspberry  Pi/Expansions}}
 
}}
 
}}
<div class="tabber">
 
  
<div class="tabbertab" title="Introduction">
 
 
__TOC__
 
__TOC__
= Introduction =
+
== 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.
 
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.
 
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.
Line 51: Line 50:
  
  
= Working principle =
+
== Working principle ==
Introduction
+
===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.
+
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=
+
 
 +
===Communication protocol===
 
----
 
----
 
[[File:2-CH-RS485 -HAT-2.png|600px]]
 
[[File:2-CH-RS485 -HAT-2.png|600px]]
Line 64: Line 64:
 
*MOSI/SI:SPI Communication master receives, slave sends
 
*MOSI/SI:SPI Communication master receives, slave sends
 
* Timing Sequence:CPHL=0, CPOL=0 (SPI0)
 
* Timing Sequence:CPHL=0, CPOL=0 (SPI0)
</div>
 
  
<div class="tabbertab" title="Hardware/Software setup">
+
==How to use==
=Raspberry Pi=
+
We provide C and Python demo codes for Raspberry Pi. A quick testing example is provided in python.
We provide C and Python demo codes. A quick testing example is provided in python.
 
  
; Detailed Connection  
+
===Hardware Connection===
----
+
To run examples, you should prepare an external [https://www.waveshare.com/usb-to-rs232-485-ttl.htm RS485 to UART] module, connect it to Channel 1 of 2-CH RS485 HAT.  
To run examples, you should prepare an external RS485 to UART module, connect it to Channel 1 of 2-CH RS485 HAT. When you test the test.py, you need to wire Channel 1 and Channel 2 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.
  
 
{|border=1; style="width:500px;"
 
{|border=1; style="width:500px;"
Line 97: Line 95:
 
|EN2|| P22
 
|EN2|| P22
 
|}
 
|}
;Software setup
+
 
----
+
===Software setup===
 
*Open the terminal and modify config.txt file by commands:
 
*Open the terminal and modify config.txt file by commands:
  
Line 105: Line 103:
 
</pre>
 
</pre>
  
*Add the following, int_pin is set according to the actual welding mode:
+
*Add the line below to the file, the int_pin should be set according to the actual welding:
 
 
''dtoverlay=sc16is752-spi1,int_pin=24''
 
  
 +
dtoverlay=sc16is752-spi1,int_pin=24
 +
*Then restart Raspberry Pi
 
<pre>
 
<pre>
 
sudo reboot
 
sudo reboot
 
</pre>
 
</pre>
*After rebooting, the driver of SC16IS752 will be loaded into the system kernel. You can run ls /dev to check the following devices:
+
*After rebooting, the driver of SC16IS752 will be loaded into the system kernel. You can run command '''ls /dev''' to check the following devices:
 
[[File:2-CH-RS485-HAT-3.png|800px]]
 
[[File:2-CH-RS485-HAT-3.png|800px]]
  
;Install Libraries
+
===Install Libraries===
----
 
 
*Install wiringpi
 
*Install wiringpi
  
Line 136: Line 133:
 
sudo apt-get install python-serial
 
sudo apt-get install python-serial
 
</pre>
 
</pre>
*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
 
  
 
*Install the python3 library
 
*Install the python3 library
Line 151: Line 143:
  
  
;Test
+
===Test===
----
 
 
*Download and run the examples:
 
*Download and run the examples:
 
<pre>
 
<pre>
Line 162: Line 153:
 
</pre>
 
</pre>
  
*You can also download the project on our Github:
+
*You can also clone the project from our Github:
 
<pre>
 
<pre>
 
sudo git clone https://github.com/waveshare/2-CH-RS485-HAT
 
sudo git clone https://github.com/waveshare/2-CH-RS485-HAT
Line 183: Line 174:
 
</pre>
 
</pre>
  
 +
Hardware connection: Channel 1 of the 2-CH RS485 HAT is connected to the USB TO [http://www.waveshare.net/shop/USB-TO-RS232-485-TTL.htm USB TO RS232/485/TTL]:<br/>
 +
[[File:2-CH-RS485-HAT-7 (3).png|800px]]
 +
 +
Connect USB TO [http://www.waveshare.net/shop/USB-TO-RS232-485-TTL.htm 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: <br/>
 +
[[File:2-CH-RS485 -HAT-4.png|800px]]
 +
 +
'''Note: The path of the samples is based on the actual directory;'''
  
</div>
+
*Run the main.py, the data sent by computer will all be received by Raspberry Pi, as below:
 +
[[File:2-CH-RS485 -HAT-5.png|800px]]
  
 +
'''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:
  
 +
[[File:2-CH-RS485-HAT-8 (3).png|800px]]
  
<div class="tabbertab" title="Resources">
+
*Running result of test.py :
 +
[[File:2-CH-RS485 -HAT-6.png|800px]]
  
= Documentation =
+
==Resources==
 +
===Documentation ===
 
* [[:File:2-CH_RS485_HAT_SchDoc.pdf|Schematic]]
 
* [[:File:2-CH_RS485_HAT_SchDoc.pdf|Schematic]]
  
= Demo code =
+
===Demo code ===
 
* [[:File:2-CH_RS485_HAT_code (1).7z|Demo code]]
 
* [[:File:2-CH_RS485_HAT_code (1).7z|Demo code]]
 
*[https://github.com/waveshare/2-CH-RS485-HAT Github]
 
*[https://github.com/waveshare/2-CH-RS485-HAT Github]
  
= Datasheets =
+
=== Datasheets ===
 
* [[:File:SP3481_SP3485.pdf|SP3481_SP3485.pdf]]
 
* [[:File:SP3481_SP3485.pdf|SP3481_SP3485.pdf]]
 
* [[:File:SC16IS752_datasheet.pdf|SC16IS752_datasheet.pdf]]
 
* [[:File:SC16IS752_datasheet.pdf|SC16IS752_datasheet.pdf]]
  
 
+
== FAQ ==
 
 
</div>
 
 
 
<div class="tabbertab" title="FAQ">
 
= FAQ =
 
  
 
{{FAQ|In the semi-automatic mode (manual mode), the green RXD light or the green TXD light is always on?
 
{{FAQ|In the semi-automatic mode (manual mode), the green RXD light or the green TXD light is always on?
Line 215: Line 215:
 
2). Determine whether A and B of 485 correspond one-to-one with the controlled 485 devices A and B;<br/>
 
2). Determine whether A and B of 485 correspond one-to-one with the controlled 485 devices A and B;<br/>
 
3). You can use USB to 485 module to communicate with 2-CH RS485 HAT to ensure that there is no problem with the Raspberry Pi settings.}}
 
3). You can use USB to 485 module to communicate with 2-CH RS485 HAT to ensure that there is no problem with the Raspberry Pi settings.}}
</div>
+
 
 +
==Supports==
 +
{{Service00}}
 +
</font>

Revision as of 01:11, 29 October 2019

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

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

{{{name3}}}

{{{name4}}}

{{{name5}}}

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

Interfaces

VCC 3.3V
PIN Description
VCC 3.3V/5V Power
GND Ground
SCLK SPI Clock input
MOSI SPI Data input
MISO SPI Data output
CS SPI Chip Selection
IRQ Interrupt output (Interrupt Request)
EN1 Channel 1 output enable
EN2 Channel 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


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, 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 PIN Raspberry Pi(BCM)
VCC 5V
GND GND
SCK P21 (SPI1 SCLK)
MOSI P20 (SPI1 MOSI)
MISO P19 (SPI1 MISO)
CS P18 (SPI1 CS)
IRQ P24
EN1 P27
EN2 P22

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:

2-CH-RS485-HAT-3.png

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:
2-CH-RS485-HAT-7 (3).png

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:

2-CH-RS485 -HAT-4.png

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:

2-CH-RS485 -HAT-5.png

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:

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:
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 if the serial communication of the Raspberry Pi has enabled flow control;

2). Determine whether A and B of 485 correspond one-to-one with the controlled 485 devices A and B;

3). You can use USB to 485 module to communicate with 2-CH RS485 HAT to ensure that there is no problem with the Raspberry Pi settings.
{{{3}}}
{{{4}}}

{{{5}}}


Supports

Support

If you require technical support, please go to the Support page and open a ticket.