Linux can bus device

CAN Bus

The CAN bus is an ISO standard bus originally developed for vehicles. It manages the Chassis Electrical System Control and is responsible for critical activities like engine electrical, and skid control. This system is also used to provide vehicle diagnostic information for maintenance. A multi-star configuration seems typical of this bus with a primary bus line that branches into sub bus lines at its extremities then attaches to multiple device nodes. Differential voltage is applied over twisted pair at 1.5 to 2.5V and 2.5 to 3.5V for noise resistant signaling. Bit rates up to 1 Mbit/s are possible at network lengths below 40 m. Decreasing the bit rate allows longer network distances (e.g., 500 m at 125 kbit/s). (Jeremiah J. Flerchinger Source) Controllers supporting CAN FD, an enhanced CAN version with frames up to 64 byte and bit rates up to 4 Mbit/s, will be available in the second half of 2014. A can4linux version supportig CAN FD on a IFI CAN is ready to be used.

Although developed as car communication network CAN is used in many other areas, industrial, medical, maritime laboratory and more. Most often with a CAN based higher layer protocol like CANopen on top of it.

Additional information can be found at:

CAN Support in Linux

CAN is supported by Linux device drivers. Mainly two types exist. Character device based drivers and network socket based drivers. The Linux kernel supports CAN with the SocketCAN framework.

Читайте также:  Посмотреть dns сервера linux

One of the character based drivers is can4linux.

SocketCAN Supported Protocols

  • RAW: send & receive raw CAN frames
  • BCM: Broadcast manager, offload repetitive work to the Linux kernel
  • ISOTP .
  • SAE J1939

SocketCAN Supported Controllers

  • Microchip MCP251x
  • Atmel AT91 SoCs
  • ESD 331 CAN Cards
  • NXP (Philips) SJA1000
  • Freescale MPC52xx SoCs
  • Bosch CC770
  • Intel AN82527
  • TIs SoCs
  • Serial/network devices utilizing ASCII protocol (slcan driver)

Источник

CAN communication tutorial, using simulated CAN bus¶

It is possible to create a virtual (simulated) CAN bus on Linux systems. This can be used to simulate the activity of a real CAN bus, and for testing CAN software. Install a virtual CAN bus as described elsewhere in this documentation, and name it vcan0 (look at DEPENDENCIES.rst file for installation commands).

Linux CAN command-line tools¶

In order to test the CAN communication, we are using the can-utils command line CAN tools. These are used similarly on real and simulated CAN buses. For example, one of the tools is candump which allows you to print all data that is being received by a CAN interface.

In order to test this facility, start it in a terminal window:

From another terminal window, send a CAN frame with identifier 0x1A (26 dec) and 8 bytes of data:

$ cansend vcan0 01a#11223344AABBCCDD

This will appear in the first terminal window (running candump):

vcan0 01A [8] 11 22 33 44 AA BB CC DD

To send large amount of random CAN data, use the cangen tool:

In order to record this type of received CAN data to file (including timestamp), use:

Читайте также:  Linux мониторинг ресурсов сервера

The resulting file will be named like: candump-2015-03-20_123001.log

In order to print logfiles in a user friendly format:

$ log2asc -I candump-2015-03-20_123001.log vcan0

Recorded CAN log files can also be re-played back to the same or another CAN interface:

$ canplayer -I candump-2015-03-20_123001.log

If you need to use another can interface than defined in the logfile, use the expression CANinterfaceToUse=CANinterfaceInFile . This example also prints the frames:

$ canplayer vcan0=can1 -v -I candump-2015-03-20_123001.log

The cansniffer command line application is showing the latest CAN messages. Start it with:

It shows one CAN-ID (and its data) per line, sorted by CAN-ID, and shows the cycle time per CAN-ID. The time-out until deleting a CAN-ID row is 5 seconds by default.

There is an example CAN log file distributed with the Secure Gateway. Download it, replay it, and study the result using cansniffer.

Also the Wireshark program can be used to analyse CAN frames.

There is a description on how to analyze CAN using Wireshark: https://libbits.wordpress.com/2012/05/07/capturing-and-analyzing-can-frames-with-wireshark/ Make sure to enable the CAN interface before starting the program.

Setting up CAN communication between two embedded Linux boards¶

In order to test real CAN communication, you need two embedded Linux machines, for example Raspberry Pi and Beaglebone. Both should be equipped with CAN interface boards, set to a speed of 500 kbit/s. The installation of software and hardware is described elsewhere in this documentation.

Test the communication using command line tools. Send a CAN frame from one of the machines:

This will be repeatedly sent on the CAN bus until there is an acknowledgement from at least one other node.

Читайте также:  Astra linux руководство разработчика

For the CAN controller to be able to send a message, a CAN transceiver must be connected (as it senses the CAN bus voltage). Otherwise it will stop immediately after the first try.

To cancel this sending, you need to disable and re-enable the can0:

$ sudo ip link set can0 down $ sudo ip link set can0 up

On the other machine receive the CAN frames using:

Источник

Оцените статью
Adblock
detector