Pi RS485&CAN Module User Manual - V1.3
Pi RS485&CAN Module User Manual - V1.3
Pi RS485&CAN Module User Manual - V1.3
www.inno-maker.com
1.General Description:
RS485&CAN Module is an industrial communication module for Raspberry Pi, on board 2*RS485
Bus and 1*CAN Bus communication interface via SPI interface.
CAN bus and RS485 bus powered through separated isolation power module, signal between the
transceiver and the controller is isolated , ESD protection for the communication port, ensure
your Raspberry Pi can be used in more strictly industrial sites
2.Features:
2.1 Compatible with Raspberry Pi Zero/Zero W/2B/3B/3B+/4. Only a small amount of GPIO are
used and the remaining pins allow to work for other extended function
2.2 Power supply and signal transmission isolation, Build-in surge and ESD protection.
2.3 CAN function: on-board CAN controller MCP2515 via SPI interface, high speed CAN
transceiver, digital isolation ADUM1201BRZ, and communication Rates 20Kbps-1Mpbs can be
programmed arbitrarily.
2.4 RS485 function: on-board controlled via UART, half-duplex communication, supports
automatically TX/RX switch without extra programming, on-board SPI to RS485 SC16IS1752
Electrical data isolation with ADI ADM2483.
2.5 On-board individual 120 Ohm terminal resistance, Impedance matching and guarantee the
ability to drive. On-board User ATC24C32 EEPROM,
3.Hardware Description
3.1 Overview
Selection
18 GPIO_24 RS485 Interrupt
22 GPIO_25 CAN Interrupt
Reserved for an ID EEPROM on the Raspberry Pi.These pins
ID SCL and
27,28 are always reserved and should never be used to connect
ID SDA
external components
6,9,14,20,25,30,34,3 Ground Pin, connected to the main system Ground of the
GND
9 Raspberry Pi
The remaining pins are unused, You can use them for your other hardware boards.
Pin 27 and 28 are always reserved for an ID EEPROM on the Raspberry Pi. Independently
which card you use. It’s useless for most application. If you want to use this function, you
need to solder the IC, resistance and capacitance by yourself.
For more information about GPIO of Raspberry PI, please refer to below link:
https://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/#pret
tyPhoto
The other way is update the drive file to your image.Please refer to the 4.6 Chapter.
(2) Prepare two RS485&CAN modules, two TF cards and two Raspberry Pi boards. Connect the
two connectors in proper order. Connect the UART debug port of Raspberry Pi to your computer
(or using remote login).
(3) You also can connect two RS485 port directly of one module and connect the CAN port to
our USB2CAN module(http://www.inno-maker.com/product/usb-can/) for testing.
(2) Execute following commands on both Raspberry Pi, And you will see the data interaction.
./rs485_test -d/dev/ttySC0 -s abcdefghigklmnopqrstuvwxyz -e &
(3) Set the other one as senderand You should see that the receiver has received the packet.
./can0_send
(6) If you’re use our USB2CAN module for testing, please change the CAN device ‘can0’ to ‘can1’
in either ‘send.py’ or ‘receive.py’ file.
(1) Insert a TF cart into your computer, load your image of Raspbian to it
(2) Download the file named 'rs485_at.dtbo' from our wiki and copy it to /boot/overlays of the TF
card.
(3) Open ‘config.txt’ and add below two lines in the end.
dtoverlay=rs485_at
dtoverlay=mcp2515-can1,oscillator=16000000,interrupt=25
(4) Insert the TF card into the Raspberry Pi and power on.
(5) Download test codes and copy the folder to the Raspberry Pi by USB flash Dsik or remote
login.
(6) Go into the folders and change the permission. Otherwise you can't run the Demo.
chmod -R a+x *
(7) Check the kernel log to see if RS485 was initialized successfully.
ls -l /dev/ttyS*
(8) Check the kernel log to see if CAN was initialized successfully.
Support: [email protected] wiki.inno-maker.com 15
Bulk Price: [email protected]
Design Service,Production Service
www.inno-maker.com
------------------If you don’t want to use Python, you needn’t do below these steps.----------------------
(9)Check the Python version of your Raspbian. Python 3.7.3 default in 2019-07-10-Raspbian.img.
Our Demo can run on any Python3 version.
python3 -V
(10)If you can’t find the Python3 in system. Install the Python3
sudo apt-get install python-pip
sudo apt-get install python3 idle3 nano
5.Software Description
For more detail about Socket CAN please refer to below link:
https://www.kernel.org/doc/Documentation/networking/can.txt
b: Locate the interface to “can0” or other name you wish to use. The name will show when you
execute ‘./ifconfig –a’.
d: Disable sender’s filtering rules,this program only send message do not receive packets.
f: Send message to the can bus.You can use the return value of write() to check whether all data
has been sent successfully .
d:Define receive filter rules, we can set more than one filters rule.
import can
The python-can library provides Controller Area Network support for Python, providing common
abstractions to different hardware devices, and a suite of utilities for sending and receiving
messages on a CAN bus.
For more information about python-can, please to below link:
https://python-can.readthedocs.io/en/stable/index.html
Support: [email protected] wiki.inno-maker.com 21
Bulk Price: [email protected]
Design Service,Production Service
www.inno-maker.com
a:Enable RS485
# RS485 ioctls
TIOCGRS485 = 0x542E
TIOCSRS485 = 0x542F
SER_RS485_ENABLED = 0b00000001
SER_RS485_RTS_ON_SEND = 0b00000010
SER_RS485_RTS_AFTER_SEND = 0b00000100
SER_RS485_RX_DURING_TX = 0b00010000
buf[0] |= SER_RS485_ENABLED|SER_RS485_RTS_AFTER_SEND
buf[1] = 0
buf[2] = 0
fcntl.ioctl(ser, TIOCSRS485, buf)
command = ['a','b','c','d']
n = ser.write(command)
str = ser.read(ser.inWaiting())
6.Modbus Description
Modbus is a serial communication protocol developed by Modicon published by Modicon® in
1979 for use with its programmable logic controllers (PLCs). In simple terms, it is a method used
for transmitting information over serial lines between electronic devices. The device requesting
the information is called the Modbus Master and the devices supplying information are Modbus
Slaves. In a standard Modbus network, there is one Master and up to 247 Slaves, each with a
unique Slave Address from 1 to 247. The Master can also write information to the Slaves.
Now we use two RS485 ports on-board to make a modbus demo with Python3. set one port as
modbus master and the other port as modbus slave in same shield.
There are two files in the folder, ’rtumaster.py’ and ‘rtuslave.py’. I just make a simple demo to
show you how to use ‘READ_HOLDING_REGISTERS’ command to read data with modbus
viaRS485.
(5) You can see the result read from master. If you not set values follow step 3, The result will be
0,0,0,0 default.
Version Descriptions
If you have any suggestions, ideas, codes and tools please feel free to email to me. I will update
the user manual and record your name and E-mail in list. Look forward to your letter and kindly
share.