R-Car/Boards/CAN

This page provides information on CAN bus support on R-Car evaluation boards.

For general information regarding CAN bus operation refer to Wikipedia article.

Cable
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.

Porter board
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: [*] CAN_H and CAN_L signals form a differential pair. These wires should be twisted.

See example (picture) of XNP-3 to DB9 cable:

Break-out box
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.

Porter board
JP10 should be left open if a break-out box is used.

OBD-II
In order to connect to OBD-II interface use a cable from PEAK Systems.

Porter board
CAN termination resistor must be switched off (JP10 left open) when connecting to OBD-II.

Yocto build
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.  

Configuration
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 for steps necessary for starting the board.   Check that can0 interface is present. Run: ip link show can0 The output should be: 2: can0:  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 500000   Bring CAN interface UP with: ip link set can0 up </li>  You can then dump all messages coming from the bus with candump utility from can-utils package: candump can0 When valid CAN messages are received, candump will print the following output: can0 2C4   [4]  F8 D4 D6 D1  can0  2C5   [2]  37 73 can0 610   [3]  27 B4 45 </li>  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    (CAN ID generation mode - see below) -L    (CAN data length code (dlc) generation mode - see below) -D    (CAN data (payload) generation mode - see below) -p (poll on -ENOBUFS to write frames with ms) -n   (terminate after 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 => fix value using

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 :) </li>

 When CAN bus is no longer needed or for reconfiguration, bring CAN interface DOWN with: ip link set can0 down </li> </ol>