CAN_TUT

Embed Size (px)

Citation preview

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

Atmel Wireless & Microcontrollers CAN TutorialGerhard [email protected]

Agenda

CAN Tutorial

10/10/2000

1

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

Agenda8Introduction or: What is CAN? 8Why CAN? 8CAN Protocol 8CAN higher Layer Protocols 8CAN Applications 8CANary: Atmel CAN Microcontrollers & Roadmap 8Application Support 8Conclusion

CAN Tutorial

10/10/2000

2

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

Introduction The CAN is an ISO standard (ISO 11898) for serialcommunication The protocol was developed 1980 by BOSCH for automotive applications Today CAN has gained widespread use: Industrial Automation Automotive, etc.

The CAN standard includes:* Physical layer Data-link layer Some message types Arbitration rules for bus access Methods for fault detection and fault confinement

Agenda Introduction

CAN Tutorial

10/10/2000

3

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

Why CAN? Mature Standard CAN protocol more than 14 years Numerous CAN products and tools on the market

Hardware implementation of the protocol Combination of error handling and fault confinement with high transmission speed

Simple Transmission Medium Twisted pair of wires is the standard, but also just one wire will work Other links works, too: Opto - or radio links

Excellent Error Handling Strong point of the protocol: Extensive error detection mechanism

Fine Fault Confinement Built-in feature to prevent faulty node to block system

Most used protocol in industrial and automotive world Best Performance / Price ratioAgenda Why CAN?CAN Tutorial 10/10/2000 4

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

CAN Protocol8What is CAN? 8ISO-OSI Reference Model 8CAN Bus Logic 8Typical CAN Node 8CAN Bus Access and Arbitration 8CAN Bit Coding & Bit Staffing 8CAN Bus Synchronization 8CAN Bit Construction 8Relation between Baud Rate andBus Length

8Frame Formats (1) 8Frame Formats (2) 8Frame Formats (3) 8Frame Formats (4) 8Fault Confinement (1) 8Fault Confinement (2) 8Undetected Errors

Agenda CAN Protocol

CAN Tutorial

10/10/2000

5

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

What is CAN? Controller Area Network Invented by Robert Bosch GmbH Asynchronous Serial Bus Absence of node addressing Message identifier specifies contents and priority Lowest message identifier has highest priority

Non-destructive arbitration system by CSMA with collision detection Multi-master / Broadcasting concept Sophisticated error detection & handling system Industrial and Automotive Applications

Agenda CAN Protocol

CAN Tutorial

10/10/2000

6

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

ISO-OSI* Reference ModelHLPs: CANopen, DeviceNet, OSEK/V**

7. Application Layer

6. Presentation Layer 5. Session Layer 4. Transport Layer 3. Network Layer 2. Data Link LayerCAN Protocol Partially implemented by Higher Layer Protocols (HLP)

1. Physical Layer*) OSI - Open System Interconnection

Agenda CAN Protocol

CAN Tutorial

10/10/2000

7

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

CAN Bus Logic

Two logic states on the CAN bus

1 = recessive 0 = dominant

Node A

Node Node B C

D D D D R R R R

D D R R D D R R

D R D R D R D R

BUS D D D D D D D R

Wired-AND function: as soon as one node transmit a dominant bit (zero) the bus is in the dominant state

Only if all nodes transmit recessive bits (ones) the Bus is in the recessive state

Agenda CAN Protocol

CAN Tutorial

10/10/2000

8

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

Typical CAN Node

T89C51CC01/02

CAN_H

TxDI/O

Controller

CAN ControllerRxD

Diff. CAN Line Driver

CAN_L

CAN Bus(terminated by 120 Ohm on each side)

Agenda CAN Protocol

CAN Tutorial

10/10/2000

9

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

CAN Bus Access and Arbitration: CSMA/CD and AMP *)Start of Frame Arbitration Field Node 1: TxD Node 2: TxD Node 3: TxD CAN Bus

Node 2 loses Arbitration

Node 3 loses Arbitration

*)Carrier Sense Multiple Access/Collision Detection and Arbitration by Message Priority

Agenda CAN Protocol

CAN Tutorial

10/10/2000

10

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

CAN Bit Coding & Bit Staffing Bit Coding : NRZ (Non-Return-To-Zero code) does not ensure enough edges for synchronization Stuff Bits are inserted after 5 consecutive bits of the same level Stuff Bits have the inverse level of the previous bit. No deterministic encoding, frame length depends on transmitted data1 1 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 1 2 3 1 2 3 4

Data Stream

Number of consecutive bits with same polarity $

$ = Staff Bits $ $ CAN Bus Bit Stream

1 1 1 2 3 4 5 1 1 2 3 4 5 1 2 3 4 5 1 1 1 2 3 1 2 3 4

Agenda CAN Protocol

CAN Tutorial

10/10/2000

11

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

CAN Bus Synchronization Hard synchronization at Start Of Frame bitSOF

Intermission / Idle

ID10

ID9 ID8

ID7

ID6

ID5

All nodes synchronize on leading edge of SOF bit (Hard Synchronization)

Re-Synchronization on each Recessive to Dominant bit

Resynch

Resynch

ResynchCAN Tutorial 10/10/2000 12

Agenda CAN Protocol

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

CAN Bit Construction Length of one time quanta can be set to multiple of Controller clock 1 Time quantum = 1 period of CAN Controller base clock Number of time quanta in Propag and Phase segments isprogrammable1 Bit Time8 to 25 Time QuantaR

NRZ SignalD

Phases

Sync Seg1 tq

Propag Seg1 to 8 tq

Phase Seg 11 to 8 tq 1 to16 tq

Phase Seg 21 to 8 tq

Sample Point

Agenda CAN Protocol

CAN Tutorial

10/10/2000

13

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

Relation between Baud Rate and Bus Length

Bit Rate [kbps]

1000 500 200 100 50 20 10 5

0

1O

40

100

200

1000

10000

CAN Bus Length [m] Example based on CAN Bus Lines by twisted pair

Agenda CAN Protocol

CAN Tutorial

10/10/2000

14

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

Frame Formats (1)Bit StaffingSOFACK

del

Bus FrameDuration in Data Bit

ARBITRATION

CTRL 6RTR RB0 IDE

DATA 064

CRC 15

del

EOF 7

IFS 3

1 SOF

12- 32

1

1

1

CAN - V2.0ADuration in Data Bit

ID 11ARBITRATION

DLC 4

DATA

1

1

1

1 CTRL

SOF

RB1

SRR

ID[28..18] 11

ID[17..0]

RTR

IDE

CAN - V2.0BDuration in Data Bit

RB0

DLC 4

DATA

1

1

1 18 ARBITRATION

1

1

1 CTRL

SOF Start of Frame CRC Cyclic Redundancy Code del Delimiter ACK Acknowledge

EOF End of Frame IFS Inter Frame Spacing ID Identifier IDE Identifier Extension

RTR SRR RB0/1 DLC

Remote Transmission Request Substitute Remote Request Reserved bits Data Length CodeCAN Tutorial 10/10/2000 15

Agenda CAN Protocol

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

Frame Formats (2)Bit StaffingSOF

Data FrameDuration in Data Bit

ACK

del

ARBIT.*

CTRL 6

DATA 064

CRC 15

del

EOF 7

IFS 3

1

12- 32

1

1

1

(*) RTR = dominant

Bit StaffingSOF

Remote FrameDuration in Data Bit

ACK

del

ARBIT.*

CTRL 6

CRC 15

del

EOF 7

IFS 3

1

12- 32

1

1

1

(*) RTR = recessive

Agenda CAN Protocol

CAN Tutorial

10/10/2000

16

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

Frame Formats (3) If any of the CAN nodes detects a violation of the frame format or a stuff error, it immediately sends an Error Frame

Data Frame

Superposition of Error Flag Error Flag

Error Delimiter

IFS or Overload Frame

Error FrameDuration in Data Bit

6

6

8

Error Frame

Agenda CAN Protocol

CAN Tutorial

10/10/2000

17

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

Frame Formats (4) If any of the CAN nodes suffers from a data over flow, it mightsend up two consecutive Overload Frames to delay the network

EOF or Error delimiter or Overload delimiter

Superposition of Overload Flag Overload Flag

Overload Delimiter

IFS or Overload Frame

Overload FrameDuration in Data Bit 6 6 8

Overload Frame

Agenda CAN Protocol

CAN Tutorial

10/10/2000

18

CAN TutorialWIRELESS & C

Atmel Wireless & Microcontrollers

Fault Confinement (1) Three fundamental states define each nodes error signaling Error active: Normal state, node can send all frames incl.error frames Error passive: Node can send all frames excluding error frames Bus off: Node is isolated from bus

Internal error counts determine the state Transmit error counter (TEC) Receive error counter (REC) An error increases the counter by 8 A successful operation decreases by 1Communication suspended

Aims to prevent from bus dead-locks by faulty nodesCommunication active Reset TEC128

Warning at >96

Error active

REC128 TEC