Difference between revisions of "2-CH RS232 HAT"

From Waveshare Wiki
Jump to: navigation, search
Line 22: Line 22:
 
{{Amazon|{{#urlget:amazon|default}}=display
 
{{Amazon|{{#urlget:amazon|default}}=display
 
|More = [https://www.waveshare.com/2-ch-rs232-hat.htm More]}}
 
|More = [https://www.waveshare.com/2-ch-rs232-hat.htm More]}}
 
= Interfaces =
 
{|class="wikitable"
 
|-
 
! 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)
 
|}
 
 
 
== 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 interfaces communication. This module uses the 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===
 
----
 
[[File:2-CH-RS485 -HAT-2.png|600px]]
 
*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 [https://www.waveshare.com/product/modules/communication/rs232-rs485-can/usb-to-rs232-485-ttl.htm RS232 to USB] module, connect it to Channel 1 of 2-CH RS232 HAT.
 
 
If you test the 2-CH RS232 HAT with the text.py example, you need to wire Channel 1 and Channel 2 of 2-CH RS232 HAT.
 
 
{|border=1; style="width:500px;"
 
|-style="background:#0000ff; color:white;" align="center"
 
|232 PIN|| Raspberry Pi(BCM)
 
|-align="center"
 
|VCC|| 5V
 
|-align="center"
 
|GND|| GND
 
|-align="center"
 
||SCK|| P21 (SPI1 SCLK)
 
|-align="center"
 
||MOSI||P20 (SPI1 MOSI)
 
|-align="center"
 
|MISO|| P19 (SPI1 MISO)
 
|-align="center"
 
||CS|| P18 (SPI1 CS)
 
|-align="center"
 
|IRQ|| P24
 
|}
 
 
===Software setup===
 
*Open the terminal and modify config.txt file by commands:
 
 
<pre>
 
sudo nano /boot/config.txt
 
</pre>
 
 
*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
 
<pre>
 
sudo reboot
 
</pre>
 
*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]]
 
 
===Install Libraries===
 
*Install wiringpi
 
 
<pre>
 
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.
 
</pre>
 
 
*Install the python2 library
 
<pre>
 
sudo apt-get update
 
sudo apt-get install python-pip
 
sudo pip install RPi.GPIO
 
sudo apt-get install python-serial
 
</pre>
 
 
*Install the python3 library
 
<pre>
 
sudo apt-get update
 
sudo apt-get install python3-pip
 
sudo pip3 install RPi.GPIO
 
sudo apt-get install python3-serial
 
</pre>
 
 
 
===Test===
 
*Download and run the examples:
 
 
<pre>
 
sudo git clone https://github.com/waveshare/2-CH-RS232-HAT
 
cd 2-CH-RS232-HAT/
 
</pre>
 
 
*C program
 
<pre>
 
cd c
 
sudo make clean
 
sudo make
 
sudo ./main
 
</pre>
 
 
*Python program
 
<pre>
 
cd python
 
cd examples
 
sudo python main.py
 
</pre>
 
 
Hardware connection: Channel 1 of the 2-CH RS232 HAT is connected to [https://www.waveshare.com/product/modules/communication/rs232-rs485-can/usb-to-rs232-485-ttl.htm RS232 to USB]:<br/>
 
 
Connect [https://www.waveshare.com/product/modules/communication/rs232-rs485-can/usb-to-rs232-485-ttl.htm RS232 to USB] 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_RS232_HAT_serial.png|800px]]
 
 
'''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:
 
[[File:2-CH_RS232_HAT_serial1.png|800px]]
 
 
'''Note: The path of the samples is based on the actual directory;'''
 
 
If you don't have other RS232 devices, you can choose the test method as follow by connecting channel 1 with channel 2:
 
 
*Running result of test.py :
 
[[File:2-CH_RS232_HAT_serial2.png|800px]]
 
  
 
==Resources==
 
==Resources==

Revision as of 02:02, 29 June 2020

2-CH RS232 HAT
2-CH-RS232-HAT-1.jpg

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

{{{name3}}}

{{{name4}}}

{{{name5}}}

Introduction

This is a 2-channel isolated RS232 expansion HAT designed for Raspberry Pi, adopts the SC16IS752+SP3232 solution, with embedded protection circuits such as power supply isolation, ADI magnetical isolation, and TVS diode, etc.

It is easy to control the 2-channel RS232 via SPI interface. Due to its fast communication, stability, reliability, and safety, it is an ideal choice for fields like industrial automation.

More

Resources

Documentation

Demo code

Datasheets

FAQ

Supports

Support

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