can bus

45
Main Features: o CAN stands for Controller Area Network o Serial communication protocol o Supports real time control o High level of error handling. o Multi-Master Multi-Slave communication. o Message based protocol .

Upload: -

Post on 15-Jul-2015

472 views

Category:

Engineering


5 download

TRANSCRIPT

Page 1: Can bus

Main Features:

o CAN stands for Controller Area Network

o Serial communication protocol

o Supports real time control

o High level of error handling.

o Multi-Master Multi-Slave communication.

o Message based protocol .

Page 2: Can bus

CAN Application:

o Motor vehicles

o Utility vehicles

o Industrial automation.

o Other applications for CAN are:

trains, medical equipment, building automation,

household appliances, and office automation.

Automotive

Industrial

Page 3: Can bus

o Initially developed for motor

vehicles by Robert Bosch

GmbH, Germany, starting

1983, also holding the CAN

license.

o CAN is internationally

standardized by ISO and

SAE in 1986 .

CAN History:

CAN Spec

ISO/OSI

SAE

Physical Layer

Data Link Layer

Application Layer

...

CAL, CANopen (CiA),

DeviceNet (ODVA),

SDS (Honeywell)

7

2

1 } CAN

Page 4: Can bus

o The original CAN specifications (Versions 1.0, 1.2 and 2.0A) specify

an 11 bit message identifier.

o 16 messages with the lowest priority (2032-2047) are reserved.

CAN History:

Identifier

11 bits

CRC

Field

Data Field

(0..8 Bytes) Control

Field

ACK

Field End

of Frame

Start of

Frame

Standard CAN

Page 5: Can bus

Extended CAN

o CAN specification Version 2.0B updated to meet the SAE J1939

standard .

o 29-bit identifier is made up of the 11-bit identifier ("Base ID") and the

18-bit Extended Identifier ("ID Extension").

o CAN v2.0B still allows message identifier lengths of 11 bits to be

used.

CAN History:

Identifier

29 bits

CRC

Field

Data Field

(0..8 Bytes) Control

Field

ACK

Field End

of Frame

Start of

Frame

Page 6: Can bus

CAN Specification :

o 2.0A :

Considers 29 bit ID as an error

o 2.0B Passive:

Ignores 29 bit ID.

o 2.0B Active :

Handles both 11 and 29 bit ID.

V2.0B

Active CAN Tx/Rx OK Tx/Rx OK

Frame with

11 bit ID

V2.0B

Passive CAN

V2.0A CAN

Frame with

29 bit ID

Tolerated Tx/Rx OK

Tx/Rx OK Bus

ERROR

Three Types of CAN Modules : Care when

mixing protocol

versions !

Page 7: Can bus

CAN properties :

CAN-Bus

(logical)

CAN

Nodes

e.g.

ABS e.g.

EMS

Node A Node n

o Multi Master Concept

o Number of nodes not limited by protocol

o No node addressing, Message identifier

specifies contents & priority

o Easy connection/ disconnection of nodes

o Broadcast capability

o Sophisticated error-detection and error

handling mechanisms

o Non-Return-to-Zero bit coding

Signal to

transmit a“0”

Signal to

transmit a“1”

HIGH

LOW

HIGH

LOW

Page 8: Can bus

CAN properties :

o High data transfer rate of 1000 kbps at a

maximum bus length of 40 meters

o Twisted wire pair is the bus medium

used for CAN.

o Multiple Access/Collision Detection

with Non-Destructive Arbitration.

Page 9: Can bus

CAN properties :

o The bus can have one of two complementary

logical:

o Dominant(„0‟)

o Recessive(„1‟).

o During simultaneous transmission of

‟dominant‟ and ‟recessive ‟bits, the resulting

bus value will be ‟dominant‟.

A B C BUS

0 0 0 0

0 0 1 0

0 1 0 0

0 1 1 0

1 0 0 0

1 0 1 0

1 1 0 0

1 1 1 1

Page 10: Can bus

CAN properties :

A B C BUS

0 0 0 0

0 0 1 0

0 1 0 0

0 1 1 0

1 0 0 0

1 0 1 0

1 1 0 0

1 1 1 1

Node A Node B Node C

5V

Bus State: recessive (High)

R T

rece

ssiv

e

R T

rec

es

siv

e

R T

rece

ssiv

e

1 1 1

Page 11: Can bus

CAN properties :

A B C BUS

0 0 0 0

0 0 1 0

0 1 0 0

0 1 1 0

1 0 0 0

1 0 1 0

1 1 0 0

1 1 1 1

Node A

CAN-Bus

(single logical

bus line)

Node B Node C

5V

Bus State: dominant

R T

do

min

an

t

R T re

ces

siv

e

R T

rec

es

siv

e

0 1 1

Page 12: Can bus

Bus Arbitration :

o CAN protocol handles bus accesses according to :

“Carrier Sense Multiple Access with Arbitration on Message Priority”

(CSMA/CD w/AMP).

o It avoids collisions of transmit messages simultaneously

o Arbitration priories the massages using the identifier .

o It isn‟t permitted for different nodes to send messages with the same

identifier as arbitration could fail leading to collisions and errors.

CAN properties :

Page 13: Can bus

Node X

Node A

Node B

Node C

Transmit

Request

Rest of

Frame

Arbitration

phase Node A

Node B

Node C

Node B loses Arbitration Node C loses Arbitration

Start

Bit

CAN Bus

Identifier Field

Bus Arbitration :

CAN properties :

Page 14: Can bus

Bus Arbitration :

CAN properties :

Page 15: Can bus

o NRZ if there are no edges, receivers

lose track of bits.

o Periodic edges allow receiver to

resynchronize to sender clock

o Bit stuffing is used to ensure

synchronization of all bus nodes.

Bit Stuffing :

CAN properties :

Page 16: Can bus

o When five consecutive bits of the

same polarity transmitted:

Transmitter insert one additional bit of

the opposite polarity.

o The receiver checks the number of

bits with the same polarity

Removes the stuff bits again from the

bit stream. "destuffing".

Bit Stuffing :

CAN properties :

Page 17: Can bus

o Hard Synchronization:

• CAN synchronize the message transfer

for each node with the leading edge of

SOF bit.

o Re-synchronize

• With each recessive to dominant edge.

SOF ID10 ID9 ID8 ID7

All nodes synchronize on

leading edge of SOF bit

(Hard Synchronization)

Re-

sync Re-

sync

Re-

sync

Re-

sync

Synchronization:

CAN properties :

Page 18: Can bus

CAN Frames

Remote

Frame

Inter-

frame

Space

Data

Frame

Overload

Frame

Error

Frame

Standard CAN Frames

Page 19: Can bus

11 1

Standard Data Frame Inter Frame Space

dominant

recessive

1 1 1 4 0...64 15

Sta

rt o

f F

ram

e

Ide

nti

fie

r F

ield

Da

ta F

ield

Da

ta L

en

gh

t C

od

e

CR

C S

eq

ue

nc

e

CR

C D

eli

mit

er

AC

K D

eli

mit

er

AC

K S

lot

En

d o

f F

ram

e

Inte

rmis

sio

n

Bu

s I

dle

Arbitration

Field

Control

Field

CRC

Field

Acknowledge

Field

IDE

Bit

(D

)R

TR

Bit

(D

)

( re

se

rve

d (

D))

1 7 311

CAN Frames

Standard Data Frame

RTR: Remote Transmission Request

IDE :Identifier Extension CRC :Cyclic Redundancy

Page 20: Can bus

CAN Frames CAN Frames

Standard Data Frame

o SRR (Substitute Remote Request) :replace for the RTR .

o r0 and r1: reserve for future applications.

Page 21: Can bus

Standard Data Frame Inter Frame Space

dominant

recessive

1 11 1 1 1 4 0...64 15 1 1 1 7 3

Standard Remote Frame Inter Frame Space

dominant

recessive

1 11 1 1 1 4 15 1 1 1 7 3

CAN Frames

Remote Frame

Page 22: Can bus

CAN Frames

Data and Remote Frame scenario

Data Frame; Identifier 'oil_tmp';

contains desired information ~~~~

~~~~~

Remote Frame; Identifier 'oil_tmp' Node A

Node B

(oil temp.-

sensor)

How hot is the oil ?

115°C

115 °C !

Page 23: Can bus

CAN Frames

Error Frame

Overload Frame

o Generated due to internal conditions of

a receiver, which requires a delay of

the next DATA or REMOTE frame.

Inter-Frame space

Page 24: Can bus

o There are 5 error detection mechanisms:

CAN Error Detection:

ACK

Error

Form

Error

Stuff

Error

Bit

Error

CRC

Error

Page 25: Can bus

o Calculated and received CRC checksum must match.

CAN Error Detection:

CRC

CAN_H

Node A Node B

CAN_L

Received

CRC Checksum:

Calculated

CRC Checksum:

Transmitted

CRC Checksum:

Calculated

CRC Checksum:

1234h Idle

Receive

Transmit

Idle

Receive

Transmit

CRC Sequence

Data Frame

1234h

1234h 1234h match

Page 26: Can bus

o Otherwise Frame was not received correctly (CRC Error)

CAN Error Detection:

CRC

mismatch

CAN_H

Node A Node B

CAN_L

Received

CRC Checksum:

Calculated

CRC Checksum:

Transmitted

CRC Checksum:

Calculated

CRC Checksum:

1234h Idle

Receive

Transmit

Idle

Receive

Transmit

Error Frame

1235h

1234h 1234h

Page 27: Can bus

o No Dominant Bits allowed in:

• – CRC Delimiter

• – ACK Delimiter

• – End of Frame

• – Inter-frame space

o Otherwise Form Error is generated

CAN Error Detection:

Frame Check

Page 28: Can bus

o Each Node transmits a bit must be

able to read back it correctly.

o Dominant bits are allowed to

overwrite recessive bits only in the

arbitration phase and ACK slot.

o Otherwise, a bit error should be

issued.

CAN Error Detection:

Bit Monitoring

Page 29: Can bus

o 6 consecutive bits with same

polarity are not allowed between

Start Of Frame and CRC Delimiter

o Otherwise Bit Stuffing Error.

CAN Error Detection:

Bit Stuffing

Page 30: Can bus

o A frame must be acknowledged

by at least one other node.

o Otherwise ACK Error.

CAN Error Detection:

Acknowledgment (ACK)

Page 31: Can bus

o Detected errors are made public to all other nodes via Error Frames.

o The transmission of the erroneous message is aborted and the frame is

repeated as soon as possible.

CAN Error Handling:

CAN_H

Node A Node C Node B

Error Frame

Error

detected

Error

reco-

gnized

Error

reco-

gnized

Data Frame

Idle

Receive

Transmit

Idle

Receive

Transmit

Idle

Receive

Transmit

CAN_L

Page 32: Can bus

o CAN node has three error states

• Error active

• Error passive

• Bus off

o State is according to the value of

their internal error counters.

o the error counters are updated according specific rules:

• For each error on reception or transmission,

Error counters are incremented.

• For each successful transaction,

Error counters are decremented .

CAN Error Handling:

Node Error State

Page 33: Can bus

o The error-active Node state:

• State after reset.

• Receive and transmit messages.

• Transmit active Error Frames ,

• Both error counters are smaller than or equal

to 127.

Reset

REC<=127

and

TEC<=127

Error

active

Error Handling:

Node Error State

Page 34: Can bus

o the error-passive node state/;

• Either the receive or the transmit error counter reach to128.

• Messages can still be received and transmitted.

• After transmission ,the node must suspend transmission.

Must wait 8 bit times longer than error-active nodes before

it may transmit another message.

• Passive Error Frames can be transmitted

• If both error counters go below 128 again

Node switches back to the error-active state.

Error

passive

REC>127

or

TEC>127

Error Handling:

Node Error State

Page 35: Can bus

o The bus-off state

• Transmit error counter exceeds the value

of 255.

• All bus activities are stopped which

makes it temporarily.

• Messages can be neither received nor

transmitted.

• To return to the error active state and to

reset error counter :

CAN node has to be reinitialized.

Error Handling:

Node Error State

Reset

TEC>255

Re-Initialization only

Bus

off

Page 36: Can bus

o Error Frame consists of 2 fields

• Error Flag field

• Error Delimiter field.

o Error Delimiter :

• Consists of 8 recessive bits and allows the bus nodes to restart bus

communications cleanly after an error.

o There are two forms of Error Flag fields.

o Form of the Error Flag field depends on the “error status” of the node

that detects the error.

Error Handling:

Error Frame:

Page 37: Can bus

o If “error-active” node detects a bus error :

• Node interrupts transmission by generating an “active error flag”.

• “Active error flag” is composed of six consecutive dominant bits.

• This bit sequence actively violates the bit stuffing rule.

• All other stations recognize the resulting bit stuffing error and in turn generate

Error Frames themselves.

• Error Flag field therefore consists of between six and twelve consecutive

dominant bits (generated by one or more nodes).

Error Handling:

Error Frame:

Page 38: Can bus

o If a “error passive” node detects a bus error:

• Node transmits an “passive Error Flag”.

• “Passive Error Flag” consists of six consecutive recessive bits,

• Error Frame consists of 14 recessive .

• Unless the bus error is detected by master node, the transmission of an Error

Frame by an “error passive” node will not affect any other node on the network.

• If the bus master node generates an “error passive flag” then this may cause

other nodes to generate error frames due to the resulting bit stuffing violation.

Error Handling:

Error Frame:

Page 39: Can bus

o CAN chips Dividing into:

o Basic-CAN devices

o Full-CAN devices.

o It‟s possible to use both Basic-CAN and Full-CAN devices in the

same network.

CAN Devices

Page 40: Can bus

o Only basic functions concerning the filtering and management of

CAN messages are implemented in hardware.

o Provides one transmit buffer and one or two receive.

o CAN receiver accept message which filtering certain CAN identifiers

are stored in the receive buffer.

CAN Devices

Basic-CAN devices:

Page 41: Can bus

o Only two buffers for the reception of messages the host controller is

quite busy reading and storing the incoming messages before they get

overwritten by the following ones which results in a quite high CPU

load.

o The answering of Remote Frames with the corresponding Data Frame

has to be handled by the host controller.

o Basic-CAN devices should only be used at low baudrates and low bus

loads with only a few different messages.

CAN Devices

Basic-CAN devices:

Page 42: Can bus

CAN Devices

Full-CAN devices

Host CPU

CPU load

low high

Status/Control

Registers

Message

Object 1

CAN

Protocol

Controller

Acceptance

Filtering

Host

Inter-

face

Message

Object 2

Message

Object n ..

.

Receive

Buffer(s)

CAN

Bus

Bus Inte

rface

Page 43: Can bus

o Provide the whole hardware for convenient acceptance filtering and

message management.

o For each message to be transmitted or received these devices have so

called message objects which contains all information regarding the

message (e.g. identifier, data bytes etc.).

o During the initialization, the host CPU defines which messages are to

be sent and which are to be received.

CAN Devices

Full-CAN devices

Page 44: Can bus

o Only if the CAN controller receives a message whose identifier

matches with one of the identifiers of the programmed (receive-)

message objects the message is stored and the host CPU is informed

by interrupt.

o Remote Frames can be answered automatically by the Full-CAN

controller with the corresponding Data Frame.

o the CPU load is strongly reduced compared to the Basic-CAN

solution.

o Using Full CAN devices, high baudrates and high bus loads with

many messages can be handled.

CAN Devices

Full-CAN devices

Page 45: Can bus

o http://www.engineersgarage.com/article/what-is-controller-

area-network?page=3

o http://www.nxp.com/news/press-releases/2013/12/nxp-releases-

smallest-most-efficient-can-system-basis-chips-for-in-vehicle-

networks.html#!

CAN :