Felix Lin
• Overview
• Concepts
• Message Frame
• Error Handling
• Discussion
• Conclusion
OSI Model CAN
Application Layer
Presentation Layer
Session Layer
Transport Layer
Network Layer
Data Link Layer
Physical Layer
CANopen/MilCAN/DeviceNet…
NA
NA
NA
NA
LLC/MAC
ISO11898
Mapping
• Controller Area Network
• Half-Duplex Differential Bus
• Broadcast(Multicast) Message
• Message-Based communication protocol
• Non-Return–to-Zero (NRZ) transmission method
• Low cost and Simple implementation
• Good error detection capabilities
• Excellent two-wire fault tolerance capabilities
– Either of the two wires in the bus is broken.
– Either of the two wires are shorted to power, to
ground, or together.
• 車用電子裝置(Automotive device)
• 工業控制
• 樓宇自動化
• 船舶、火車等交通工具
• 醫療設備
• 1980s 由Bosch GmbH發展
• 目標為解決日益複雜的車載電子裝置
• 由ISO(International Standards Organization
與SAE(Society Automotive Engineers)制定
為標準
• 1991 發布 2.0A/B 標準
Before CAN
After CAN
• ISO 11898 Controller Area Network
– 1 Data Link and PHY
– 2 High-speed medium access unit
– 3 Low-speed, fault-tolerant, medium-dependent
interface
– 4 Time-triggered communication
– 5 High-speed medium access unit with low-power
mode
– 6 High-speed medium access unit with selective wake-
up functionality
• ISO 11992 p2p
• ISO 16845 Conformance test Plan
• SAE J2411
• 2.0A
– Same as 1.2 spec.
– Only Support Standard Data Frame (11-bit ID)
• 2.0B(passive)
– Support Standard(11-bit ID)
– Ignore Extended Data Frame(29-bit ID)
• 2.0B(active)
– Support Standard(11-bit ID) and Extended
Data Frame(29-bit ID)
Bit Rate Bit Time Bus Length
1 Mbps 1 µs 25 m
800 kbps 1.25 µs 50 m
500 kbps 2 µs 100 m
250 kbps 4 µs 250 m
125 kbps 8 µs 500 m
62.5 kbps 16 µs 1000 m
20 kbps 50 µs 2500 m
10 kbps 100 µs 5000 m
• Overview
• Concepts
• Message Frame
• Error Handling
• Discussion
• Conclusion
• 訊息具有優先權等級(後詳仲裁)
• 訊息間有保證延遲時間
• 設置彈性大
• 時間同步的多點接收
• 多重主站(multi-master)
• 錯誤檢測機制
• 自動重送機制
• 以訊息為基礎傳遞,並非以位址為依據由一個節點被
傳送到另一個節點
• 所有節點都會接收到Bus上的任何訊息,並且適時回
應ACK
• 在傳送的訊息中包含了資料本身以及優先等級等相關
資訊
• 各個Node 自行決定要處理此資訊或置之不理( 可經由
軟體或設定適當的Masks 以及Filters 來達成)
• 新的nodes 可隨時被加入系統中, 其他nodes 並不需因
為此新node 的加入而必需更新內部資
• CS – Carrier Sense 載波偵測
– 每個網路節點在發送訊息前必須偵測沒有其他封包在
BUS上傳送
• MA – Multiple Access 多重存取
– 每個節點都有相同的訊息傳送優先權
• CD – Collision Detection 碰撞偵測
– 如果兩個節點在同一時間點送出訊息而產生碰撞, 必需
能偵測出此衝突
• CR – Collision Resolution 衝突解決
– 非破壞性逐位元仲裁(Arbitration) (後詳)
• VCC from 4.5 to 5.5V
• uC界面的Tx和Rx 皆為數位的輸
出/輸入信號
• CANH和CANL間差動信號的電
壓為0~3.0V
– ΔV > 1.0V 稱為dominant(Logic 0)
– ΔV < 0.5V 稱為recessive(Logic 1)
• 兩個以上節點同時發送訊息時造成碰撞
• 利用ID field 逐一比較
• ID越小優先權越高
• 當發現線路上有其他節點優先權高於自己,
即停止發送
• 一般訊息優先權高於 RTR 訊息
• Sync Segment
– 用以進行同步
• Propagation Segment
– 用以對於網路延遲進行補償
• Phase Buffer Segment1
• Phase Buffer Segment2
– 用以
• Sample Point
– 取樣點
• 每個Timing Segment 可被規劃為由指定數量的
TQ(Time Quanta) 所組成
• 總時間為 8-25 TQ
• 單一 TQ 長度可以被設定,以PIC為例
2*(BRP + 1 ) (Tosc) -> (Tosc = 1/Fosc)
• DB-9
• 5-pin Mini Style connector:
ANSI/B93.55M-1981
• RJ-45
• 6-pin Deutsch DT04-6P
• Eurostyle Terminal block
1 - Reserved
2 CAN_L
CAN_L bus line
(dominant low)
3 CAN_GND CAN Ground
4 - Reserved
5 (CAN_SHLD)
Optional CAN
shield
6 (GND)
Optional CAN
ground
7 CAN_H
CAN_H bus line
(dominant high)
8 -
Reserved (error
line)
9 CAN_V+ Optional power
Pin Function DeviceNet Color
1 Drain Bare
2 V+ Red
3 V- Black
4 CAN_H White
5 CAN_L Blue
1: CAN_H = CAN_H bus line (dominant high)
2: CAN_L = CAN_L bus line (dominant low)
3: CAN_GND = Ground/0 V/V-4: Reserved
5: Reserved
6: (CAN_SHLD) = Optional CAN Shield
7: CAN_GND = Ground/0 V/V-
8 (CAN_V+) = Optional CAN external positive supply
Pin Function
Recommended
cable color
1 Power negative Black
2 CAN_H White
3 Optional Signal GND Yellow
4 Optional Initiate Gray
5 Power positive Red
6 CAN_L Blue
1: CAN_GND = Ground/0 V/V-
2: CAN_L = CAN_L bus line (dominant low)
3: (CAN_SHLD) = Optional CAN Shield
4: CAN_H = CAN_H bus line (dominant high)
5: (CAN_V+) = Optional CAN external positive supply
• Overview
• Concepts
• Message Frame
• Error Handling
• Discussion
• Conclusion
• Data Frame 資料訊框,
– Standard Data Frame 標準資料訊框 2.0A
– Extended Data Frame 擴展資料訊框 2.0B
• Remote Frame 遠端訊框
• Error Frame 錯誤訊框
• Overload Frame 超載訊框
SOF: Start of Frame
RTR: Remote Transmission Request
IDE: Identifier Extension
DLC: Data Length Code
CRC: Cyclic Redundancy Check
IFS: Inter-Frame Space
SOF: Start of Frame
SRR: Substitute Remote Request
IDE: Identifier Extension
RTR: Remote Transmission Request
DLC: Data Length Code
CRC: Cyclic Redundancy Check
IFS: Inter-Frame Space
1
要向遠端節點要求資料時發送
Remote Frame(or RTR) is used by a node when it requires
information to be sent to it from another node.
偵測到錯誤時發送
When a node detects one of the many types of errors defined by the
CAN protocol, an Error Frame occurs.
• CRC Error
– X15 + X14 + X10 + X8 + X7 + X4 + X3 + 1
• Acknowledgement Error
– 沒有其他節點回應dominant(0) 在 Ack. Slot
• Form Error
– 必須為”1”的 bit 讀取到 “dominant”(0)
• Stuff Error
– Due to NRZ,每連續五個同電位必續加入一個反向的
Stuff Bit訊號,若實體線路上發生連續六個同電位,則
產生Stuff Error
• Bit Error
– 發送訊息的節點在訊息送出時,讀取到與發送不符的準
位。除了Arbitration filed 與 Ack. filed
當節點有已收到訊息
尚未處理完成時發送
Overload frames are generated by nodes that require more time to process
messages already received.
• Overview
• Concepts
• Message Frame
• Error Handling
• Discussion
• Conclusion
• 每一個 CAN node 都有各自獨立的傳送以及接收錯
誤計數器( transmit/receive error counters) TEC 與
REC
• CAN 協定根據 Error Counters 的內容將錯誤狀態分
為三種
– Error Active
– Error Passive
– Bus Off
• 據 CAN node 的狀態不同,其控制 CAN bus 的能力
也跟著調整(Active > Passive > Bus-Off)
• 如果到達 Bus-Off 的條件,CAN node 須將自身設定
為完全離線狀態
127
127 127
127
255
• CAN node 可以主動地傳送或接收訊息(messages) 和
Error-Frames (正常工作模式)
• 當偵測到錯誤發生時將送出一個用Active Error Flag ( 6
個dominate位元)組成的Error Frame,強制中斷正在傳
送中的訊息
• 這樣的做法同時觸發了 Stuff Error,所以其他的CAN
node 也將產生它們自己的 Error Frames (稱為錯誤回應
旗標Error Echo Flags)
• 每當偵測到有錯誤發生,適當的錯誤計數器(TEC/REC)將
依當時的狀態累加
• 一旦Error Frame 完成後,bus 的活動又回到正常狀態
– 訊息將會被重新傳送!
• 當TEC 或 REC 計數器超過了127, CAN node 變進入
Error-Passive 的狀態(採用較消極的錯誤回應)
• 當一個處於 Error-Passive 狀態的node 偵測到錯誤發
生時將送出一個用Passive Error Flag ( 6個recessive
位元)組成的Error Frame
• 使用Passive Error Flags 的Error Frames 將不會影響
傳送中的訊息
• 適當的錯誤計數器(TEC/REC) 將被加累加
• 當Error Frame 完成後,處於Error-Passive 的node
會等到以下的條件符合後才會被致能傳送
– 在dominate位元之後有3個 intermission 的位元加上8
個位元的時間長度
• 當TEC 超過255 CAN node 將進入Bus-Off 狀態
• 此時的CAN node 將無法傳送或接收任何的
message 或錯誤狀態
• 透過以下的程序,可使 CAN node 再度回到
Error Active 的狀態
– 接收到正確的“bus recovery”程序(11個連續的
recessive 位元發生128 次!!)
– 經由硬體或軟體的重置動作
– 將控制器設定成“Configuration mode”
• Overview
• Concepts
• Message Frame
• Error Handling
• Discussion
• Conclusion
• HLP – Higher Layer Protocols
• Application Layer in CAN?
– CANopen
– CanKingdom
– CCP/XCP
– DeviceNet
– J1939
– MilCAN
– NMEA 2000
– OSEK/VDX
– SDS
• Overview
• Concepts
• Message Frame
• Error Handling
• Discussion
• Conclusion
• CAN為底層(L1, L2)協定,上層須搭配其他協定
• 簡單易用,使用四條線進行差動半雙工傳輸
• 傳輸距離長、低速、短訊框
• 主要應用於自動化載具與工業領域
• 適應性與容錯能力強,打不死的蟑螂
• 老兵不死,適得其所
• BOSCH, “CAN Specification version 2.0”, 1991
• Marco Di Natale, “Understanding and using the Controller Area
Network”, October 30, 2008
• Microchip, “AN713 – Controller Area Network(CAN) Basics”, Sep. 2005
• Microchip, "CAN Workshop 202”
• Freescale, “Analog Bus Communication and Products”
• Wikipedia – CAN bus

Computer Network 6 CAN

  • 1.
  • 2.
    • Overview • Concepts •Message Frame • Error Handling • Discussion • Conclusion
  • 3.
    OSI Model CAN ApplicationLayer Presentation Layer Session Layer Transport Layer Network Layer Data Link Layer Physical Layer CANopen/MilCAN/DeviceNet… NA NA NA NA LLC/MAC ISO11898 Mapping
  • 4.
    • Controller AreaNetwork • Half-Duplex Differential Bus • Broadcast(Multicast) Message • Message-Based communication protocol • Non-Return–to-Zero (NRZ) transmission method • Low cost and Simple implementation • Good error detection capabilities • Excellent two-wire fault tolerance capabilities – Either of the two wires in the bus is broken. – Either of the two wires are shorted to power, to ground, or together.
  • 5.
    • 車用電子裝置(Automotive device) •工業控制 • 樓宇自動化 • 船舶、火車等交通工具 • 醫療設備
  • 6.
    • 1980s 由BoschGmbH發展 • 目標為解決日益複雜的車載電子裝置 • 由ISO(International Standards Organization 與SAE(Society Automotive Engineers)制定 為標準 • 1991 發布 2.0A/B 標準
  • 7.
  • 8.
    • ISO 11898Controller Area Network – 1 Data Link and PHY – 2 High-speed medium access unit – 3 Low-speed, fault-tolerant, medium-dependent interface – 4 Time-triggered communication – 5 High-speed medium access unit with low-power mode – 6 High-speed medium access unit with selective wake- up functionality • ISO 11992 p2p • ISO 16845 Conformance test Plan • SAE J2411
  • 9.
    • 2.0A – Sameas 1.2 spec. – Only Support Standard Data Frame (11-bit ID) • 2.0B(passive) – Support Standard(11-bit ID) – Ignore Extended Data Frame(29-bit ID) • 2.0B(active) – Support Standard(11-bit ID) and Extended Data Frame(29-bit ID)
  • 10.
    Bit Rate BitTime Bus Length 1 Mbps 1 µs 25 m 800 kbps 1.25 µs 50 m 500 kbps 2 µs 100 m 250 kbps 4 µs 250 m 125 kbps 8 µs 500 m 62.5 kbps 16 µs 1000 m 20 kbps 50 µs 2500 m 10 kbps 100 µs 5000 m
  • 11.
    • Overview • Concepts •Message Frame • Error Handling • Discussion • Conclusion
  • 12.
    • 訊息具有優先權等級(後詳仲裁) • 訊息間有保證延遲時間 •設置彈性大 • 時間同步的多點接收 • 多重主站(multi-master) • 錯誤檢測機制 • 自動重送機制
  • 13.
    • 以訊息為基礎傳遞,並非以位址為依據由一個節點被 傳送到另一個節點 • 所有節點都會接收到Bus上的任何訊息,並且適時回 應ACK •在傳送的訊息中包含了資料本身以及優先等級等相關 資訊 • 各個Node 自行決定要處理此資訊或置之不理( 可經由 軟體或設定適當的Masks 以及Filters 來達成) • 新的nodes 可隨時被加入系統中, 其他nodes 並不需因 為此新node 的加入而必需更新內部資
  • 15.
    • CS –Carrier Sense 載波偵測 – 每個網路節點在發送訊息前必須偵測沒有其他封包在 BUS上傳送 • MA – Multiple Access 多重存取 – 每個節點都有相同的訊息傳送優先權 • CD – Collision Detection 碰撞偵測 – 如果兩個節點在同一時間點送出訊息而產生碰撞, 必需 能偵測出此衝突 • CR – Collision Resolution 衝突解決 – 非破壞性逐位元仲裁(Arbitration) (後詳)
  • 17.
    • VCC from4.5 to 5.5V • uC界面的Tx和Rx 皆為數位的輸 出/輸入信號 • CANH和CANL間差動信號的電 壓為0~3.0V – ΔV > 1.0V 稱為dominant(Logic 0) – ΔV < 0.5V 稱為recessive(Logic 1)
  • 19.
    • 兩個以上節點同時發送訊息時造成碰撞 • 利用IDfield 逐一比較 • ID越小優先權越高 • 當發現線路上有其他節點優先權高於自己, 即停止發送 • 一般訊息優先權高於 RTR 訊息
  • 21.
    • Sync Segment –用以進行同步 • Propagation Segment – 用以對於網路延遲進行補償 • Phase Buffer Segment1 • Phase Buffer Segment2 – 用以 • Sample Point – 取樣點
  • 22.
    • 每個Timing Segment可被規劃為由指定數量的 TQ(Time Quanta) 所組成 • 總時間為 8-25 TQ • 單一 TQ 長度可以被設定,以PIC為例 2*(BRP + 1 ) (Tosc) -> (Tosc = 1/Fosc)
  • 23.
    • DB-9 • 5-pinMini Style connector: ANSI/B93.55M-1981 • RJ-45 • 6-pin Deutsch DT04-6P • Eurostyle Terminal block
  • 24.
    1 - Reserved 2CAN_L CAN_L bus line (dominant low) 3 CAN_GND CAN Ground 4 - Reserved 5 (CAN_SHLD) Optional CAN shield 6 (GND) Optional CAN ground 7 CAN_H CAN_H bus line (dominant high) 8 - Reserved (error line) 9 CAN_V+ Optional power
  • 25.
    Pin Function DeviceNetColor 1 Drain Bare 2 V+ Red 3 V- Black 4 CAN_H White 5 CAN_L Blue
  • 26.
    1: CAN_H =CAN_H bus line (dominant high) 2: CAN_L = CAN_L bus line (dominant low) 3: CAN_GND = Ground/0 V/V-4: Reserved 5: Reserved 6: (CAN_SHLD) = Optional CAN Shield 7: CAN_GND = Ground/0 V/V- 8 (CAN_V+) = Optional CAN external positive supply
  • 27.
    Pin Function Recommended cable color 1Power negative Black 2 CAN_H White 3 Optional Signal GND Yellow 4 Optional Initiate Gray 5 Power positive Red 6 CAN_L Blue
  • 28.
    1: CAN_GND =Ground/0 V/V- 2: CAN_L = CAN_L bus line (dominant low) 3: (CAN_SHLD) = Optional CAN Shield 4: CAN_H = CAN_H bus line (dominant high) 5: (CAN_V+) = Optional CAN external positive supply
  • 29.
    • Overview • Concepts •Message Frame • Error Handling • Discussion • Conclusion
  • 30.
    • Data Frame資料訊框, – Standard Data Frame 標準資料訊框 2.0A – Extended Data Frame 擴展資料訊框 2.0B • Remote Frame 遠端訊框 • Error Frame 錯誤訊框 • Overload Frame 超載訊框
  • 31.
    SOF: Start ofFrame RTR: Remote Transmission Request IDE: Identifier Extension DLC: Data Length Code CRC: Cyclic Redundancy Check IFS: Inter-Frame Space
  • 32.
    SOF: Start ofFrame SRR: Substitute Remote Request IDE: Identifier Extension RTR: Remote Transmission Request DLC: Data Length Code CRC: Cyclic Redundancy Check IFS: Inter-Frame Space
  • 33.
    1 要向遠端節點要求資料時發送 Remote Frame(or RTR)is used by a node when it requires information to be sent to it from another node.
  • 34.
    偵測到錯誤時發送 When a nodedetects one of the many types of errors defined by the CAN protocol, an Error Frame occurs.
  • 35.
    • CRC Error –X15 + X14 + X10 + X8 + X7 + X4 + X3 + 1 • Acknowledgement Error – 沒有其他節點回應dominant(0) 在 Ack. Slot • Form Error – 必須為”1”的 bit 讀取到 “dominant”(0) • Stuff Error – Due to NRZ,每連續五個同電位必續加入一個反向的 Stuff Bit訊號,若實體線路上發生連續六個同電位,則 產生Stuff Error • Bit Error – 發送訊息的節點在訊息送出時,讀取到與發送不符的準 位。除了Arbitration filed 與 Ack. filed
  • 36.
    當節點有已收到訊息 尚未處理完成時發送 Overload frames aregenerated by nodes that require more time to process messages already received.
  • 37.
    • Overview • Concepts •Message Frame • Error Handling • Discussion • Conclusion
  • 38.
    • 每一個 CANnode 都有各自獨立的傳送以及接收錯 誤計數器( transmit/receive error counters) TEC 與 REC • CAN 協定根據 Error Counters 的內容將錯誤狀態分 為三種 – Error Active – Error Passive – Bus Off • 據 CAN node 的狀態不同,其控制 CAN bus 的能力 也跟著調整(Active > Passive > Bus-Off) • 如果到達 Bus-Off 的條件,CAN node 須將自身設定 為完全離線狀態
  • 40.
  • 41.
    • CAN node可以主動地傳送或接收訊息(messages) 和 Error-Frames (正常工作模式) • 當偵測到錯誤發生時將送出一個用Active Error Flag ( 6 個dominate位元)組成的Error Frame,強制中斷正在傳 送中的訊息 • 這樣的做法同時觸發了 Stuff Error,所以其他的CAN node 也將產生它們自己的 Error Frames (稱為錯誤回應 旗標Error Echo Flags) • 每當偵測到有錯誤發生,適當的錯誤計數器(TEC/REC)將 依當時的狀態累加 • 一旦Error Frame 完成後,bus 的活動又回到正常狀態 – 訊息將會被重新傳送!
  • 42.
    • 當TEC 或REC 計數器超過了127, CAN node 變進入 Error-Passive 的狀態(採用較消極的錯誤回應) • 當一個處於 Error-Passive 狀態的node 偵測到錯誤發 生時將送出一個用Passive Error Flag ( 6個recessive 位元)組成的Error Frame • 使用Passive Error Flags 的Error Frames 將不會影響 傳送中的訊息 • 適當的錯誤計數器(TEC/REC) 將被加累加 • 當Error Frame 完成後,處於Error-Passive 的node 會等到以下的條件符合後才會被致能傳送 – 在dominate位元之後有3個 intermission 的位元加上8 個位元的時間長度
  • 43.
    • 當TEC 超過255CAN node 將進入Bus-Off 狀態 • 此時的CAN node 將無法傳送或接收任何的 message 或錯誤狀態 • 透過以下的程序,可使 CAN node 再度回到 Error Active 的狀態 – 接收到正確的“bus recovery”程序(11個連續的 recessive 位元發生128 次!!) – 經由硬體或軟體的重置動作 – 將控制器設定成“Configuration mode”
  • 45.
    • Overview • Concepts •Message Frame • Error Handling • Discussion • Conclusion
  • 46.
    • HLP –Higher Layer Protocols • Application Layer in CAN? – CANopen – CanKingdom – CCP/XCP – DeviceNet – J1939 – MilCAN – NMEA 2000 – OSEK/VDX – SDS
  • 51.
    • Overview • Concepts •Message Frame • Error Handling • Discussion • Conclusion
  • 52.
    • CAN為底層(L1, L2)協定,上層須搭配其他協定 •簡單易用,使用四條線進行差動半雙工傳輸 • 傳輸距離長、低速、短訊框 • 主要應用於自動化載具與工業領域 • 適應性與容錯能力強,打不死的蟑螂 • 老兵不死,適得其所
  • 53.
    • BOSCH, “CANSpecification version 2.0”, 1991 • Marco Di Natale, “Understanding and using the Controller Area Network”, October 30, 2008 • Microchip, “AN713 – Controller Area Network(CAN) Basics”, Sep. 2005 • Microchip, "CAN Workshop 202” • Freescale, “Analog Bus Communication and Products” • Wikipedia – CAN bus