Difference between revisions of "R-Car/Boards/CAN"

From eLinux.org
Jump to: navigation, search
 
(9 intermediate revisions by the same user not shown)
Line 15: Line 15:
 
Use a cable with [http://www.digikey.com/product-detail/en/XHP-3/455-2219-ND/1651017 XHP-3] and DB-9 connectors. Mating terminals are [http://www.digikey.com/product-detail/en/SXH-001T-P0.6/455-1135-1-ND/527370 SXH-001T-P0.6]. You may need a crimper tool.  
 
Use a cable with [http://www.digikey.com/product-detail/en/XHP-3/455-2219-ND/1651017 XHP-3] and DB-9 connectors. Mating terminals are [http://www.digikey.com/product-detail/en/SXH-001T-P0.6/455-1135-1-ND/527370 SXH-001T-P0.6]. You may need a crimper tool.  
  
Minimum number of wires consist of three:
+
Minimum number of wires is three:
 
{|class="wikitable"
 
{|class="wikitable"
 
|-
 
|-
! Porter JP6 Pins || Signal || DB-9 pins
+
! Porter CN11 Pins || Signal || DB-9 pins
 
|-  
 
|-  
 
|1 || CAN_H* || 7
 
|1 || CAN_H* || 7
Line 29: Line 29:
 
[*] CAN_H and CAN_L signals form a differential pair. These wires should be twisted.
 
[*] CAN_H and CAN_L signals form a differential pair. These wires should be twisted.
  
Connecting several Porter boards without intermediate DB-9 connectors is not recommended since it will be difficult to add new devices in the future.
+
See example (picture) of XNP-3 to DB9 cable:
 +
[[File:Porter_can_cable_example.png | left| thumb]]
  
 
<br clear=all>
 
<br clear=all>
 +
 
=== Break-out box ===
 
=== Break-out box ===
 
[[File:Can breakout box 2.jpg|thumb|upright|CAN break-out box from National Instruments]]
 
[[File:Can breakout box 2.jpg|thumb|upright|CAN break-out box from National Instruments]]
If you need to temporarily connect multiple devices to the bus, usage of a break-out box as shown on the picture is highly recommended.
+
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 very long cables.
+
Termination should only be enabled on the break-out box and at the end of long cables.
 
===== Porter board =====
 
===== Porter board =====
JP10 should be left open if a break-out box is used.
+
JP4 should be left open if a break-out box is used.
  
 
<br clear=all>
 
<br clear=all>
 +
 
=== OBD-II ===
 
=== OBD-II ===
 
In order to connect to OBD-II interface use a cable from PEAK Systems [http://www.peak-system.com/PCAN-Cable-OBD-2.273.0.html?&L=1].
 
In order to connect to OBD-II interface use a cable from PEAK Systems [http://www.peak-system.com/PCAN-Cable-OBD-2.273.0.html?&L=1].
 
===== Porter board =====
 
===== Porter board =====
CAN termination resistor must be switched off (JP10 left open) when connecting to OBD-II.
+
CAN termination resistor must be switched off (JP4 left open) when connecting to OBD-II.
  
 
== Software ==
 
== Software ==
Line 61: Line 64:
 
<li>
 
<li>
 
Complete all steps on [[R-Car/Boards/Yocto]].
 
Complete all steps on [[R-Car/Boards/Yocto]].
<li>
+
</li>
 
</ol>
 
</ol>
  
Line 84: Line 87:
 
Configure the interface with:
 
Configure the interface with:
 
<pre>
 
<pre>
ip link set can0 type can bitrate 500000
+
ip link set can0 type can bitrate 125000
 +
</pre>
 +
the CAN with Flexible Data-Rate (CAN FD) configuration command looks like:
 +
<pre>
 +
ip link set can0 type can bitrate 500000 sample-point 0.75 dbitrate 4000000 dsample-point 0.8 fd on
 
</pre>
 
</pre>
 
</li>
 
</li>

Latest revision as of 11:38, 23 November 2016

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

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

Hardware

Cable

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.


OBD-II

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.

Software

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.

Configuration

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
        link/can
    
  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.
    
    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 :)
    
  7. When CAN bus is no longer needed or for reconfiguration, bring CAN interface DOWN with:
    ip link set can0 down