Kumar S. Golla 4/10/2010
Kumar S. Golla 4/10/2010
Kumar S. Golla 4/10/2010
Golla
4/10/2010
What is CAN?
Controller Area Network
A serial communication protocol
Originally developed for automotive industry but is used
in other industries
Is a multi-master broadcast “bus”
Each node can transmit and receive, not simultaneously
Uses differential signaling
The signal pattern is encoded in NRZ
Excellent error handling and fault confinement
Bit rate 1 Mbps (< 40m) 125 Kbps (~500m)
Where is CAN used?
Modern dashboards
Before CAN
Modern cars
Automotive networks
Automotive networks (contd…)
Automotive Protocol Comparison
LIN CAN FlexRay MOST
20 Kbps max. 1 Mbps max. 10 Mbps max./ch 23 Mbps max.
Single Multiple master TDMA Multiple master
master/multiple
slave
Door Locks, Body Systems, Drive-by-Wire, Media
Climate Control, Engine Brake-by-Wire,
Seat Belts, Management, Advanced Safety
Sunroof, Lighting, Transmission and Collision
Window Lift, Avoidance
Mirror Control Systems, Steer-by-
Wire, Stability
Control, Camera-
Based Monitoring
Systems
CAN History
Started in 1986
By Robert Bosch for
Mercedes
Defined for only logical link
and physical layer
Data link layer divided into
logical link layer and media
access control
ISO 11898 (High Speed)
ISO 11519 (Low Speed)
J1939 – Trucks & Busses
CAN Layers
CAN Layers
LLC sub-layer deals with message acceptance filtering, overload
notification, and error recovery management.
MAC sub-layer presents incoming messages to the LLC sub-layer and
accepts messages to be transmitted forward by the LLC sub-layer.
MAC sub-layer is responsible for message framing, arbitration,
acknowledgement, error detection, and signaling.
MAC sub-layer is supervised by the fault confinement mechanism.
The physical layer defines how signals are actually transmitted, dealing
with the description of bit timing, bit encoding, and synchronization.
CAN bus driver/receiver characteristics and the wiring and connectors are
not specified in the CAN protocol.
System designer can choose from several different media to transmit the
CAN signals
CAN Characteristics
Carrier Sense Multiple Access with Collision
Detection (CSMA/CD) + AMP
Every node on the network must monitor the bus
(carrier sense) for a period of no activity before trying
to send a message on the bus.
Once the bus is idle, every node has equal opportunity
to transmit a message.
If two nodes happen to transmit simultaneously, a
nondestructive arbitration method is used to decide
which node wins.
CAN Characteristics
Message-Based Communication
Each message contains an identifier.
Identifiers allow messages to arbitrate and also allow each node to
decide whether to work on the incoming message.
The lower the value of the identifier, the higher the priority of the
identifier.
Each node uses one or more filters to compare the incoming
messages to decide whether to take actions on the message.
CAN protocol allows a node to request data transmission from
other nodes.
There is no need to reconfigure the system when a new node joins
the system.
CAN Characteristics
Error Detection and Fault Confinement
The CAN protocol requires each node to monitor the
CAN bus to find out if the bus value and the
transmitted bit value are identical.
The CRC checksum is used to perform error checking
for each message.
The CAN protocol requires the physical layer to use bit
stuffing to avoid long sequence of identical bit value.
Defective nodes are switched off from the CAN bus.
Bit Stuffing
CAN uses NRZ encoding
To guarantee edges
Insert opposite bit after 5 consecutive bits
Eliminates clock drift
Bit Stuffing
CAN Messages
Data Frame
Remote Frame
Error Frame
Overload Frame
127<TEC<255
REC = REC + 1
Receiver finds error after
transmitting a error frame error passive
bus off
REC = REC + 8
TEC > 255
TQ
TQ = SYNCSEG
CAN Spec Says
tseg1 tseg2
Tseg1 = PROP_SEG +
3/BRP ≤ tseg1 ≤ 16 TQ
PHASE_SEG1 3/BRP ≤ tseg2 ≤ 8 TQ
Tseg2 = PHASE_SEG2 1 TQ ≤ sjw ≤ MIN[ 4*TQ , tseg2]
TQ = (BRP + 1) / SYSCLK BRP 5 ( if three sample mode is used)
CAN Bit Timing Example
Bit Configuration for SYSCLK = 150 MHz
Sample Point at 80% of Bit Time :
CAN-Baudrate BRP TSEG1 TSEG2
1 MBPS 9 10 2
500 KBPS 19 10 2
250 KBPS 39 10 2
125 KBPS 79 10 2
100 KBPS 99 10 2
50 KBPS 199 10 2
Example 50 KBPS:
TQ = (199+1)/150 MHz = 1.334 ns
tseg1 = 1.334 ns ( 10 + 1) = 14.674 ns tCAN = 20.010 ns
tseg2 = 1.334 ns ( 2 + 1) = 4.002 ns
Message Filtering
Used to decide which message to use
Filtering applied to whole message ID
Can use optional mask registers to decide which bits
to look at in the message ID
If using mask registers, all bits should be
programmable
Types of CAN
BASIC-CAN
Close loop between MCU-core and CAN
Only one transmit buffer
Only two receive buffers
Only one filter for incoming messages
Software required to select between messages
FULL-CAN
Message server
Extensive acceptance filtering
User-configurable mailboxes
Mailbox memory/size configurable
Advanced error recognition
Types of CAN
CAL
CAN-Open
MicroCAN Open
CANiA
CAN-Open IA
DeviceNet
CAN Kingdom
SDS
J1939
Advantages
Capable of providing real-time communication
Error correction and confinement useful in noise-
critical environments
Uses lossless, bit-wise arbitration
Provides high speeds at low cost
Used for control, not data movement
Suitable for small networks
Protocol design to increase integrity of the system
Disadvantages
Electrical properties set physical limits in
combination with transmission speed
Same with branch lines
Must be terminated with load resistors
Cable end not correctly terminated can make the
whole bus inoperable
Node starvation is possible
CAN Bus Waveform
Typical CAN Implementation
Kumar S. Golla
9866005323
Backup
Masking Example
CAN Standard Frame
2.0A – Max. Frame Length 127 bits with stuffing
Arbitration Field Control Field Data Field
No Bit
Bit Stuffing
Stuffing
SOF = Start Of Frame= one dominant bit
RTR = Remote Transmission Request = Data Frame (dominant), Remote Frame (recessive)
IDE = Identifier Extension Bit = Standard Frame (dominant), Extended Frame (recessive)
DLC = Data Length Code = 4 bits (rxxx = 8 bytes) (code length 9-15 not allowed)
R0 = reserve bit = transmitted as dominant
CRC = Cyclic Redundancy Check = 15 bit with 1 bit recessive CRC delimiter
ACK = Acknowledgement = Ack slot and delimiter = xmitter sends 2 recessive bits
EOF = End Of Frame = 7 recessive bits
Error Counters
CAN Extended Frame
2.0B : Max. frame length 150 bits with stuffing
Arbitration Field Control Field Data Field
No Bit
Bit Stuffing
Stuffing