From eLinux.org
Jump to: navigation, search

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

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



Typical pinout of DB9 CAN connector

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
Pins of CAN connector on Renesas R-Car M2 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:

Porter CN11 Pins Signal DB-9 pins
1 CAN_H* 7
2 CAN_L* 2
3 GND 6

[*] CAN_H and CAN_L signals form a differential pair. These wires should be twisted.

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

Porter can cable example.png

Break-out box

CAN break-out box from National Instruments

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

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 [1].

Porter board

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


Yocto build

To build Yocto image with CAN bus support for Porter board, follow this procedure carfully:

  1. Do all steps specified on R-Car/Boards/Yocto and stop before executing bitbake core-image-weston or bitbake core-image-x11
  2. Edit $WORK/build/conf/local.conf with your favorite text editor, and add at the end:
    IMAGE_INSTALL_append = "can-utils iproute2" 
  3. Complete all steps on R-Car/Boards/Yocto.


CAN interface can be configured with ip tool from iproute2 package configured in Yocto.

  1. Login into command prompt on the board. Refer to R-Car/Boards/Yocto#Running Yocto image for steps necessary for starting the board.
  2. 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
  3. 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
  4. Bring CAN interface UP with:
    ip link set can0 up
  5. 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
  6. 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.
    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 :)
  7. When CAN bus is no longer needed or for reconfiguration, bring CAN interface DOWN with:
    ip link set can0 down