SK Pang PiCAN2 DUO SMPS RSP-PICAN2DUOSMPS User Guide

PiCAN2 DUO SMPS Rev D V1.4

PiCAN2 DUO SMPS USER GUIDEV1.4

Product name PiCAN2 DUO 3A SMPS CAN-Bus Board for Raspberry Pi
Model number RSP-PICAN2DUOSMPS
Manufacturer SK Pang Electronics Ltd

Introduction

This PiCAN2DUO board provide two independent CAN-Bus channels for theRaspberry Pi 4. It uses the Microchip MCP2515 CAN controller with MCP2551 CAN transceiver. Connections are made via plug-in 4-way screw terminal. This board has a 5v 3A SMPS that can power the Pi is well via the screw terminal.Easy to install SocketCAN driver. Programming can be done in C or Python.1.1. Features

  • CAN v2.0B at 1 Mb/s
  • High-speed SPI Interface (10 MHz)
  • Standard and extended data and remote frames
  • CAN connection via screw terminal
  • 120Ω terminator ready
  • Serial LCD ready
  • LED indicator
  • Four fixing holes, comply with Pi Hat standard
  • SocketCAN driver appears as can0 and can1 to application
  • Interrupt RX on GPIO25 and GPIO24
  • 5v 3A SMPS to power Raspberry Pi and accessories from the screw terminalo Reverse polarity protectiono High-efficiency switch mode designo 7v to 24v input range

1.2. Hardware InstallationBefore installing the board make sure the Raspberry is switched off. Carefully align the 40way connector on top of the Pi. Use spacer and screw (optional items) to secure the board.

1.3. Screw TerminalThe CAN connection can also be made via the 4-way screw terminal.

CAN B (J4) CAN A (J3)
Pin number Function Pin number Function
1 CAN_L 1 CAN_L
2 CAN_H 2 CAN_H
3 GND 3 GND
4 n/c 4 +12v In

Connector J3 pin 4 is the input for the SMPS, it has an input voltage range of 6v to 20v that is used to power the Raspberry Pi.1.4. 120W TerminatorThere is a 120W fitted to the board. To use the terminator solder a 2way header pin to JP1 and JP2 then insert a jumper.1.5. LEDThere are two red LEDs fitted to the board. This is connected to GPIO04 and GPIO26.1.6. Not Fitted ItemsJP5 can be used to power a serial LCD with data on the TXD line from the Pi. There is also 5v supply on JP5.

Software Installation

It is best to start with a brand new Raspbian image. Download the latest from:https://www.raspberrypi.org/downloads/raspbian/

After first-time boot up, do an update and upgrade first.sudo apt-get updatesudo apt-get upgradesudo rebootAdd the overlays by:sudo nano /boot/config.txtAdd these 4 lines to the end of file:dtparam=spi=ondtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25dtoverlay=mcp2515-can1,oscillator=16000000,interrupt=24dtoverlay=spi-bcm2835-overlay

Reboot Pi:sudo reboot1.7. Bring Up the InterfaceYou can now bring the CAN interfaces up:sudo /sbin/ip link set can0 up type can bitrate 500000sudo /sbin/ip link set can1 up type can bitrate 5000001.8. Installing CAN UtilsInstall the CAN utils by:sudo apt-get install can-utilsConnect the PiCAN2 Duo to your CAN network via a screw terminal.To send a CAN message on can0 (CAN B J4) use :cansend can0 7DF#0201050000000000This will send a CAN ID of 7DF. Data 02 01 05 – coolant temperature request.To send a CAN message on can1 (CAN A J3) use :cansend can1 7DF#0201050000000000Connect the PiCAN Duo to a CAN-bus network and monitor traffic by using command:candump can0You should see something like this:

Writing Your Own Software

You can write your own application software in either C or Python.1.9. Application in PythonDownload the Python-CAN files from:https://github.com/hardbyte/python-can/releases/tag/3.2.0Unzip and copy over to the Pi.sudo python3 setup.py installBring the CAN interface up if it is not already done:sudo /sbin/ip link set can0 up type can bitrate 500000Now start python3python3To sent a message out type the following lines:import canbus = can.interface.Bus(channel=’can0′, bustype=’socketcan_native’)msg = can.Message(arbitration_id=0x7de,data=[0, 25, 0, 1, 3, 1, 4, 1],extended_id=False)bus.send(msg)

To received messages and display on screen type:notifier = can.Notifier(bus, [can.Printer()])

1.10. Application in CBring the CAN interface up if it is not already done:sudo /sbin/ip link set can0 up type can bitrate 500000Download the source code and example files by typing the following in the command prompt:wget http://skpang.co.uk/dl/cantest.tarUnpack the tar file and change it into a directory by:tar xf cantest.tarcd linux-can-utilsThe example file is called can test. c to edit this file, type the following in the command prompt:nano cantest.cLine 77 is the CAN message to be sent out.unsigned char buff[] = “7DF#0201050000000000”;7DF is the message ID and 0201050000000000 is the data. Change the data to suit.Press CTRL-X to exit.To compile the program type:makeCheck there are no errors. To run the program type:./cantest

SK Pang Electronics Ltd Ó 2021www.skpang.co.uk

References

[xyz-ips snippet=”download-snippet”]


Posted

in

by