CAN Bus Basics

General Introduction

Interfaces are used to transfer information between the individual components of a system.

In a Bus system, all components are connected  to a common data line via short stub lines.

The cost of the cabling is minimized, and additional components can be easily connected .

The data flow, however, needs to be controlled through an access method (protocol) if all the components share a common Bus line. If possible,  components from different manufacturers should be cooperated.

The Controller Area Network (CAN) connects together several equal components (nodes) over a 2-wire bus plus additional ground line. The CAN protocol was developed in 1983 by Bosch for use in motor vehicles and was first presented to the public in 1986.

 

 

Figure1: Controller Area Network (CAN)

Due to the high noise immunity, low cost and the real-time capability CAN is used not only in the automotive industry, but also in many other industries (eg. As in commercial vehicles, mobile vehicles, railways, medical, industrial automation, elevators and as a machine bus system).

The organization „CAN in Automation“ (CiA) dedicates to the advancement of the CAN protocol and the specification of the CANopen application protocol and the CANopen profiles.

Physical description of the CAN interface

The physical CAN transmission is standardized in ISO 11898-2 (high-speed) and ISO 11898-3 (low-speed). To implement this specification there are transceivers from different producers, such. As the PCA82C250 from NXP.

The electrical noise immunity is achieved among other things by displaying simultaneously one bit on the two lines  with anopposing potential changel. This is also called a differential signal.

On a second line occurs a redundant inverted transmission of the logic signal.

Disturbances incoming In the line affect both lines in the same direction. The difference in level is largely maintained even by disturbances, since the two differential lines, however, always have opposite levels . This is called in English "Common Mode Rejection Ratio" (CMRR). The lines CAN-High and CAN-Low. contain the inverted and non-inverted serial data signal.

Moreover, by the implementation as an open Collector (PNP on VCC at CAN H and NPN on GND at CAN-L) several participants can become a parallel-switched on the Bus, without forming electric short circuits in the conflict case.

The state with two different level recorders on CAN-H and CAN-L is called as the dominant state (level recorder difference: 2.0 volts nominally); the state with two same level recorders is called recessive (level recorder difference: 0.0 volts nominally).

The dominant state corresponds to a logical zero: if a knot lays a logical zero on the Bus, it possibly overwrites the state of a logical One of another knot. The coupling of the knots over the Bus line represents a logical And linking (Wired-And).

Figure 2: Transceiver PCA82C250 from NXP

 

logic level

state

CAN-H

CAN-L

difference level

0

dominant

Transistor interconnected (pulls level to VCC)

Transistor interconnected (pulls level to GND)

2 Volt

1 or high resistance

recessive or floating

transistor blocked

transistor blocked

0 Volt

Table 1: representation of the logic level in the CAN

 

Another measure to increase noise immunity is the NRZ coding, which means, a flank change is not in every bit. To avoid the loss of synchronization to the transmitter among the participants, a bit of the other polarity is inserted from the transmitter after five bits of the equal "polarity" (recessive or dominant). It is called  "bit-stuffing".  The receivers remove this stuff-bits automatically, so that the transmitted bit-sequence and the forwarded to the host controller are identical.

 

Pin assignment

As CAN plug connector 9-pin Sub-D connector proposed from CAN in Automation (CiA) has gained acceptance in many applications. Both "female" and "male" connectors are used simultaneously in the node. Thus, they can be integrated into the bus line without interrupting other nodes. ( "Daisy chain" wiring).

A 3-pole cable with CAN-High, CAN-Low and Ground is the minimum requirement for the transmission of CAN signals. The use of a shielded cable is not required. For longer cables, twist of the wire pair and shielding are recommended.

CiA has the pin assignment recommended for other connectors (CiA 303-1): for example, for the 5-pole M12 connector and 4- and 5-pole "open style" connector without considering the dimensions.

An equally useful thing is the CiA-defined 10-pole "multipole connector", in which the pin 10 is reserved and may not be used.

 

PIN

Signal

Description

1

 

reserved

2

CAN-L

negated CAN signal (dominant low)

3

CAN-GND

mass

4

 

reserved

5

CAN-SHLD

shield (optional)

6

GND

devices mass (optional)

7

CAN-H

positive CAN signal (dominant high)

8

 

reserved

9

VCC

supply voltage (optional)

Table 2: CAN assignment of D-SUB 9 connector

Bit rate and cable lengths

In principle, the CAN network can transmit bit rates up to 1 Mbit/s. All CAN nodes must be able to process the message simultaneously. The maximum cable length therefore depends on the bit rate. The table shows the recommended bit rates and the corresponding maximum cable length. In addition, the achievable length depends  also on the cable used, on the network topology and the sampling time.

Bitrate

Cable length

10 kbits/s

6,7 km

20 kbits/s

3,3 km

50 kbits/s

1,0 km

125 kbits/s

500 m

250 kbits/s

250 m

500 kbits/s

125 m

1 Mbits/s

25 m

Table 3: relationship between CAN bit rate and maximum cable length

Bus termination (terminating resistor)

The bus termination occurs at a CAN bus in a line topology with 120 Ohm at both ends of the network.

A termination is already recommended for short lines at low bit rates. There are reflections without termination. In the practice a termination at one end is sufficient for short lines, ideally is though the bus at both ends (and only there) terminated with 120 ohms.

Principle of the data exchange in the CAN network

When transmitting data in a CAN bus no nodes are addressed, but the content of a message (eg. speed or engine temperature) is characterized by a unique identifier. In addition to the content characterization, the identifier also determines the priority of the message.

With the following acceptance test all stations determine whether the received data for they is relevant or not due to the correct receipt of the message by reading the identifier (ID) .

Through content-based addressing, a high flexibility is achieved: it can be very easy to add stations to the existing CAN-network.

All messages are broadcasted to all participants and forwarded depending on the ID-acceptance filtering for processing to the host controller. The measured variables, that are needed by several electronic control units (ECUs) as information, can be distributed via the CAN network so, so that not every control unit requires a separate sensor.

Collision check

Each participant may send messages without a specific request of another participant (e.g. Send Master). As with Ethernet, it can happen that several participants transmit simultaneously. The message with the lowest identifier (the lowest binary value) receives the transmission permission.The process of collision check with the identifier called "bitwise arbitration".

According to the "wired and" mechanism, in which the dominant state (logic 0) overwrites the recessive state (logical 1), those nodes lose the contest of the arbitration, which recessive send, but detect on the bus a dominant bit. All "losers" automatically become receivers of the message with the highest priority and try to send again, only if the bus is free.

Simultaneous bus accesses of multiple nodes must always lead to a clear transmission permission, so the identifier must be clearly assigned, this means they may not be used by two persons simultaneously. By the process of bitwise arbitration on the identifiers of the awaiting transmission messages, every collision is clearly resolved after a predictable time: for messages in the base format (11-bit ID) there are a maximum of 13 bit times (29-bit ID) in expanded format there are a maximum of 33 bit times. The above mentioned Stuff bits are not considered.

Layers of CAN software and CAN hardware

The individual tasks of the CAN-communication take place according to the IOS/OSI reference model in "layers".

  • Physical Layer: this layer describes the physical properties, such as signal level, bit rate, sampling time, connector, cable, etc. It is partially implemented in the CAN controller and CAN transceiver.

  • Data Link Layer: this is the actual CAN protocol with its message formats (data telegrams, remote request telegram, error telegram and overload telegram) and the fault confinement.

  • The higher level protocols: The overlying layers are not reported separately, and as a rule are typically implemented in software on the host controller. In some sectors, this higher level protocols are standardized (eg. CANopen, DeviceNet, SAE J1939). The automotive industry has a transport protocol in ISO 15675 internationally standardized, which allows you to segment long messages with more than 8 bytes on the transmitter side and to assemble at the receiver side.

 

Construction of a CAN message

A message is packaged in its own CAN bus form. This packaging is designated as "frame".

A frame consists of seven maps:

  • start field (Start-of-frame bit)

  • arbitration field (CAN-Identifier plus RTR-Bit)

  • control field (contains the data length code)

  • data field (0 to 8 byte)

  • CRC-field (contains a 15-bit checksum and an end tag)

  • Acknowledge-field (ACK-Bit plus end tag)

  • end field (End-of-frame)

There are two frame formats that mainly differ by the length of the identifier:

  • Base-format (11-bit-Identifier)

  • Extendet-format (29-bit-Identifier)

There are following types of frames:

  • Data Frame (Message is sent without any special request)

  • Remote Transmission Request (RTR) Frame (Message is requested - the receiver, who "possesses" the message with the requested identifier, provides the corresponding data frame)

Basis-Frame according to ISO 11898-1 (formerly known as CAN 2.0A):

Start

1 Bit

Identifier

11 Bit

RTR

1 Bit

IDE

1 Bit

r0

1 Bit

DLC

4 Bit

DATA

0...8 Byte

CRC

16 Bit

ACK

2 Bit

EOF+IFS

10 Bit

 

Extended-Frame according to ISO 11898-1 (formerly known as CAN 2.0B):

Start

1 Bit

Identifier

11 Bit

SRR

1 Bit

IDE

1 Bit

Identifier

18 Bit

RTR

1 Bit

r1

1 Bit

r0

1 Bit

DLC

4 Bit

DATA

0...8 Byte

CRC

16 Bit

ACK

2 Bit

EOF+IFS

10 Bit

 

  • Start: dominant, serves the synchronization,

  • Identifier: Information to the recipient and priority information for bus arbitration,

  • RTR: distinguishes between data (dominant) and RTR telegram (recessive),

  • IDE: Identifier Extension,

  • r0, r1: reserved,

  • DLC: contains the length information of the following data field,

  • DATA: contains the data of the telegram,

  • CRC: contains the CRC check sum and CRC end detection for the preceding bit sequence,

  • ACK: contains a confirmation by other participants for the correct reception of the message,

  • EOF: marks the end of the data telegram (seven recessive bits),

  • IFS: 3-bit-long gap between CAN frames,

  • SRR: replaces the RTR-Bit in the Extended-Frame,

  • IDE: indicates that there are more 18 bits,

 

Error detection in the CAN network

The CAN protocol can detect and signalize errors itself. In order to detect errors that are  three mechanisms in the CAN protocol implemented at the message level :

1. Cyclic Redundancy Check (CRC)

The CRC ensures the information of the frame by adding the send-side redundant check bits. At the receiving side, these check bits are recomputed from the received bits and compared with the received check bits. In case of nonconformance there is a CRC error.

2. Frame-check

This mechanism checks the structure of the transmitted frame. Die durch Frame-Check erkannten Fehler werden als Formatfehler bezeichnet.

3. ACK-Fehler

Of all the receivers, the received frames are positive acknowledged (the recessive bit of the transmitter is "overwritten by dominant bits of the receiver"). If there is no acknowledgment detected on the transmitter (ACK error), this points to a transmission error detected possibly only by the recipients, to a distortion of the ACK field or to nonexistent recipients.

In addition, two mechanisms for error detection at the bit level are implemented in the CAN protocol.

1. Monitoring

Each node that transmits, simultaneously observes the Bus level. It recognizes differences between the transmitted and received bits. This helps to detect all global errors and bit errors locally occurring on the transmitter.

2. Bit-stuffing

The coding of the single bit is checked at the bit level. The CAN protocol uses the NRZ coding (Non-Return-to Zero) which guarantees a maximum efficiency with the bit coding. The synchronization flanks are produced according to the method of the bit stuffings by which after five consecutive equivalent bits a stuff bit is inserted with the complementary value into the bit stream from the transmitter, which removes the receiver automatically. If one or more errors are detected by at least one node using the above-mentioned mechanisms, the current transmission is canceled by sending an "error flag". Thereby acceptance of the transmitted message is prevented by other stations ensuring network-wide data consistency.

After demolition of the error message transmission the transmitter starts automatically re-sending the message (Automatic Repeat Request).

If an error occurs several times consecutively, this results in the automatic shutdown of the node.

Effective transfer rate of data bytes

Despite of the automatic access of a CAN node on the bus line reference values ​​can be specified for the effective transfer rate for a node of the highest priority. A message in the basic format with eight data bytes requires a maximum of 130 bits.

It is based on a maximum number of 19 stuff bits and 3 space bits:

1 Start bit

+11 Identifier bits

+ 1 RTR bit

+ 6 Control bits

+ 64 Data bits

+ 15 CRC bits

+ 19 (maximum) Stuff bits

+ 1 CRC delimiter

+ 1 ACK slot

+ 1 ACK delimiter

+ 7 EOF bits

+ 3 IFS (Inter Frame Space) bits

= 130 bits

In extended format, maximum 154 bits have to be transferred.

The net data rate is derived from the number of data bits divided by the total number of bits times the transfer rate.

The following table lists typical values ​​for the effective transfer rate with a different number of data bytes. The variable number of stuff bits is not taken into account:

 

effective transfer rate in kBit/s

at 1000 kBit/s

Number of data bytes per frame

with standard ID

with Extended ID

1

145

107

2

254

193

3

338

264

4

405

323

5

460

374

6

505

417

7

432

455

8

576

489

Table 4: effective transfer rates

The measuring amplifier GSV-3CAN, which transmits a measured value with three data bytes per frame, can transfer via CAN-network with 1 MBit/s maximum 338*1024/24 = 14421 measuring values per second.

In the packed format of the GSV 3CAN a frame with 8 data bytes is used, which contains the four measured values for each of two bytes.

The number increases thereby up to 576*1024/64*4 = 36864 measuring values per second, which can be specified via the CAN network.

Measuring Amplifier with CAN for strain gauges

To evaluate the signals from strain gauges the measuring amplifiers GSV-2, GSV-3, GSV-6 and GSV-8 are available.

Product Description
GSV-2LS Circuit board; RS232 and CAN, CANopen protocol;
GSV-2AS IP66 Alu housing, RS232 and CAN, CANopen protocol;
GSV-2FSD Front panel mounting; display, RS232 and CAN, CANopen protocol;
GSV-2TSD-DI Desktop device with battery; Display, RS232, USB and CAN, CANopen protocol;
GSV-3CAN IP66 Alu housing, CAN
GSV-6CPU circuit board, 3.3V, UART and CAN, each without transceivers
GSV-8DS Desktop  8-Kanal measuring amplifier; UART, USB, CAN with CANopen protocol
GSV-8AS IP66 Alu housing, 8-Kanal measuring amplifier; UART, USB, CAN with CANopen protocol

Table 5: Measuring amplifier for strain gage with CAN

Related Links

http://www.can-cia.org/ CAN in Automation (CiA) is the international users' and manufacturers union for the Controller Area Network (CAN).