CAN Protocol Tutorial
CAN Protocol Tutorial
1986 - Protocol
1987 - CAN 1988 - BMW 8
1983 -
was officially controller chips Series is first
Development of
produced by Intel production vehicle
CAN bus released at SAE
and Philips to feature CAN bus
Construction
Automotive
Equipments
CAN
Building Medical
Automation Equipments
Industrial
Automation
-Engine -Airbag
5
DPIT Systems Pvt. Ltd.
Bus characteristics
Serial data communications bus
Inexpensive and simple, but slower than parallel bus.
Typical definitions:
Low-speed: 25 kBit/sec up to 125 kBit/sec.
High-speed: 500 kBit/sec up to 1 Mbit/sec.
Carrier Sense: Every node monitors the bus level, all the time =>
monitoring of foreign and own CAN frames!
Multiple Access: Every node can start a transmission any time
when the bus is free.
Collision Avoidance: When several nodes start transmission at
the same time, all but one withdraw from sending.
Standardized connector
Recommended: 9-pin D-sub connectors (DIN 41652).
Note:
Different voltage levels are defined for different purposes.
Presentation Layer
Physical Layer
PLS (Physical Signalling) PLS: Bit Encoding / Decoding Bit Timing,
1 PMA (Physical Medium Synchronization
Attachment)
MDT (Medium Dependent CAN
Hardware)
Transceiver PMA: Transceiver Characteristics
MDT: Wiring, Connectors, Bus
CAN Bus
Remote
Data Frame
Frame
Overload
Error Frame
Frame
DPIT Systems Pvt. Ltd. 18
Data Frame: Formats
Standard Format (CAN 2.0A): 11-bit Identifier
211 = 2048 identifiers possible
Bus Idle Arbitration Field Control Data Field CRC Field Ack End of Inter- Bus Idle
Field Field Frame frame
Field Space
recessive
S RI r DAD
Bus Idle OF 11-bit Identifier TD0 DLC 0..64 Bit Data 15-bit CRC ECE 7-bit EOF IFS Bus Idle
RE LKL
dominant
Bus Idle Arbitration field Control Data Field CRC Field Ack End of Inter- Bus Idle
Field Field Frame frame
Field Space
recessive
S SI Rr r DAD
Bus Idle OF 11-bit Base Id RD
RE
18-bit Ext. Id T 1 0 DLC 0..64 Bit Data 15-bit CRC ECE 7-bit EOF IFS Bus Idle
R LKL
dominant
recessive
1 0
dominant
Arbitration Field
Bus Idle SOF Arbitration Field Control Field
1 0 11-bit Identifier 0 0
dominant
Control Field
Arbitration Field Control Field Data Field
0 0
dominant
Data Field
Control Field Data Field CRC Field
DLC
recessive
0 .. 64 bits ( 0 .. 8 bytes )
dominant
CRC Field
Data Field CRC Field ACK Field
DEL
recessive
1 0 1 1
dominant
DEL
recessive
1 1 1 1 1 1 1 1 1
dominant
recessive
1 1 1 1 1
dominant
Bus line
S1 0 1 0 1 0 1 0 1
S2 0 0 1 1 0 0 1 1
S3 0 0 0 0 1 1 1 1
Bus 0 0 0 0 0 0 0 1
S1 E1 S2 E2 S3 E3
Transceiver 1 Transceiver 2 Transceiver 3
Bus
Idle SOF
recessive
Unit 1 loses arbitration
1 0 0 0 1 0 0 1 1 1 1 0 1
ID: 13Dh dominant
Start
Bus
Idle SOF
recessive
Unit 2 wins arbitration
1 0 0 0 0 0 1 1 0 1 0 0 1
ID: 069h dominant
Bus
Idle SOF
recessive
Unit 3 loses arbitration
1 0 0 0 0 0 1 1 1 1 0 0 1
ID: 079h dominant
recessive
Bus
1 0 0 0 0 0 1 1 0 1 0 0 1
level dominant
Consequence: Frames
carrying information of
priority should
have a identifier
Example 2 recessive
original 1 0 0 0 0 0 1 1 0 1 0 0 1
sequence dominant
recessive
stuffed
1 0 0 0 0 0 1 1 1 0 1 0 0 1
sequence
dominant
stuff bit
Example 3 recessive
original 1 0 0 0 0 0 1 1 1 1 0 0 1
sequence dominant
recessive
stuffed
1 0 0 0 0 0 1 1 1 1 1 0 0 0 1
sequence
dominant
stuff bit stuff bit
Method of detection
Sending unit constantly monitors the bus while transmitting
Possible cause
Sending unit hardware is defective
Exceptions
Arbitration phase (unit loses arbitration)
Acknowledgement bit (unit gets positive ACK from at least one receiver)
Sending of a Passive Error Frame
Method of detection
Receiver detects error when de-stuffing a received frame
Possible causes
Error of sending unit during bit stuffing and/or transmission
Bit changed value during transmission, possibly due to EMI/RFI
An Active Error Frame was sent
Exceptions
Transmission of ACK delimiter, EOF field and Interframe Space (IFS):
11 consecutive recessive bits, bit stuffing does not apply to this section
Method of detection
Receiver calculates CRC code immediately after reception of the Data Field
Receiver compares calculated CRC code with the one contained in frame
Efficiency
Recognizes up to 5 single bit errors per frame Hamming distance: 6
Recognizes burst errors with lengths of up to 14 bits
Recognizes all odd numbers of bit errors
The more bits the CRC code has, the more efficient it is
Method of detection
Receiver checks received frames for bits or bit fields having a fixed value
(e.g. SOF bit, CRC delimiter, ACK delimiter, EOF field, Interframe Space)
Violation of frame integrity when wrong value in one of these fields
Possible cause
Transmission error, error in sender and/or receiver
Transmission of an Active Error Frame during EOF field
Transmission of an Overload Frame during Interframe Space (IFS)
Method of detection
Sender monitors the bus while transmitting recessive ACK bit
Sender expects to observe dominant ACK bit on bus
Acknowledgement error when ACK bit on bus remains recessive
Possible cause
No other nodes are connected to the bus
Not one single receiver acknowledges that the received frame was error -
free
Cause of error is very likely to be found in sender
recessive
Data Frame 6 dominant bits 8 recessive bits 3 bits Bus Idle
dominant
Error Frame violates the bit stuffing rules Other receivers are instantly
informed that an error has occurred (unless they already found out)
As a result, other units also send Error Frames
Sender and receivers reject erroneous frame completely
Sender retries transmission later
REC>127 ||
TEC>127 &
TEC <=255
Bus Off
Error Passive
TEC>255
recessive
Data Frame 6 recessive bits 8 recessive bits 3 bits Bus Idle
dominant
Error Passive
127
Warning Level
96
Error Active
Error Passive
135
127
Warning Level
96
Error Active
4.7 10-11
Example 1*
A CAN bus is used 365 days / year *Source: CiA
8 hours / day
with a transmission speed of 500 kBit / sec
and errors arise every 0.7 seconds
in 1.000 years, only one error remains undiscovered
Example 2**
A CAN bus in a car is run at 500 kBit / sec **Source: Kaiser, Schröder:
“Maßnahmen zur Sicherung
with an average bus load of 15 % der Daten beim CAN-Bus”
an average data frame size of 110 bits
for an average operating time of 4000 hours
only one error in 100.000 automobiles remains undetected
The CAN Frame is valid for the transmitter, if up to the end of END OF FRAME
no fault appears. Is a CAN Frame faulty, it will be repeated
automatically.
The CAN Frame is valid for the receiver, if up to the second last bit OF END OF
FRAME end no fault appears.
The receiver must reject the CAN Frame and has to force the transmitter to
repeat the frame, if a local error was detected during the last bit, which was
necessary for the validation of the CAN Frame.
So that the receiver can inform the transmitter, it is clear that the transmitter
must wait an additional bit time till the message for him is valid.
The problem is independent of this, which last bit is required for the validity.
Therefore nothing helps to introduce further additional bits at the end of
message.
recessive
S RI r DAD
Bus Idle O 11-bit Identifier T D 0 DLC 15-bit CRC ECE 7-bit EOF IFS Bus Idle
F RE LKL
dominant
recessive
Bus Idle 6 dominant bits 8 recessive bits 3 bits Bus Idle
dominant
Solution Bus
For reception: Hardware acceptance filters
Problems
FullCAN controllers can only transmit and Transmit
receive pre-defined identifiers Buffers
Solution
Bus
Buffers are pre-defined for groups of identifiers
instead of identifiers only
Volts
CAN-H
3.5
2.5
CAN-L
1.5
Time
Volts
CAN-H
4.0
3.25
1.75
CAN-L
1.0
Time
Node 1 . . . . . . Node n
CAN-H
120 W 120 W
CAN-L
1 - Reserved
4 - Reserved
8 - Reserved
! Solution:
CAN Bit Timing divides the bit time into several segments.
Segments can be lengthened or shortened during transmission.
Re-synchronization of nodes during transmission is possible.
1 Bit
The bit time tBit is the time it takes to transmit one bit.
Example:
1 Bit
tq
The bit time is divided up into time quanta tq.
Length of one time quantum: tq = BRP / f Sys
Allowed number of time quanta: 8 nq 25
BRP: Baud Rate Prescaler, fSys: System clock
tq
Sync_Seg Synchronization Segment
Prop_Seg Propagation Time Segment
Phase_Seg1 Phase Buffer Segment 1
Phase_Seg2 Phase Buffer Segment 2
tq
tq
The Propagation Time Segment compensates for
physical delay times within the CAN network.
Length: 1 tq tProp_Seg 14 tq
Node 1 Node 2
Node_Output_Delay Node_Input_Delay
Bus_Line_Delay
Prop_Seg 2 * ( Node_Output_Delay +
Bus_Line_Delay +
Node_Input_Delay )
tq Sample point
Lengths: 1 tq tPhase_Seg1 8 tq
2 tq tPhase_Seg2 8 tq
Presentation Layer
Controller independent DP IL
Diagnostic Interaction
Layer NM Session Layer
Protocol
Network
Management CCP Driver Transport Layer
TP Can
Transport Calibration
Protocol Protocol Network Layer
Software
Presentation Layer
Transport Layer
Provides Tx and Rx frame buffers
Network Layer
Filters messages
Physical Layer
Physical Layer
3 1
ECU 3 2 3
Transport Layer
On no internal activity and no bus activity,
ECU switches to Sleep Mode Network Layer
Ready Sleep: makes transition between Normal Operation and Prepare Bus Sleep
exists so that nodes can synchronize when entering Prepare Bus Sleep
Transport Layer
Flow control handling
Network Layer
Time-out detection and handling
B1 B2 B3 B4 B5 B6 B7 B8
0L XX XX XX XX XX XX XX
Flow Control frames (FC) : contains data used for controlling frame
flow
B1 B2 B3 B4 B5 B6 B7 B8
1L LL XX XX XX XX XX XX
B1 B2 B3 B4 B5 B6 B7 B8
2S XX XX XX XX XX XX XX
B1 B2 B3 B4 B5 B6 B7 B8
3F BS ST XX XX XX XX XX
BS tells the receiver after how many CFs to send a new FC.CTS
The FCs will always be sent by the node that receives the message, unlike
the FFs and the CFs.
Functional addressing :
corresponds to 1-to-n communication
supports only single-frame messages
functional addresses are recognized be each node (they
are not unique, and they may be multiple)
cyclic
Session Layer
cyclic and event-triggered
Transport Layer
No processing of requests !
Network Layer
Network Layer
Physical Layer