Barry
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # CANBUS 2.0A和2.0B差異及CAN FD (Controller Area Network) ###### tags: `protocols ` <style> .red { color: red; } .blue { color: blue; } .green { color: green; } .yellow { color: yellow; } </style> * CAN bus 是差動雙線通訊(CAN_H / CAN_L),差動訊號範圍約為 ±2V 以上。 * CAN BUS架構基本上都是以 CAN 2.0A and CAN 2.0B為延伸 * 多主多從(multi-master)。 * 優先權由 CAN ID 決定:數值越小優先權越高(因為 0 代表 dominant) * CAN Protocols: CAN 2.0A and CAN 2.0B. * CAN SPEED : 125kbs、250kbs、500kbs、1Mbps(不能向上支援CANFD) * CAN FD : 250kbs、500kbs、1Mbps、2Mbps、5Mbps(可以向下支援CAN BUS) * CAN FD 向下相容的精確性:但反過來,傳統 CAN 2.0 節點無法接收 CAN FD 封包(會報 Stuff Error 或 Form Error),因此在同一個網路中混合使用時需要特別小心。 * Error handling:CAN 有強大的錯誤檢測(Stuff Error, CRC Error, ACK Error 等) ![image](https://hackmd.io/_uploads/H1qifC6j0.png) ## CAN 硬體 1. 收發器(Transceiver)的角色 * CAN Bus 確實需要 收發器 (Transceiver) 作為硬體媒介。 * 功能: 它負責將微控制器 (MCU) 的數位訊號(TTL 電位)轉換為匯流排上的差動訊號(Differential Signal),反之亦然。 2. 協定分析與軟體層 * CAN Bus 的通訊協定可以透過軟體進行深度分析。 * 運作: 軟體層負責處理資料編框 (Framing)、錯誤檢查 (CRC)、仲裁機制 (Arbitration) 以及過濾 ID。 * 工具: 工程師通常使用 CAN Analyzer(如 CANoe, PCAN)或邏輯分析儀,配合軟體來解碼封包內容。 3. 終端電阻(Termination Resistor)的奧秘 * 在 CAN_H 與 CAN_L 之間並聯電阻是必要的,標準做法是在匯流排的兩端各加上一顆 120Ω 的電阻(並聯後等效電阻為 60Ω)。 * 為什麼是 120Ω?為什麼範圍在 60-120Ω 之間? 這與硬體上的訊號反射 (Signal Reflection) 與 阻抗匹配 (Impedance Matching) 有關 ## CANBUS 2.0A和2.0B差異及CAN FD、CANOPEN * CANBUS協議版本2.0A和2.0B的差異主要在protocols 不一樣。 * CAN-FD則是CANBUS的延伸。 * CANOPEN主要是在OSI中的網路層以上(包括網路層)的協定,上層應用層等。 - CANopen標準包括address、數個小的通訊子協定及由設備子協定所定義的應用層。 ![image](https://hackmd.io/_uploads/rJQaICKexx.png) ![](https://hackmd.io/_uploads/Hyt0gmGUh.png) * CAN FD與CAN的差異在Data field 和 CRC 長度 * CAN FD 是 64byte * CAN bus 2.0 是 8byte * 更詳細資料請繼續閱讀下面 ### CAN BUS 2.0A * 在CAN 2.0A協議中,標準protocols有11位元組。 * CAN 2.0A 使用 11 位protocols,最多允許傳輸 2^11(或 2048)條不同的消息。 * 2.0A版本的CAN協議使用基本帧格式(Base Frame Format),支持11位protocols(Standard Identifier)和29位protocols(Extended Identifier)。 ### CAN BUS 2.0B * CAN 2.0B 使用 29 位protocols,最多允許傳輸 2^29(或 536,870,912)不同的消息。它有兩種類型的消息幀:標準的和擴展的。 2.0B 協議還可以檢測正在發送的消息中的錯誤,並具有錯誤檢測和恢復機制。 * 2.0B版本的CAN協議則支持基本帧格式和擴展帧格式(Extended Frame Format),擴展帧格式可以支持更長的識別符(最長可達到32位),並且提供了更強大的錯誤檢測和診斷能力。 * 此外,不論是 2.0A 還是 2.0B,只要符合 ISO 11898 規範,都具備 Error Counters (TEC/REC) 與狀態切換(Error Active/Passive/Bus Off)機制。2.0A 與 2.0B 的主要區別僅在於 ID 長度與幀格式。 ``` CAN (Controller Area Network) is a communication protocol used in various industries for communication between microcontrollers and devices. There are two versions of CAN protocols: CAN 2.0A and CAN 2.0B. CAN 2.0A uses an 11-bit identifier, which allows for up to 2^11 (or 2048) different messages to be transmitted. It has a lower priority message that can interrupt higher priority messages. The 2.0A protocol can also detect errors in the message being sent. CAN 2.0B uses a 29-bit identifier, which allows for up to 2^29 (or 536,870,912) different messages to be transmitted. It has two types of message frames: standard and extended. The 2.0B protocol can also detect errors in the message being sent and has an error detection and recovery mechanism. Both CAN 2.0A and CAN 2.0B use the same physical layer, which includes the physical connection and voltage levels used for communication. ``` ### CAN OPEN(Controller Area Network, CAN) * CAN BUS 2.0延伸且支援的一種針對在網路封包的定義 * Network management (NMT) protocols. * Service Data Object (SDO) protocol. * Process Data Object (PDO) protocol. * Synchronization Object (SYNC) protocol. * Time Stamp Object (TIME) protocol. * Emergency Object (EMCY) protocol. ### CAN-FD Main features of the CAN-FD protocol are listed below: • Compatibility with the CAN protocol: CAN-FD node is able to send/receive CAN messages according to ISO 11898-1 • Error-checking improvement, based on checksum field up to CRC 21 bits • Prioritization of messages • Guarantee of latency times • Configuration flexibility • Multicast reception with time synchronization • System-wide data consistency up to 64 bytes per message • Multimaster • Error detection and signaling • Distinction between temporary errors and permanent failures of nodes and autonomous switching off of defect nodes ### CAN and CAD-FD差異 * CAN FD與標準CAN結構相似,但有以下主要不同點: * CAN FD:最大數據速率可達 8 Mbps(但實際上受限於收發器與拓撲,多數車用場景穩定在 2-5 Mbps。) * CAN FD:每個數據最多 64(Bytes),提升數據傳輸效率 * CAN FD: 數據階段(Data Phase) 可切換至更高的速率,提高吞吐量 * CAN FD 提供更強的 CRC(Cyclic Redundancy Check),提高數據完整性 * FDF(FD Format)位:用於區分 CAN FD field 與標準 CAN field * BRS(Bit Rate Switching)位:允許數據階段使用更高的傳輸速率 * ESI(Error State Indicator)位:指示節點是否處於錯誤狀態 * 數據長度:支持 0、1、2、3、4、5、6、7、8、12、16、20、24、32、48、64 字節的有效數據 ## CAN sample point 說明 * <span class="red">CAN sample point 百分比最少要 80%達到抗雜訊能力,且Master and Slave Sample point要為相同的80%</span> - 例如: I2C Slave 100k = Master 100K * 實際 Bit Time = SYNC_SEG + PROP_SEG + PHASE_SEG1 + PHASE_SEG2 1. SYNC_SEG (Synchronization Segment, SYNC_SEG) :同步區段,固定 1 time quantum(Tq),用來偵測訊號邊緣,與其他節點同步。 2. PROP_SEG (Propagation Time Segment, PROP_SEG) :傳播延遲補償時間。 3. PHASE_SEG1 (Phase Buffer Segment 1, PHASE_SEG1) :第一階段調整區,用來做同步補償。 4. PHASE_SEG2 (Phase Buffer Segment 2, PHASE_SEG2) :第二階段調整區,用來做同步補償。 5. SJW:同步跳躍寬度,代表允許調整 PHASE_SEG1 或 SEG2 的最大時間,用來處理時鐘差異。 6. Baud Rate Prescaler (BRP / NBRP):將 CAN 時脈除頻,用來產生一個 Tq。 ### Sample point 公式 * <span class="red">CAN_NBTP calculation: - Nominal bit rate prescaler(NBRP) = (fdcan_clk / ((3 + PHASE_SEG1 + PHASE_SEG2) * bit rate)) - Nominal Time segment 1(PHASE_SEG1) = ((PHASE_SEG2 + 1) * sample point / (1 - sample point))</span> ![image](https://hackmd.io/_uploads/H1fC71hMgl.png) ### Bit tim 設計分類 * Bit Time CAN (ISO 11898-1:2015) 以前設計: - BS1 (Bit Segment 1):SYNC_SEG + PHASE_SEG1(含PROP_SEG) - BS2 (Bit Segment 2):PHASE_SEG2 - SJW:同步跳躍寬度NBRP / BRP:除頻器(影響一個 Tq 的長度) * Bit Time Flexible Data-Rate CAN (ISO 11898-1:2015): - BRP(Bit Segment ): PROP_SEG - BS1 (Bit Segment 1):PHASE_SEG1 - BS2 (Bit Segment 2):PHASE_SEG2 - SJW:同步跳躍寬度NBRP / BRP:除頻器(影響一個 Tq 的長度) #### Example 1: REG設計有 SYNC_SEG + PHASE_SEG1(含PROP_SEG) + PHASE_SEG2 算法 ![image](https://hackmd.io/_uploads/SyatR1hMxx.png) ```= Can 配置: 54MHZ 1MHZ 總和54 * T SYNC_SEG = 1 (tQ) * T PHASE_SEG1 = 43 (tQ) * T PHASE_SEG2 = 10 (tQ) 1. 計算整個位時間 T BIT = TSYNC_SEG + TPHASE_SEG1 + TPHASE_SEG2 TBIT = 1 + 43 + 10 = 54tQ 2. 計算採樣點之前的時間總和(分子) Numerator = TSYNC_SEG + TPHASE_SEG1 Numerator = 1 + 43 = 44 tQ 3. 計算採樣點百分比 Sample point = 44/54 * 100% = 0.81 * 100% = 81% ``` #### Example 2: REG設計有 SYNC_SEG + PROP_SEG + PHASE_SEG1 + PHASE_SEG2 算法 ![image](https://hackmd.io/_uploads/Hkhw01nGle.png) ```= Can 配置: 54MHZ 1MHZ 總和54 * T SYNC_SEG = 1 (tQ) * T PROP_SEG = 5 (tQ) * T PHASE_SEG1= 38 (tQ) * T PHASE_SEG2 = 10 (tQ) 1. 計算整個位時間 T BIT = TSYNC_SEG + TPROP_SEG + TPHASE_SEG1 + TPHASE_SEG2 TBIT = 1 + 5 + 38 + 10 = 54tQ 2. 計算採樣點之前的時間總和(分子) Numerator = TSYNC_SEG + TPROP_SEG + TPHASE_SEG1 Numerator = 1 + 5 + 38 = 44 tQ 3. 計算採樣點百分比 Sample point = 44/54 * 100% = 0.81 * 100% = 81% ``` ## CANBUS and CANFD Protocol ### STM32 Protocol ![image](https://hackmd.io/_uploads/BkwfYnbcJg.png) After identifier, CAN 2.0 and CAN-FD have a different action: 1. CAN-FD 訊息可分為三個階段 (1) a first arbitration phase (2) a data phase (3) second arbitration phase The first arbitration phase is a message that contains: • a start of frame (SOF) • an ID number and other bits, that indicate the purpose of the message (supplying or requesting data), and the speed and format configuration (CAN or CAN-FD). The data transmission phase consists on: • the data length code (DLC), that indicates how many data bytes the message contains • the data the user wishes to send • the check cyclic redundancy sequence (CRC) • a dominant bit 3. arbitration phase and ID,指示消息的目的或提供請求數據和速度格式配置(CAN and CANFD)標準偵測是12bit = 11 bit + 1 bit r1; 4. 32bit= 11bit Base ID + 1 bit r1 + 1 bit IDE + 18 bit Extended ID + 1 bit r0, ### CAN 自行定義 ![image](https://hackmd.io/_uploads/r1HuOTn8Jg.png) ### NXP Protocol ![image](https://hackmd.io/_uploads/Bk7QEU7F1g.png) ## CAN ID * CAN上有三個device,為A,B,C。 * A device有接收ID:202,302;發送ID:101,102; * B device有接收ID:101,303;發送ID:201,202; * C device有接收ID:101,102,201;發送ID:302,303; * 如果A device發送了ID為101的Commad,因為B device和C device都有接收為101的ID,那麼B device和C device都可以接收到這條Commad。 * 如果B device發送了ID為202的Commad,因為A device有接收為202的ID,那麼A device可以接收到這條Commad。 * 如果A device發送了ID為102的Commad,因為C device有接收為102的ID,那麼A device可以接收到這條Commad。 ## 使用STM32 ### CAN2.0A與CAN2.0B的Arbitration Field * 一個32bit的Filter,可以看到在CAN2.0B當中STDID的確有10個bit,EXTID有17個bit而剩餘的就是IDE與RTR共 32bit,所以32位元的可以實現對標準與擴展的訊息過濾。 * ![](https://i.imgur.com/YjgkfVp.png) * 兩個16bit的Filter,包含了CAN2.0A當中的11個STDID、1個IDE、1個RTR與3個EXTID,只能實現對標準模式的訊息過濾。 * ![](https://i.imgur.com/x0V4QTl.png) ### Filter模式 * IDMASK : 當設置為1則會去比對所接收到的ID與Register當中的ID相不相符,0則不比對。像下方這張圖來說紅色的部分就是會比對的ID位置必須與暫存器當中相同才可以通過。 * ![](https://i.imgur.com/MBYtfK0.png) * 以32bit來看最多只能寫入一組ID去過濾而已 * ![](https://i.imgur.com/CGgCMBE.png) * 以16bit來看最多可寫入兩組ID,但只能識別標準模式下的ID * ![](https://i.imgur.com/8IMqdvS.png) * IDLIST : 所接收到的訊息當中ID必須與Filter Register當中所有的bit相同才會接收,只要有任何一個不相同則不接收。 ![](https://i.imgur.com/Ee2zUOs.png) * 以32位元來看因為是IDLIST模式,可以設置兩種ID來進行過濾 * ![](https://i.imgur.com/1FkAMWm.png) * 以16位元來看最多可設置四種ID來進行過濾 * ![](https://i.imgur.com/M4Znhkk.png) ## 邏輯分析儀解析解說 ![22F31326](https://hackmd.io/_uploads/BJRiafN9yx.png) * 只要資料有連續5個0或連續5個1 就會塞入一個stuff bit - 如果是5個0 就塞一個 1 , 5個1 就塞一個0 - CAN控制器 會自己移除這個bit,但是邏輯分析儀上面會捕捉到這個bit # 參考 * [CAN—通讯实验](https://doc.embedfire.com/mcu/stm32/f103badao/std/zh/latest/book/CAN.html) * [STM32-12 CANBus概念介紹](https://ithelp.ithome.com.tw/articles/10284348)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully