Sei sulla pagina 1di 46

Controller Area Network (CAN)

Basado en el material del


Dr. Maarten Uijt de Haag

CAN.1
Reference Material
[1] CANPRES Version 2.0
Siemens Microelectronics, Inc.
October 98
[2] CAN Specification Version 2.0
Robert Bosch GmbH
1991
[3] CAN System Engineering
Wolfhard Lawrenz
Springer-Verlag 1997
[4] Embedded Networking with CAN and CANopen
Olaf Pfeiffer et al.
RTC Books, 2003

CAN.2
Reference Material

[5] Ken Tindell, Alan Burns, "Guaranteeing Message


Latencies on Control Area Network (CAN)
[6] Microchip Application Notes - Controller Area
Network Basics
[7] Microchip Application Notes CAN Physical Layer
[8] Lars-Berno Fredriksson, "CAN for Critical Embedded
Automotive Networks," IEEE Micro, 2002.
[9] Joaquim Ferreira, et al. "The FTT-CAN Protocol for
Flexibility in Safety-Critical Systems," IEEE Micro, 2002.

CAN.3
Introduction Car Functions
Air
Conditioning

Lightning
Engine Anti-lock Power
Control Brakes Locks

Dashboard

Transmission Active
Airbag
Control Suspension Power
Seats

Power
Windows

CAN.4
Introduction Early Days
Air
Conditioning

Lightning
Engine Anti-lock Power
Control Brakes Locks

Dashboard

Transmission Active
Power Airbag
Control Suspension
Seats

Power
Windows

CAN.5
Introduction With CAN
Air
Conditioning

Lightning
Engine Anti-lock Power
Control Brakes Locks

high-speed low-speed
Dashboard
CAN bus CAN bus

Transmission Active
Airbag
Control Suspension Power
Seats

Power
Windows
= CAN
CAN.6
CSMA/CD-AMP
Carrier Sense Multiple Access/Collision Detection
with Arbitration on Message Priority

Carrier Sense Multiple Access

Transmitter tries to detect the Multiple nodes send and receive


presence of an encoded signal on the medium
(waveform) from another node before
attempting to transmit itself

CAN.7
CSMA/CD-AMP
Carrier Sense Multiple Access / Collision Detection

Transmitter is capable of detecting if


a collision has occurred on the
network

T1 Success
Node #0 Messages Retry

Node #1 T2 Success
Node #2 Messages Retry
time

CAN.8
CSMA/CD-AMP
CSMA/CD with Arbitration on Message Priority

Nodes use a form of Bit Dominance / Binary Countdown

Node #0
0 bit is dominant over the 1 bit => node 1 wins
Node #1

Network:

CAN.11
Wired-AND Implementation

A B C BUS
D D D D
D D R D
D R D D
D R R D
R D D D
R D R D
R R D D
R R R R CAN.10
CAN
Bus Arbitration
CAN is built on a Wired-AND bus similar to I2C

Node 1 Winner

Node 2

Node 3

Bus

0 : Dominant Bit
1 : Recessive bit node 2 node 3
miscompare miscompare CAN.15
CAN Physical Layer
Voltage Levels

CAN
Volts [V] High
Speed
ISO-IS
Recessive Dominant Recessive
5 11898

4 U_CAN_H
3.5V
3
2.5V
UDIFF
2
1.5V
1 U_CAN_L

CAN.29
CAN
The Identifier

El Identificador va al principio del mensaje y procuramos asignar una


prioridad al mensaje con este identificador

El mecanismo:

Example:

Priority 1 (highest priority) attitude information 0000 0000 1000 0000


Priority 2 position information 0000 0001 1100 0000
Priority 3 speed information 0000 0010 or 1110 0000
Priority 4 cabin pressure 0000 0011 1111 0000
Priority 5 personal video status 0000 0100 1111 1000

CAN.13
OSI Layers

Example:
MCP2515/
MCP2510

Example:
MCP2551

CAN.14
CAN Basics

CAN.15
EE395A-CAN Modification

EE395 EE395
Lab MCP2510 MCP2551 MCP2551 MCP2510 Lab
Board Board

CAN
Transceiver

EE395 EE395
Lab MCP2510 MCP2551 MCP2551 MCP2510 Lab
Board Board

CAN
Display Controller Keyboard Host
Controller
EE395 EE395
Lab MCP2510 MCP2551 MCP2551 MCP2510 Lab
Board Board

CAN.16
Microchip Example

CAN.17
CAN Basics

Messages transmitted from one node do not


contain an address of either the transmitting or
receiving node
Instead, the content of the message is labeled
(e.g. revolutions per minute, radar altimeter
altitude, odometer reading, airbag
accelerometer outputs etc.) by an identifier that
is unique throughout the network.
All other nodes can determine internally if they need
the information based on the identifier

CAN.18
Ken Tindell, Alan Burns, "Guaranteeing Message Latencies on Control Area Network (CAN)
CAN.19
CAN Physical Layer
Voltage Levels

Microchip MCP2551 CAN Transceiver


CAN.20
CAN Physical Layer
Voltage Levels Closer Look

0 open valve/
0 closed switch
3.5V

1.5V
0
open valve/
closed switch

CAN.21
CAN Physical Layer
Voltage Levels Closer Look

1 open switch/
1 closed valve
2.5V

2.5V

1 2.5V
open switch/
closed valve

CAN.22
Standardization Issues

bit rate [kbps] CAN


High
Speed
CAN ISO-IS
Low 11898
Speed
1000 ISO-IS
11519-2
Engine management,
Class C gearbox, ABS
125
dashboard,
Class B diagnostics
10
body
Class A control

Real-time capability
CAN.24
CAN Physical Layer
(ISO-IS 11898)

CAN
High
Speed
ISO-IS
Node 1 Node N 11898

CAN CAN
Bus Bus
Driver Driver
40 m / 130 ft 0.3 m / 1 ft
@ 1 Mbps @ 1 Mbps
CAN_H

120
120
CAN_L

CAN.24
Baud Rate versus Bus Length

From [1]
CAN.25
CAN Physical Layer
Voltage Levels What about the arbitration ?

3.5V

1.5V

2.5V Because 2.5V was


due to pull-up; so
now it will be 3.5V
2.5V and 1.5V

CAN.26
CAN Physical Layer
Bit Stuffing

Long NRZ messages may cause problems in


receivers
Clock drift means that if there are no edges, receivers
lose track of bits
Periodic edges allow receiver to resynchronize to
sender clock
Solution: stuff bits
Stuff bits are extra bits added to force transitions
regardless of data
Typical approach:
add an opposite-valued stuff bit after every 5 identical bits
In best case you dont need stuff bits they only are
needed for runs of values

CAN.27
CAN Physical Layer
Bit Stuffing - Example

H H H H H H H H H H H H H L L L L L L L L L L L L L

H H H H H S H H H H H S H L L L L L L L S L L L L L S L L L

stuff bits
CAN.35
CAN Implementations
Basic CAN
Full CAN

From [1]
CAN.29
CAN Implementations
Basic CAN
Full CAN

From [1]
CAN.30
CAN Implementation Example

(2) (3)

to
CAN
transceiver

MCP2515: Microchip Standalone CAN Controller with SPI Interface CAN.31


CAN Protocol Versions

CAN V2.0A (Standard)


11-bit identifier
211 = 2048 messages

CAN V2.0B (Extended)


29-bit identifier
229 = 536,870,912 messages

CAN.32
CAN Frame Formats

Data Frame
a CAN node wishes to transmit data
Remote Frame
a CAN node requests data from a
source node
Error Frame
Overload Frame
Interframe Space
CAN.33
CAN Frame Formats
Data or Message Frame (CAN 2.0A)

Arbitration Control Data CRC ACK EOF Int


Field Field Field Field
Bus Bus
Idle Idle

Data Length Code INTermission field


Reserve bit (DLC) (4 bits) (3 bits)
Start of Frame (r0) (1 bit) (*) End-Of-Frame
(SOF) (1 bit) Identifier Extension Bit (EOF)
(IDE) (1 bit) (7 bits)
Delimiter Delimiter After these bits the bus is
Remote Transmission Request
(1 bit) (1 bit) recognized as free. The
(RTR) (1 bit)
Cyclic Redundancy Check bus idle time may be of
11 bit identifier (CRC) (15 bits) any arbitrary length
(lower number has a higher priority) Data (0 - 8 bytes) including 0.
Number of bytes is indicated by DLC (binary)
0 : DLC = 0000
1 : DLC = 0001 I
2 : DLC = 0010 etc. (*) is the Slot bit: transmitted as recessive (1) but
subsequently overwritten by dominant bits
transmitted from any node that successfully
received the data CAN.41
CAN Frame Formats
Extended Data or Message Frame (CAN 2.0B)

Arbitration Control Data


Field Field Field
Bus
Idle

Data Length Code


Reserve bits: (DLC) (4 bits)
Start of Frame (r1) (1 bit)
(SOF) (1 bit) (r0) (1 bit)
Remote Transmission Request
18-bit identifier (RTR) (1 bit)

Identifier Extension Bit


(IDE) (1 bit)
Substitute Remote Request
(SRR) (1 bit)

11 bit identifier
(lower number has a higher priority)

CAN.42
CAN Frame Formats
Remote Frame (CAN 2.0A)
A station can initiate the transmission of respective data by its source node by sending
a remote frame. It differs from the data in that the RTR is recessive and the data field is empty!

Example: If node A wants node B to send information concerning the oil pressure
(identifier 00010101111), it sends a remote frame with that identifier. As a
result, node B will try to send oil pressure information.

Arbitration Control Data CRC ACK EOF Int


Field Field Field Field
Bus Bus
Idle Idle

Data Length Code INTermission field


Reserve bit (DLC) (4 bits) (3 bits)
Start of Frame (r0) (1 bit) (*) End-Of-Frame
(SOF) (1 bit) Identifier Extension Bit (EOF)
(IDE) (1 bit) (7 bits)

Remote Transmission Request Delimiter


I Delimiter After these bits the bus is
(1 bit) (1 bit) recognized as free. The
(RTR) (1 bit)
Cyclic Redundancy Check bus idle time may be of
11 bit identifier (CRC) (15 bits) any arbitrary length
(lower number has a higher priority) Data (0 - 8 bytes) including 0.
CAN.43
Remote Frame Scenario

CAN.37
Overload Frame
This frame is transmitted by a node that becomes too busy.
It is primarily used to provide for an extra delay between
messages.
Up to two may be used

Violates the bit


stuffing rule

Overload flag: 6 dominant bits Overload delimiter: 8 recessive bits


CAN.38
CAN Data Link Layer
Error Handling CRC - 2

Node B detects a mismatch between the calculated and the


received CRC sequence , then a CRC error has occurred.
Node B discards the message and transmits an Error
Frame to request retransmission of the garbled frame.

From [1]
CAN.39
CAN Data Link Layer
Error Handling Error Frame

Node makes detected errors public via an Error Frame


transmission of the erroneous message is aborted and the
frame is repeated as soon as possible

From [1]
CAN.40
CAN Data Link Layer
Error Handling Error Frame

ACTIVE ERROR FLAG:


six consecutive dominant bits.
PASSIVE ERROR FLAG:
six consecutive recessive bits unless it is overwritten
by dominant bits from other nodes.

Violates the bit


stuffing rule

CAN.41
Error flag: 6 dominant bits Error delimiter: 8 recessive bits
CAN Data Link Layer
Error Handling Acknowledgement Check
Transmitter checks in the Acknowledge Field of a message
to determine if the Acknowledge Slot, which is sent out as a
recessive bit, contains a dominant bit.
If this is the case, at least one other node, (here node B) has
received the frame correctly.
If not, an Acknowledge Error has occurred and the message
has to be repeated. No Error Frame is generated, though.

From [1]
CAN.42
CAN Data Link Layer
Error Handling Frame Check

If a transmitter detects a dominant bit in one of the four


segments:
CRC Delimiter,
Acknowledge Delimiter,
End of Frame or
Interframe Space
then a Form Error has occurred and an Error Frame is
generated. The message will then be repeated.
Arbitration Control Data CRC ACK EOF Int
Field Field Field Field
Bus Interframe
Idle Space

CAN.52
CAN Data Link Layer
Error Handling Bit Monitoring

When a dominant bit is detected instead of a recessive bit,


no error occurs during the Arbitration Field or the
Acknowledge Slot because these fields must be able to be
overwritten by a dominant bit in order to achieve arbitration
and acknowledge functionality.

CAN Bus

+
-

CAN.44
CAN Data Link Layer
Error Handling Bit Stuffing Error

If six consecutive bits with the same polarity are


detected between Start of Frame and the CRC
Delimiter, the bit stuffing rule has been violated.
A stuff error occurs and an Error Frame is
generated. The message is then repeated.

H H H H H H S H H H H H S H L L L

CAN.54
CAN Data Link Layer
Error Handling Error Counters

When an error is flagged, error counts are added to one of


two dedicated error count register within each CAN
controller on each node.
Receive errors are given a weighting of 1 and are
accumulated in a Receive Error Count (REC) register;
Transmit errors are given a weighting of 8 and
accumulated in a Transmit Error Count (TEC) register. If
errors continue to occur, the error counts continue to
increase.
Any good messages decrement the Error Count registers
and, if no further errors are detected, both Error Counts go
back to zero.
The accumulated error counts determine the error status
of a node.

CAN.46

Potrebbero piacerti anche