0% found this document useful (0 votes)
80 views1 page

2 Channel CAN BUS FD Shield For Raspberry Pi Seeed Studio Wiki

The document describes the 2 Channel CAN BUS FD Shield for Raspberry Pi, highlighting its features such as high-speed transmission up to 8Mbps and compatibility with Raspberry Pi and Nvidia Jetson Nano platforms. It includes installation instructions, hardware connections, and software setup for using the shield with both Raspberry Pi and Arduino. Additionally, it provides code examples for sending and receiving data using the CAN BUS Shield.

Uploaded by

Luis Aechter
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views1 page

2 Channel CAN BUS FD Shield For Raspberry Pi Seeed Studio Wiki

The document describes the 2 Channel CAN BUS FD Shield for Raspberry Pi, highlighting its features such as high-speed transmission up to 8Mbps and compatibility with Raspberry Pi and Nvidia Jetson Nano platforms. It includes installation instructions, hardware connections, and software setup for using the shield with both Raspberry Pi and Arduino. Additionally, it provides code examples for sending and receiving data using the CAN BUS Shield.

Uploaded by

Luis Aechter
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Collaborating with us!

Join the Seeed Studio Ranger


Program or Contributor Program!

Raspberry Pi Pi HAT

2 Channel CAN BUS FD Shield for Raspberry Pi

On this page

2 Channel CAN BUS


FD Shield for
Raspberry Pi

This is a CAN BUS shield for Raspberry


Pi(hereinafter referred to as 2 channel pi hat), 2
channel CAN BUS I/O, support CAN FD. CAN
FD support much faster transmission speed(up
to 8Mbps)

Also it have two On-board 120Ω terminating


resistors which are controlled by the switches.

Versions Declare
There are 3 versions of the CAN BUS shield
for Raspberry Pi. All 3 versions work perfectly
on Raspberry Pi platform, and may skip this
section if you're using RPi platform.

The CAN BUS shield now also supports the


Nvidia Jetson Nano platform, and different
versions of the CAN BUS Shield do affect the
functionality, please check the table below
carefully if you're using with Jetson Nano
Platform.

Product RPi J
Chip
Name State

2-Channel
CAN-
Two Si
BUS(FD) MCP2517FD
Channels Ch
Shield for RPi
(MCP2517FD)

2-Channel
CAN-
BUS(FD) Two
MCP2518FD Tw
Shield for Channels
Raspberry Pi
(MCP2518FD)

As you can see, there are two versions of chips


used in the 2-Channel CAN-BUS(FD) Shield for
RPi (MCP2517FD) and both channels work on
RPi but only single channel (CAN0) works on
the Jetson Nano Platform!

Features
High-speed transfer rate: 8Mbps@10m
20AWG shielded cable / 1Mbps@40m
20AWG shielded cable
Stable power supply, selectable Raspberry
Pi power supply or DC power supply
Compatible with Raspberry Pi 2, Raspberry
Pi 3, Raspberry Pi 3, Raspberry Pi 4 and
Raspberry Pi Zero
One-button configuration of 120Ω
terminating resistor
Support CAN FD

Hardware Overview

Figure 1. Hardware
overview(MCP2517)

Figure 2. Hardware
overview(MCP2517)

Figure 3. Block Diagram(MCP2517)

Figure 4. Hardware
overview(MCP2518FD)

Mounting Guide

Figure 4. Mounting Guide

CAUTION

You can see that we used nylon columns


during assembly to avoid short-circuiting
between the metal terminals under the
CAN BUS port and the HDMI interface on
the Raspberry Pi. So please be sure to
assemble the nylon column as shown.

Specification

Parameter Value

12V~24V DC
Power Input Raspberry Pi GPIO
5V

CAN FD Controller MCP2517FD

CAN FD
MCP2557FD
Transceiver

CAN FD Channel 2

8Mbps@10m 20AWG
shielded cable
Transfer Rate
1Mbps@40m 20AWG
shielded cable

Communication
SPI
Interface with Pi

Grove Interface Grove I2C x2

Platforms Supported

Raspberry
Arduino
Pi

Getting Started

Materials required

2-
CAN-
Channel
Raspberry Arduino BUS
CAN-
pi Board Shield
BUS(FD)
V2
Shield

Get Get
Get ONE Get ONE
ONE ONE
Now Now
Now Now

Also we need to two male to male jumper and


power cables to power those boards.

Hardware Connection

Step 1. Follow the Mounting Guide to Plug


the 2-Channel CAN-BUS(FD) Shield into
Raspberry.

Step 2. Plug the CAN BUS Shield V2 into


the Seeeduino(or Arduino) Board

Step 3. Use the jumpers to connect the


CAN terminal of both shield.

2-Channel CAN- CAN-BUS


BUS(FD) Shield Shield V2

CAN_0_L CANL

CAN_0_H CANH

TIP

You can find the silkscreen at the b

Step 4. Power the Raspberry Pi and


Seeeduino.

Software

Install CAN-HAT

Step 1. Open config.txt file

sudo nano /boot/config.txt

Step 2. Add the following line at the end of


the file

dtoverlay=seeed-can-fd-hat-v2

Step 3. Press Ctrl + x, press y and press


Enter to save the file

Step 4. Reboot Raspberry Pi

sudo reboot

Step 5. Check the kernel log to see if


CAN-BUS HAT was initialized successfully.
You will also see can0 and can1 appear in
the list of ifconfig results

pi@raspberrypi:~ $ dmesg | grep spi


[ 6.178008] mcp25xxfd spi0.0 can0: MCP2
[ 6.218466] mcp25xxfd spi0.1 (unnamed n

pi@raspberrypi:~ $ ifconfig -a
can0: flags=128<NOARP> mtu 16
unspec 00-00-00-00-00-00-00-00-00-
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0
device interrupt 166

can1: flags=128<NOARP> mtu 16


unspec 00-00-00-00-00-00-00-00-00-
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0
device interrupt 167

eth0: flags=4163<UP,BROADCAST,RUNNING,MULT
inet 10.0.0.13 netmask 255.255.25
inet6 fe80::44cc:eeb8:47a0:7fce p
ether b8:27:eb:25:d4:e0 txqueuele
RX packets 299 bytes 27437 (26.7
RX errors 0 dropped 0 overruns 0
TX packets 172 bytes 25974 (25.3
TX errors 0 dropped 0 overruns 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 655


inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid
loop txqueuelen 1000 (Local Loop
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0

wlan0: flags=4098<BROADCAST,MULTICAST> mt
ether b8:27:eb:70:81:b5 txqueuele
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0

Step 6. Set the can fd protocol, and the


dbitrate can be set to 8M speed. Refer to
the kernel documentation for more usage

sudo ip link set can0 up type can bitr


sudo ip link set can1 up type can bitr

sudo ifconfig can0 txqueuelen 65536


sudo ifconfig can1 txqueuelen 65536

Step 7. Open two terminal windows and


enter the following commands in the
Windows to test can fd protocol.

#send data
cangen can0 -mv

#dump data
candump can0

You can test the CAN-BUS by connecting


two channels by itself using jumpers: 0_L
<===> 1_L, 0_H <===> 1_H.

Communicate with Arduino CAN BUS


Shield

In this demo, we only use one of the two


channels.

For Arduino CAN BUS Shield, we provide the


Arduino Code, if you don't know how to use
Arduino, please check here.

For 2 channel pi hat, there are two ways to


send & receive, you can use both can-
util/cangen and python code.

CAN BUS Shield send and CAN HAT receive

Arduino Code for CAN BUS Shield:

// demo: CAN-BUS Shield, send data


// loovee@seeed.cc

#include <mcp_can.h>
#include <SPI.h>

// the cs pin of the version after v1.


// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN);

void setup()
{
Serial.begin(115200);

while (CAN_OK != CAN.begin(CAN_500


{
Serial.println("CAN BUS Shield
Serial.println(" Init CAN BUS
delay(100);
}
Serial.println("CAN BUS Shield ini
}

unsigned char stmp[8] = {0, 0, 0, 0, 0


void loop()
{
//send data: id = 0x00, standrad
stmp[7] = stmp[7]+1;
if(stmp[7] == 100)
{
stmp[7] = 0;
stmp[6] = stmp[6] + 1;

if(stmp[6] == 100)
{
stmp[6] = 0;
stmp[5] = stmp[6] + 1;
}
}

CAN.sendMsgBuf(0x00, 0, 8, stmp);
delay(100);
}
// END FILE

Respberry pi setting and and you can use can-


util to receive

#set 500k baudrate


pi@raspberrypi:~ $ sudo ip link set ca
pi@raspberrypi:~ $ ip -details link sh
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu
link/can promiscuity 0
can state ERROR-ACTIVE (berr-count
bitrate 500000 sample-point 0.875
tq 25 prop-seg 34 phase-seg1 35 pha
mcp25xxfd: tseg1 2..256 tseg2 1..12
mcp25xxfd: dtseg1 1..32 dtseg2 1..1
clock 40000000numtxqueues 1 numrxqu
#receive
pi@raspberrypi:~ $ candump can0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0
can0 000 [8] 00 00 00 00 00 00 0

Or you can use python code to get the CAN


data. To use python to receive CAN data, you
should install python-can at first.

# install python-can
sudo pip3 install python-can

Open a new python file and copy the following


code, save as can_test.py:

import can

can_interface = 'can0'
bus = can.interface.Bus(can_interface,
while True:
message = bus.recv(1.0) # Timeout
if message is None:
print('Timeout occurred, n
print(message)

Run the Python code and the results are as


follows :

0 00 00 00 00 00 0e 63 Channel: can0
0 00 00 00 00 00 0f 00 Channel: can0
0 00 00 00 00 00 0f 01 Channel: can0
0 00 00 00 00 00 0f 02 Channel: can0
0 00 00 00 00 00 0f 03 Channel: can0
0 00 00 00 00 00 0f 04 Channel: can0
0 00 00 00 00 00 0f 05 Channel: can0
0 00 00 00 00 00 0f 06 Channel: can0
0 00 00 00 00 00 0f 07 Channel: can0
0 00 00 00 00 00 0f 08 Channel: can0
0 00 00 00 00 00 0f 09 Channel: can0
0 00 00 00 00 00 0f 0a Channel: can0

CAN BUS Shield receive and CAN HAT send #

For Raspberry Pi, you can use cangen to send


random package:

pi@raspberrypi:~ $ cangen can0 -v


can0 442#14.C4.1A.1A.C2.25.79.25
can0 748#4E.C7.8B.0B.6E.B9.15.77
can0 1E4#64.D4.62.22.2F.A6.BF
can0 1DD#69.6F.61.33.1F.59.E4.7C
can0 63D#
can0 764#2C.C1.E3
can0 68B#11.9C.63.6D.EA.E9.4B
can0 329#DA.06.2C.34.6C
can0 7DD#2E.F5.E0.2A.26.77.58.38
can0 1BE#94.30.6E.2F.A2.7B.E3.1D
can0 654#D1.21.A3.58.31.E8.51.5F
can0 706#51.41.36.5C.43.8D.AE.5D
can0 34A#89.F2.DE.33.AE.52.38.6C
can0 6AC#C1.35.83.41.37
can0 38C#22.AF
can0 208#22.8E.97.58.E5.69.F7.2C

For Arduino, you can use the following code to


recieve CAN data.

// demo: CAN-BUS Shield, receive data


// when in interrupt mode, the data co
// loovee, 2014-6-13

#include <SPI.h>
#include "mcp_can.h"

// the cs pin of the version after v1.


// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN);

unsigned char flagRecv = 0;


unsigned char len = 0;
unsigned char buf[8];
char str[20];

void setup()
{
Serial.begin(115200);

while (CAN_OK != CAN.begin(CAN_500


{
Serial.println("CAN BUS Shield
Serial.println(" Init CAN BUS
delay(100);
}
Serial.println("CAN BUS Shield ini

attachInterrupt(0, MCP2515_ISR, FA
}

void MCP2515_ISR()
{
flagRecv = 1;
}

void loop()
{
if(flagRecv)
{

flagRecv = 0;

// iterate over all pending me


// If either the bus is satura
// both RX buffers may be in u
// message does not clear the
while (CAN_MSGAVAIL == CAN.che
{
// read data, len: data l
CAN.readMsgBuf(&len, buf);

// print the data


for(int i = 0; i<len; i++)
{
Serial.print(buf[i]);S
}
Serial.println();
}
}
}

Open the Serial Monitor of Arduino IDE by

You might also like