2-CH RS232 HAT

From Waveshare Wiki
Jump to: navigation, search
2-CH RS232 HAT
2-CH-RS232-HAT-1.jpg

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

{{{name3}}}

{{{name4}}}

{{{name5}}}

{{{name6}}}

Overview

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. With the advantages of fast communication, stability, reliability and safety, it is an ideal choice for industrial automation.

More

Feature

  • Standard Raspberry Pi 40PIN GPIO extension header, supports Raspberry Pi series boards.
  • Adopts SC16IS752+SP3232 dual-chip combination, converts SPI to RS232, data rate up to 921600bps.
  • Onboard TVS (Transient Voltage Suppressor), effectively suppresses surge voltage and transient spike voltage in the circuit, lightning proof & anti-electrostatic.
  • Onboard LEDs for indicating the power and transceiver status.
  • Breakout 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
  • RS232 transceiver: SP3232
  • Communication interface: SPI
  • Data rate: 300 ~ 921600 bps
  • Operating voltage: 3.3V / 5V
  • Dimensions: 65mm × 56.5mm
  • Mounting hole size: 3.0mm

Interfaces

  • Pinout
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)
  • RS232 interface:

2-CH RS232 HAT-rs23209.png

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, 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

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 2020-05-27, "gpiochip3" has not become 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/3/35/2-CH_RS232_HAT_Code.7z
7z x 2-CH_RS232_HAT_Code.7z -o./2-CH_RS232_HAT
sudo chmod 777 -R  2-CH_RS232_HAT
cd 2-CH_RS232_HAT/2-CH_RS232_HAT_Code/
  • GitHub
sudo git clone https://github.com/waveshare/2-CH-RS232-HAT
cd 2-CH-RS232-HAT/
  • C program:
cd c
make clean
make
sudo ./main
  • Python program:
cd python 
cd examples
sudo python main.py

Expected result:
Channel 1 is connected to the computer through the serial port cable, open the computer serial port, and set the baud rate to 115200. The computer sends any data, and the module returns the data (If you do not press Enter at the end, the terminal may fail to display).
2-CH RS232 HAT serial.png

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

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

2-CH RS232 HAT serial1.png

Also, provide a test program:

sudo python test.py

Run test.py, and connect channel 1 to channel 2 through the female-to-female serial crossover cable.
2-CH RS232 HAT serial2.png

Resources

Documentation

Demo code

Datasheets

FAQ

 Answer:

1. Check whether the serial communication of the Raspberry Pi has enabled flow control;
2. Make sure the 232 line is connected correctly;
3. You can use the USB to 232 devices to communicate with the 2-CH RS232 HAT first to ensure that there is no problem with the settings of the Raspberry Pi;
4. Check the odd and even bit checksum and baud rate settings of serial communication parameters.

{{{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. Or use the SD card of the Raspberry Pi to read and change the config.txt file under the computer (or another host that can recognize the SD card) through the card reader.

{{{5}}}


 Answer:

I'm sorry that does not support.

{{{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 PM GMT+8 (Monday to Friday)