This page provides information on CAN bus support on R-Car evaluation boards.
For general information regarding CAN bus operation refer to Wikipedia article.
Commonly used CAN bus connector is DB-9 female (socket) for cables and DB-9 male (plug) for devices. In some cases power can be provided via the connector.
General rule is that both ends of the CAN bus should be terminated with matching resistors. Typical value is 120 Ohm.
Use a cable with XHP-3 and DB-9 connectors. Mating terminals are SXH-001T-P0.6. You may need a crimper tool.
Minimum number of wires is three:
|Porter CN11 Pins||Signal||DB-9 pins|
[*] CAN_H and CAN_L signals form a differential pair. These wires should be twisted.
See example (picture) of XNP-3 to DB9 cable:
If you need to connect multiple devices to the bus it it recommended to use a break-out box as shown on the picture
Termination should only be enabled on the break-out box and at the end of long cables.
JP4 should be left open if a break-out box is used.
In order to connect to OBD-II interface use a cable from PEAK Systems .
CAN termination resistor must be switched off (JP4 left open) when connecting to OBD-II.
To build Yocto image with CAN bus support for Porter board, follow this procedure carfully:
- Do all steps specified on R-Car/Boards/Yocto and stop before executing bitbake core-image-weston or bitbake core-image-x11
Edit $WORK/build/conf/local.conf with your favorite text editor, and add at the end:
IMAGE_INSTALL_append = "can-utils iproute2"
- Complete all steps on R-Car/Boards/Yocto.
CAN interface can be configured with ip tool from iproute2 package configured in Yocto.
- Login into command prompt on the board. Refer to R-Car/Boards/Yocto#Running Yocto image for steps necessary for starting the board.
Check that can0 interface is present. Run:
ip link show can0
The output should be:
2: can0: <NOARP,ECHO> mtu 16 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 10 link/can
Configure the interface with:
ip link set can0 type can bitrate 125000
the CAN with Flexible Data-Rate (CAN FD) configuration command looks like:
ip link set can0 type can bitrate 500000 sample-point 0.75 dbitrate 4000000 dsample-point 0.8 fd on
Bring CAN interface UP with:
ip link set can0 up
You can then dump all messages coming from the bus with candump utility from can-utils package:
When valid CAN messages are received, candump will print the following output:
can0 2C4  F8 D4 D6 D1 can0 2C5  37 73 can0 610  27 B4 45
To send one CAN message use cansend command:
cansend can0 610#000000
Multiple messages can be sent with cangen command:
cangen: generate CAN frames Usage: cangen [options] <CAN interface> Options: -g <ms> (gap in milli seconds - default: 200 ms) -e (generate extended frame mode (EFF) CAN frames) -f (generate CAN FD CAN frames) -R (send RTR frame) -m (mix -e -f -R frames) -I <mode> (CAN ID generation mode - see below) -L <mode> (CAN data length code (dlc) generation mode - see below) -D <mode> (CAN data (payload) generation mode - see below) -p <timeout> (poll on -ENOBUFS to write frames with <timeout> ms) -n <count> (terminate after <count> CAN frames - default infinite) -i (ignore -ENOBUFS return values on write() syscalls) -x (disable local loopback of generated CAN frames) -v (increment verbose level for printing sent CAN frames) Generation modes: 'r' => random values (default) 'i' => increment values <hexvalue> => fix value using <hexvalue> When incrementing the CAN data the data length code minimum is set to 1. CAN IDs and data content are given and expected in hexadecimal values. Examples: cangen can0 -g 4 -I 42A -L 1 -D i -v -v (fixed CAN ID and length, inc. data) cangen can0 -e -L i -v -v -v (generate EFF frames, incr. length) cangen can0 -D 11223344DEADBEEF -L 8 (fixed CAN data payload and length) cangen can0 -g 0 -i -x (full load test ignoring -ENOBUFS) cangen can0 -g 0 -p 10 -x (full load test with polling, 10ms timeout) cangen can0 (my favourite default :)
When CAN bus is no longer needed or for reconfiguration, bring CAN interface DOWN with:
ip link set can0 down