|
An
Inroduction to CAN
By
Sudhish Kumar
|
|
|
Control Area network
This tutorial
will give the brief idea about CAN bus protocol, its functionality and
different features of it. This tutorial is divided into mainly five
sections as listed below.
1.
Introduction to CAN
2.
CAN layers
3.
CAN Properties
4.
Types of CAN
5.
CAN messages |
Introduction to CAN: -
The Controller Area Network (CAN) is a
serial communications protocol. CAN is widely used in automotive
electronics for engine control, sensors etc.
Layers of CAN: -
The CAN functionality is divided
into two layers.
1)
Data link layer.
2)
Physical layer.
Data link layer: -
Data link layer is subdivided into two
layers
1)
Logical link layer: -
Accept the messages by filtering process,
overload notification and recovery management tasks will be taken care by
this layer.
2)
MAC (medium access control) layer: -
This layer will do the data encapsulation; frame
coding, media access management, error detection and signaling and
acknowledgment tasks.
Physical layer: -
This layer deals with the bit encoding and de coding,
bit timing, synchronization processes.
CAN properties: -
There are two types of CAN implementations depending in
the size of the identifier field.
1) STANDARD: 11-bit wide identifier field.
2) EXTENDED: 29-bit wide identifier field.
1. Data frame: -
Description:
- Carries data from a transmitter to the
receivers.
Fields: -
Start of Frame,
Arbitration Field, Control Field, Data Field, CRC Field, ACK Field, End of
Frame.
Format: -
|
Bits: |
1 |
12/32 |
6 |
0-64 |
16 |
2 |
7 |
|
| |
SOF |
Arbitration Field |
Control field |
Data field |
CRC field |
ACK field |
EOF |
Interframe space |
SOF: Start of frame bit. It is the indication of
start of frame when a dominant bit is detected after the bus idle
condition.
Arbitration: The arbitration field is depending
on the type of frame.


This field contains:
Identifier field: contains information’s about
message. In case of standard frame the length of this field is 11 bits and
in case of extended 18 more bits are added to it .So in case of extended
frame total size of identifier field it is 29 bits.
SRR: one bit wide. Used in case of extended
frame. SRR bit will be recessive and in case standard frame this bit
replaces the RTR bit. .
RTR: one bit wide. Indicates that incoming frame
is a data frame or a remote frame depending on the value of this bit. If
it’s a dominant bit implies incoming bit stream is of data frame else if
recessive then remote frame.
IDE: one bit wide. Indicates that the incoming
frame is of standard format if dominant bit is received in this field or
else extended one (if recessive).
Control field: six bit wide. Two bits r0 and r1
are reserved. In standard frame r1 is replaced by IDE bit. And remaining 4
bits called as data length control (DLC) describes total length of data
field.
Data field: contains the actual information
within the limit of {0…8} bytes.
CRC field: 16 bit wide. Divided into two parts:
CRC sequence: 15 bit length. Calculated over SOF to
data field.
CRC delimiter: 1 bit recessive bit.
ACK field: 2 bit wide and contain two fields ACK
flag and ACK delimiter.
ACK flag: being successful reception of frame the
receiver will indicate the transmitter by putting a dominant bit in this
place. Otherwise recessive.
ACK delimiter: A recessive bit.
END OF FRAME: 7 bit wide. Consists of 7
recessive bits.
Interframe space: 3 bit wide. Two
continuous frames are separated by interframe space. Normal interfame bit
values should be recessive. In case of other values the next state will be
predicted depending on the bit position. Detailed discussion of this will
be done in later part of this tutorial.
2. Remote frame: -
Description: - Transmitted by a bus
unit to request the transmission of the data frame with the same
identifier.
Fields: - Start
of Frame, Arbitration Field, Control Field, CRC Field, ACK Field, End of
Frame.
Format: -
|
Bits: |
1 |
11/29 |
6 |
16 |
2 |
7 |
| |
SOF |
Arbitration field |
Control field |
CRC field |
ACK field |
EOF |
Remote frame is similar to data frame except
that it will not contain data field. And RTR bit is used to indicate the
remote frame.
3. Error frame: -
Description: - Any unit on detecting a error transmits
an error frame.
Fields: - Error flag and Error delimiter.
Format: -
|
Bits: |
6 |
8 |
| |
Error flag |
Error delimiter |
As shown in above figure there will be two fields in
error frame, error flag and error delimiter.
There are two types of error frames are there in CAN
1)
Active error frame: Error flag -6 dominant bits.
2)
Passive error frame. Error flag -6 recessive
bits.
And in both the cases all the bits of error delimiter
will be all recessive. Depending on the node internal error count register
condition the respective type of error frame will be transmitted.
Types of error: There are five types of error
are there in CAN and are listed below. And in case any one of these error
is observed the error frame is transmitted.
Bit error: During transmission the
node transmits the bit at transmit time region and receives the bit at
receive time and two bits are compared if they are not equal then that is
considered as bit error.
Stuff error: In a frame if
continuous 5 recessive or dominant bits are transmitted, the sixth bit
should be of opposite to that. While receiving if continuous 5 recessive
or dominant bits are received then the next incoming bit is of same value
that of previous then it will be considered as stuff error.
CRC error: While receiving data or remote frame
the CRC value will be calculated and is compared with the received CRC
values. In case of proper frame transmission both will be equal. Else that
will be considered as CRC error and error frame will be transmitted.
Form error: Form error will be
related to the error in forming the frame. For e.g. delimiter (CRC, ACK)
missing or improper end of frame, these conditions are taken as form error
and immediately error frame is transmitted.
Acknowledgement error: During the
transmission of data or remote frame, in the ACK flag field the
transmitter will put recessive bit and expect dominant bit from receive
pin. If dominant bit is observed then that is considered as proper
transmission. In other case it is acknowledgement error. The error frame
is transmitted if acknowledgment error is observed.
Depending on node state the active
error frame or passive error frame is transmitted. The error frame is
transmitted immediately if error found is of type other than CRC error.
And in case of CRC error the error frame will be transmitted immediate
next bit of ACK delimiter.
4. Overload frame: -
Description: - Detection of any one of overload
condition make node to transmit overload frame.
Fields: - Overload flag and Overload delimiter.
Format: -
|
Bits: |
6 |
8 |
| |
Overload flag |
Overload delimiter |
As shown in above figure there will be two
fields in overload frame, overload flag and overload delimiter. |