Download Automotive CAN Engli..

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

IEEE 802.1aq wikipedia , lookup

VMEbus wikipedia , lookup

Low-voltage differential signaling wikipedia , lookup

Recursive InterNetwork Architecture (RINA) wikipedia , lookup

MIL-STD-1553 wikipedia , lookup

IEEE 802.11 wikipedia , lookup

I²C wikipedia , lookup

IEEE 1355 wikipedia , lookup

UniPro protocol stack wikipedia , lookup

CAN bus wikipedia , lookup

Transcript
CAN Bus and its Applications in
Vehicles
J. Novák
Czech Technical University in Prague
Faculty of Electrical Engineering
Dept. Of Measurement
Distributed Systems in Vehicles








CAN
LIN
MOST
Byteflight
D2B
K-line
…
FlexRay
Application Areas of Distributed
Systems in Vehicles – Power Train

Communicating units
– engine, brake, gear, ABS/ESP
– steering wheel position, steering booster
– light control, damper …

High-speed and reliability are required
– running only when the ignition is on
– in future the technologies for X by wire will be applied

Today standards
– CAN (high-speed)
– Byteflight

Future: the FlexRay standard
Application Areas of Distributed Systems
in Vehicles – Comfort Functions

Communicating units
–
–
–
–


seat position control, mirrors control, windows control
air condition, vehicle top,
tires pressure control, parking assistant
wiper control, door control …
Lower-speed is enough
Low-power mode is required
– units wake-up by data transmission
– running also when ignition is off

Today standards
– CAN (low-speed)
– LIN
Application Areas of Distributed
Systems in Vehicles – Infotainment and
Telematics

Communicating units
– sound system, CD player, changer, tuner
– TV set, mobile phone, navigation
– inter-vehicle communication, traffic info reception …

Different communication speeds
– low speed for control transfers
– high speed for user data transfers (audio, video)

Low power mode required
– unit wake-up by data communication
– running if ignition is off

Today standards
– CAN (low-speed)
– MOST
Application Areas of Distributed
Systems in Vehicles – Diagnostics

Communicating units
– all (use their native interface) …

Different interfaces
– today often so called K-line with diagnostics
protocols
– gateway unit often translates diagnostics
protocols of particular ECUs
– in future the wireless diagnostics is expected
• using bluetooth ??? …
• security is the issue
CAN and ISO-OSI Model

Physical layer
– transmission line
parameters, signaling
levels, transmission
speed, …

Link Layer = CAN
– medium access control
– frame coding and
decoding
– addressing
– data security
– error states behavior
CAN and ISO-OSI Model

Application layer
– defines the data content of
link layers frames
– defines when (under which
conditions) the frames are
transmitted
– in automotive industry there
are only company standards
– standards do exist for
diagnostics

Application protocols are
defined e.g. in industrial
automation field (CANopen)
– effort to use them in vehicles
too
CAN and ISO-OSI Model

Inter-layer communication
– each protocol layer adds some information that
allows the layer protocols to provide the required
service for the layer above
data
layer L1
P1
layer L2
P2
layer L3
P3
data
data
data
P1
layer L1
P2
layer L2
P3
layer L3
CAN – Physical Layer Requirements

The basic requirement for the physical layer is
to provide so called wired OR functionality
Vcc
Vcc
Bus
1

2
Two basic signaling levels



recessive
dominant
available e.g. in fiber optics
3
CAN – Link Layer, MAC and LLC

MAC – Medium Access Control
– provides the physical channel access for the units,
prevents destructive collisions
– provides priority transmission
– implements the channel coding
– provides the data security by means of CRC check
– solves high error rate problem for particular nodes in
network
– provides mechanism for acknowledgement of correctly
received frames

LLC – Logical Link Control
– allows filtering of received frames
– solves the overload condition
CAN – Communication Principle



All nodes within the systems are equal (from the
communication point of view) – peer to peer
Frames, (sometimes called messages) are broadcasted
into the network and received by all nodes
simultaneously
There is no node oriented addressing
– frame always starts with identifier, which must provide a
unique frame content identification


In case the frame is received correctly by receiving
nodes, the acknowledge is sent to the transmitting node
In case there is an error detected during the
transmission, the error identification sequence is sent
and frame has to be transmitted again
CAN – Medium Access Control


Any node can start transmitting only if the bus idle state is
detected
In case that more than one node start transmitting
simultaneously
– there is no physical contention on the bus, as the dominant
bit transmission „beats“ the recessive one

Each node receives back the transmitted bit value
– if a node transmitting the recessive bit value receives back
the dominant bus state, it stops transmitting immediately

This method is called CSMA/CR
– Carrier Sense Multiple Access with Collision Resolution
– sometimes it is also less correctly called CSMA/CA
(…Collision Avoidance)
CAN – Medium Access Control

3 nodes start transmitting simultaneously
– Start of Frame (SOF) bit is always dominant
– 11 bits of identifier follow
– identifier must be unique within the system
CAN – Frame Identifier

Identifies the frame content
– It is not the sender nor the receiver address
• usually one node transmits frames with different
identifiers
• each node receives frames with identifiers it is
interested in
– Identifier must be unique within the system
• two different nodes are not allowed to transmit frame
with the same identifier (because of arbitration)
• In case the information source redundancy is required,
identifiers usually differ in low significant bit
– Identifier is transmitted from the most significant bit
• log. 0 is transmitted as a dominant state, log. 1 as a
recessive
• the lower identifier value, the higher frame priority
CAN – Frame Format

Current standard version is CAN 2.0
– Bosch, 1990
– it defines only the link layer protocol
– there are two parts (variants) A and B
• CAN2.0A is backward compatible with older CAN
versions, it uses 11-bit identifier
• CAN2.0B defines two data frame types – standard
and extended
– standard frame offers 11-bit identifier
– extended frame offers 29-bit identifier

Accepted as ISO11898-1 standard
– next standard parts define the physical layer
protocols too
CAN – Frame Format

4 frame types are defined
– data frame
• used for data transfer
• variable length (0 – 8 data bytes)
– remote request frame
• used to request the data frame with the same identifier
• it contains no data
– error frame
• consists of six consequent dominant or recessive bits
• it is transmitted to indicate the error
– overload frame
• the same format like the error frame
• nodes transmit it to delay the next data frame
transmission
CAN 2.0A – Data Frame Format
Bus
idle
Arbitration field
S
O
F
Length: 1




frame
identifier
11
Control
field
R R R data
T1
R 0 length
1 1 1
4
Data field
Acknowledge
CRC
0 - 8 data bytes
0 - 64
CRC E A A end of inter-frame
CC
space
15 bits R
C K D frame
15
1 1 1
bus idle – recessive state
SOF – start of frame
arbitration field (identifier + RTR bit)
control field (dedicated bits + data length)
– Both dedicated bits have a dominant value





data (0 – 8 bytes)
CRC (15-bit CRC, 1 recessive bit as a delimiter)
acknowledge (1 bit acknowledge, 1 bit delimiter)
end of frame (7 recessive bits)
inter-frame space (3 recessive bits)
7
3
CAN 2.0B – Standard Data Frame
Format
Bus
idle
Arbitration
field
S
O
F


frame
identifier
11 bits
Control
field
Data field
R I R data
T D 0 length
RE
In fact the same like CAN 2.0A frame format
Only the formal difference
– bit r1 name changed to IDE (identifier extended)

The IDE bit is always dominant in a standard
data frame
CAN 2.0B – Extended Data Frame
Format
Bus
idle
Arbitration field
S
O
F


frame
identifier
11 bits
S I
RD
RE
frame identifier
18 bits
Control
field
Data field
R
data
T RR
R 1 0 length
Allows higher number of frames in particular system
RTR bit is replaced by SRR bit (substitute remote
request)
– always recessive

IDE bit is always recessive
– standard frame with the same first 11 bits of identifier has
higher priority


Following 18 identifier bits are used for arbitration among
extended frames only
CAN controllers provide either active or passive
compatibility with CAN2.0B
CAN 2.0A – RTR Frame Format
Bus
idle
Arbitration
field
S
O
F
Length: 1



frame
identifier
11
Control
field
R R R data
T1
R 0 length
1 1 1
4
Acknowledge field
CRC
CRC E A A end of inter-frame
CC
space
15 bits R
C K D frame
15
1 1 1
7
3
RTR bit is always recessive
RTR frame identifier is the same like the data frame
identifier which transmission is requested
RTR frame has lower priority than the data frame with
the same identifier
– do you know WHY ???


Data length is always 0
Similarly it exists an extended RTR frame format
according to the CAN 2.0B
CAN – Error Frame Format
Error frame
Data frame or
error delimiter or
overload delimiter
Superpozition of error flags

Inter-frame space
or
overload frame
Error flag
Error
delimiter
Error frame consists of six dominant or recessive bits
– it depends on error state of the node which transmits it

It is transmitted by the node (-s) that detect (-s) any
communication error
– it result in an immediate transmission stop and its later
repetition
– this is all controlled by the controller (implemented in
silicon), not by application software
CAN – Overload Frame Format
Overload frame
Data frame or
error delimiter or
overload delimiter
Overload flag
Inter-frame space
or
overload frame
Overload
Superpozition of overload flags frame delimiter


Overload frame consists of six dominant bits
Its transmission is requested by the receiver in order to
– delay the transmission of a next data frame
– indicate a detection of a dominant value in a last bit of the
end of frame field or in first two bits of inter-frame space

Its occurrence does not mean an error
– previous frame is not retransmitted

Today controllers do not use it to delay the next
transmission – they are fast enough
CAN – Error Detection
Several simultaneously used mechanisms:
 Monitoring
– transmitter receives back the bus state and if it detects a
different value, its behavior is:
• in case it detects a dominant bus state within the
arbitration field while transmitting the recessive one, it
stops transmitting
• in case it detects a recessive bus state within the
arbitration field while transmitting the dominant one, or if
it detects anywhere else (excluding the ACK bit)
opposite bus state than that one it is currently
transmitting, it sends the error frame

CRC (Cyclic Redundancy Check)
– in case the locally evaluated CRC is different from the
received one, the error frame is transmitted
CAN – Error Detection

Bit stuffing
– transmitter transmits particular bits using NRZ
(not return to zero) coding
– if there is a sequence of 5 consecutive bits of the
same level, one bit of the opposite level is
inserted
– during the reception an inverse process takes
place, it means after five received bits of the
same level the next bit must be of the opposite
level (check) and it is known it is an inserted bit –
it is thus removed
CAN – Bit Stuffing

Error frame transmission violates bit stuffing rule
– all nodes thus detect the error
– it is thus ensured that the frame is received either by all
nodes or by no node
• data consistency
CAN – Error Detection

Frame format check
– some bits have predefined level
• CRC or ACK delimiters are always recessive
• end of frame field is whole recessive
– if there is a dominant bit detected, an error frame is sent
– data length field can contain value higher than 8
• length of 8 is expected
• error frame is not sent

Frame receive acknowledge
– by the dominant level in the ACK bit
– if there is no acknowledge, transmitting node sends an
error frame
– data frame transmission is repeated
CAN – Node Error States

One node encountering communication problems could
block complete communication within the system
– it detects an error in each received frame and transmits an
error frame
– it is necessary to limit this possibility

There are two so called error counters in each CAN
controller (and thus in each network node)
– one for errors during transmission, one during reception
– at the beginning they are reset
– if there is an error during transmission, transmission error
counter value is increased, the same is tru for reception


If the transmission or reception have passed without
error, the respective value is decremented (up to zero)
According to the error counters values particular node is
in one of three error states
CAN – Node Error States

Error active
– value of each of both error counters has to be lower
than 128
– in case the error is detected during the frame
transmission or reception, an active error flag (6
consecutive dominant bits) is generated
– it breaks communication and all other nodes within
the system detect error as well
– the number the respective error counter is increased
(0, 1 or 8) depends on the error context, it means the
situation and conditions of error detection
– if any of error counters reaches the value higher than
127, the respective node goes into the error passive
state
CAN – Node Error States

Error passive
– the value of at least one error counter is higher than 127
– if the node detects communication error, it generates a
passive error flag (6 consecutive recessive bits)
– if the error passive node is the only one who detects
error (probably incorrectly), the communication is not
broken and can be finished and acknowledged by other
nodes
– in case of successful reception the respective counter is
either decremented (if its value was lower than 128) or
set between 119 and 127 (if its value was higher 127)
– if the values of both counters fall under 128, the node
goes back to error active state
– if the value of transmission error counter gets over 255,
the controller enters bus-off state
CAN – Node Error States

Bus-off state
– transmission error counter value is higher than 255
– reception error counter value has no influence on entering
into the bus-off state
– bus-off node is completely disconnected from the network
(logical not physical disconnect)
• it is not possible to transmit frames nor to influence the
bus communication by any way (no ACK, error frame..)
• reception is possible (depends on implementation)
– from the point of view of other nodes the bus-off node
disappears from the network (like switched off)
– to leave the bus-off state only the controller hardware or
software reset is available
• then after the detection of 128 recessive 11-bit
sequences the controller enters an error active state
• incorrect software implementation can make global
problems in communication
CAN – Error States Servicing
CAN controller Status register usually contains:
 Error warning flag
– set if any error counter reaches some limit
• usually 96
• sometimes this limit can be preset
– controller can generate an interrupt service request
– application software (node firmware) may or may not
service this event

Error passive flag
– set by entering the error passive state
– interrupt service request possible
– Application software should také into account possible data
inconsistency within the local node and the rest of a
network

Bus-off flag
– controller reinitialization is necessary
CAN – Persisting communication
problems

It always depends on the error type, direction of
communication (reception, transmission) where it takes
place as well as the physical layer protocol version
– e.g. tolerance to some shorts

Fatal errors (e.g. Short connection of both CAN lines to
ground) always finishes in bus-off state
– only in case the node tries to transmits



The node which is alone in the network (or disconnected
by cable interrupt), enters after 16 unacknowledged
frame transmissions into an error passive state
If the software service of error states is not correctly
implemented, serious communication problems may
occur
Under the standard conditions all nodes within the
system are in the error active state and there are no error
frames generated
CAN – Physical Layer Standards



CAN standard (Bosch) defines the link layer protocol only
It is also standardized by ISO as ISO11898-1
Physical layers are defined in standards ISO11898-2
– high-speed CAN
– up to 1 Mbit/s

and ISO11898-3
– low-speed CAN
– up to 125 kbit/s
– particular fault tolerance



Both these physical standards are widely used in today
vehicles
For trucks there are othe standards available with higher
degree of immunity
They are all defined as SAE standards too
CAN – ISO11898-2 Physical Layer




Bus structure with terminators
Line impedance of 120 ohm
Communication speed up to 1 Mbit/s
Differential signaling (logical level defined by voltage
difference)
– CAN_H and CAN_L lines
CAN – ISO11898-2 Physical Layer

The recessive level is provided by terminators and
„wake“ voltage sources in transceivers
– CAN_H – CAN_L difference is near 0

The dominant state is driven by the transceiver
– CAN_H – CAN_L difference is about 2 volts
CAN – ISO11898-2 Physical Layer



The transceiver contains the temperature, short circuit
and ESD protection
Low load in power off state
Some offer low power states
CAN – ISO11898-3 Physical Layer




Bus structure
Sleep mode with remote wake-up by CAN
communication
Communication speed up to 125 kbit/s
Differential signaling
CAN – ISO11898-3 Physical Layer

Particular fault tolerance, transceiver enters so
called single wire mode
–
–
–
–
–

CAN_H or CAN_L wire broken
short connection of CAN_H or CAN_L to ground
short connection of CAN_H or CAN_L to +5V
short connection of CAN_H or CAN_L to +12V
short connection of CAN_H to CAN_L
Single wire mode is indicated by the transceiver
output
– after the fault is removed transceiver
automatically enters standard two wire mode
CAN – ISO11898-3 Physical Layer

RTH and RTL resistors provide termination
– their values depend on number of nodes in system


Transceiver supports node wake-up when the CAN
activity is examined, or by he local signal
Sleep mode is controlled by the local microprocessor
– if the whole bus is in sleep (low power) mode, CAN_H
voltage is near 0 and CAN_L voltage is near the battery one
CAN – Immunity to External
Disturbances

Information is transferred by the voltage difference
– if both wires are close the induced disturbance is the
same, difference stays the same
– the absolute value of the induced disturbance can be
further decrease with utilization of twisted pair wire
CAN – Transmission Timing



všechny uzly v síti musí mít nastavenu shodnou
nominální přenosovou rychlost
skutečné rychlosti se mírně liší (tolerance
oscilátorů)
vzhledem k faktu, že v průběhu arbitráže může
vysílat více uzlů najednou, že arbitráž probíhá bit
po bitu a že šíření informace z jednoho uzlu do
druhého je zatíženo zpožděním (budič – vedení –
přijímač), je třeba:
– kompenzace statických zpoždění
– průběžné synchronizace
• kvůli odchylkám oscilátorů
CAN – časování komunikace
Node 1-Tr.
Node 1-Rec.
Node 2-Tr.
Node 2-Rec.

příklad „současného“ vysílání dvou uzlů
– maximální zpoždění, s nímž je nutno počítat, je dáno
dvojnásobkem zpoždění řetězce budič, vedení, přijímač
CAN – časování komunikace

konstrukce délky bitu
– programovatelná dělička generuje signál s délkou
označovanou jako časové kvantum
– z celistvého počtu časových kvant je poté složen bitový
interval
CAN – časování komunikace
Sample point
Bit interval
Sync.
segment

Propagation
segment
Phase
segment 1
Phase
segment 2
bitový interval se skládá z 8 až 25 časových
kvant, která jsou rozdělena do 4 segmentů
– synchronizační segment je dlouhý 1 časové
kvantum
– „propagation“ segment slouží ke kompenzaci
zpoždění mezi uzly
– „phase buffer“ segmenty 1 a 2 určují bod, kde
řadič vzorkuje, zda je na sběrnici recesivní či
dominantní úroveň
CAN – časování komunikace

na začátku rámce dochází k tzv. tvrdé synchronizaci
(hard synchronization)
– sběrnice je vzorkována s periodou časového kvanta
– je-li detekován přechod z recesivní do dominantní úrovně,
pak je dané časové kvantum považováno za synchronizační
segment

v průběhu vysílání rámce dochází k resynchronizaci
– délka „phase buffer“ segmentů je měněna podle
detekovaných hran tak, aby hrany vždy spadaly do
synchronizačního segmentu jednotlivých bitů
– využívá se pouze přechodů z recesivní do dominantní
úrovně
– velikost synchronizačního skoku je omezena
– časový rozdíl mezi očekávaným a skutečným výskytem
hrany se nazývá fázovou chybou
– dvě varianty resynchronizace podle znaménka fáz. chyby
CAN – časování komunikace

při kladné fázové chybě je „phase buffer 1“ segment
prodloužen ak, aby byl bod vzorkování správně zpožděn
za příchozí hranou signálu
– dojde vlastně k „dočasnému zpomalení“ taktu
CAN – časování komunikace

při záporné fázové chybě je „phase buffer 2“ segment
zkrácen tak, aby byl příslušná hrana signálu ležela v
synchronizačním segmentu následujícího bitu
– dojde vlastně k „dočasnému zrychlení“ taktu
CAN – časování komunikace

z doposud uvedeného vyplývá, že maximální
délka sběrnice závisí na přenosové rychlosti
– musí být kompenzováno zpoždění
CAN – měření parametrů

fyzické vrstvy
– úrovně signálů
• osciloskop
– rychlosti hran
• osciloskop
– hodnoty terminátorů
• multimetr, osciloskop
– přenosová rychlost
• osciloskop
– pozice vzorkovacího bodu v bitu
• vyžaduje specielní přístrojové vybavení
• není třeba, pokud je k dispozici zdrojový kód
firmware jednotky
CAN – měření parametrů

spojové vrstvy
– lze spoléhat na správnost implementace v řadiči
– důležité jsou správné reakce firmware na výskyt
chybových stavů
– při bus-off stavu nelze jednoduše zinicializovat
řadič a spoléhat na to, že se jednalo o náhodu
• obvykle stačí osciloskop
• na definované vynucení bus-off stavu je třeba
specielní přístroj
CAN – měření parametrů

aplikační vrstvy
– vysílání rámců se správnou periodou a obsahem za všech
okolností
– důležité jsou správné reakce firmware na výskyt chybových
stavů
• zápisy do chybových pamětí
– testování jednotky od vstupů k výstupům (hardware in the
loop)
• CAN  fyzický výstup
• fyzický vstup  CAN
– aplikační testy závisí na typu jednotky, aplikačních
protokolech apod.
• automobilky obvykle přesně definují
požadavky testů a testovací procedury
– dle povahy aplikačních testů je obvykle nezbytný analyzátor
a generátor rámců v sestavě s osciloskopem, případně
CAN – aktivní a pasivní monitoring

pro většinu aplikačních měření na CANu postačí
monitoring komunikace v síti
– aktivní monitoring spočívá v plném začlenění
monitorovacího uzlu do komunikace v síti, včetně
generování potvrzení, chybových rámců a případné účasti v
arbitráži
• jediná možnost, pokud je měřený uzel
jediný v síti
– pasivní monitoring spočívá v pouhém odposlechu
komunikace bez zásahu do ní
• nelze vysílat
– některé řadiče (např. SJA1000) podporují oba režimy
• další využití je pro automatickou detekci
přenosové rychlosti
– řadič, který pasivní režim nepodporuje, lze pro jeho podporu
snadno doplnit jednoduchou logikou, která zabrání vysílání
na sběrnici, ale umožní zpětný příjem vysílaných dat