Four CAN bus BOSCH CAN2.0 Part A

Foreword

  As more and more applications and accepts introduction of serial communication, which requires the assignment of message identifiers for the communication function of the specific application for standardization. If the address range of the original 11 bit identifier defined expansion, can be more convenient to use CAN implement these applications.
  Thus, the introduction of a second message format ( Extended Format ), which provides a larger address range defined by the 29-bit identifier. This will reduce the burden on system designers in a well-defined structure naming programs. Identifier need to extend the range of formats can still rely on traditional user 11 bit identifier range ( standard format ). In this case, they can use the existing CAN controllers on the market, or to achieve the two formats of the new controller.
  In order to distinguish the standard format and extended format , using a first reserved bit r1 (r1 and r0 control domain has two reserved bits) CAN message format of the control field. This is done to make the CAN Specification 1.2 is equivalent to the old message format of the new standard format of the present specification. Furthermore, the present specification defines extensions and message format standard format coexist in the same network.

CAN2.0 specification consists of two parts

  • Part A CAN message format described in CAN Specification 1.2 defined
  • Part B describes the standard message format and the extended message format

Note: Part A according to the present specification or in accordance with the previous design CAN specification CAN implemented, in accordance with Part B of this specification and design CAN may communicate with each other, as long as it does not use the extended format can be.

Brief introduction

  CAN2.0 Part A aimed at achieving compatibility between any two CAN network. However, the compatibility of different aspects, for example, electrical characteristics and interpretation of data to be transmitted. In order to achieve transparency and flexibility of design embodiment, CAN2.0 Part A to CAN subdivided into different layers:

  • CAN object layer (the (CAN-) object layer)
  • CAN transport layer (the (CAN-) transfer layer)
  • The physical layer (the physical layer)

Objects and transport layers comprises all the services and functions of the data link layer defined by the ISO / OSI model. Range target layer comprising

  • Find the message to be sent
  • Determining which of a packet received by the transport layer actually used
  • Providing application layer related hardware interface

The main scope of the transport layer is a transport protocol, i.e. the control frame, performing arbitration, error checking, signal errors and faults constraints. In the transport layer, the bus may be used to determine whether a new transmission or reception start if just begun. In addition, some of the general characteristics of bit timing is also considered to be part of the transport layer.

  The CAN layered architecture of the OSI reference model
Here Insert Picture Description

  • The physical layer defines the actual transmission mode signal. In the present specification, the physical layer is defined to allow the transmission medium and the signal level to achieve optimized for their application
  • Transport layer represents the core of the CAN protocol. It presents the received message to the target layer, the target layer and receiving a message from the transmission. Transport layer is responsible for timing and synchronization bits, message framing, arbitration, acknowledgment, and error detection and fault signaling constraints.
  • Object Layer relates to message filtering and message and status handling.

Scope of this specification is the effect of the CAN protocol transport layer, and the surrounding layers is defined

Single-channel (Single Channel)

  Bus is carried by a single channel bit of the composition. This channel can be obtained by re-synchronization information data. This specification does not limit the use of these methods to achieve, i.e., the physical layer is not defined. To achieve this channel, using the single core wire (plus ground), two differential lines, optical cable and the like.

Value bus (Bus value)

  Bus can have one of two complementary logical values: 'dominant' or 'recessive. " When the "dominant" bits and "recessive" bits simultaneously transmitted, the result bus is "dominant." For example, in the implementation of the bus "line", 0 represents logic 'dominant' level represents logic 'recessive' level. This specification does not give a physical state which represents logic level (e.g., voltage, light).

Bit Rate

  CAN speed may be different in different systems. However, in the system in the specified bit rate is uniform and is fixed.

Synchronize

Details see another blog post

arbitration

  And each node on the CAN bus for transmitting data to the bus simultaneously read the data on the bus, and the data transmitted by itself for comparison. Whenever the bus is free, any unit may start sending messages. If two or more units simultaneously start to send a message, use the IDENTIFIER by a bit-wise arbitration to resolve bus access conflicts. Arbitration mechanisms to ensure information and time will not be lost. If the start and REMOTE FRAME DATA FRAME IDENTIFIER same while the DATA FRAME precedence REMOTE FRAME.
  During arbitration, every transmitter on the bus all levels and monitoring the level of the transmitted bit is compared. If the same level, the unit may continue to transmit. If the transmission is a bit of the recessive level , and to monitor a bit depending on the dominant level (see bus value), then the unit has lost arbitration and must exit the transmission state. If a non-quorum during the (arbitration field range), found bits do not match, an error.
Here Insert Picture Description

encoding rules

  DATA FRAME 或 REMOTE FRAME 中的位字段 START OF FRAME,ARBITRATION FIELD,CONTROL FIELD,DATA FIELD 和 CRC SEQUENCE 都需要通过比特填充的方法编码。 每当发送器在要发送的比特流中检测到相同值的五个连续比特时,则自动在实际发送的比特流中插入一个相反的比特位,这种方法被称为位填充
  DATA FRAME 或 REMOTE FRAME 的剩余位字段 CRC DELIMITER,ACK FIELD 和 END OF FRAME 是固定的格式,不需要填充。 ERROR FRAME 和 OVERLOAD FRAME 也是固定格式,不通过位填充方法编码。
  消息中的比特流根据不归零(Non-Return-to-Zero,NRZ)法进行编码。这意味着在总比特时间内,生成的比特电平要么是“显性”要么是“隐性”。

详细说明见另一篇博文《CAN 总线 之 BOSCH CAN2.0 比特位填充(编码规则)、归零编码(RZ)和不归零编码(NRZ)》

消息传输

  消息即总线上传输的节点的信息。其实就是一些固定长度的不同格式的比特位电平的组合。消息传输由四种不同的帧类型显示和控制:

  • 数据帧(DATA FRAME): 将数据从发送器传送到接收器。
  • 远程帧(REMOTE FRAME): 由总线单元发送,以请求传输使用相同的IDENTIFIER 的 DATA FRAME。
  • 错误帧(ERROR FRAME): 在检测到总线错误时,任何单元都会发送错误帧。
  • 过载帧(OVERLOAD FRAME): 用于在前一个和后一个DATA或REMOTE FRAME之间提供额外的延迟。

DATA FRAME 和 REMOTE FRAME 通过 INTERFRAME SPACE 与前一帧分离。

数据帧(DATA FRAME)

  DATA FRAME 由 7 个不同的位域组成:START OF FRAME、ARBITRATION FIELD、CONTROL FIELD、DATA FIELD、CRC FIELD、ACK FIELD、END OF FRAME。 其中,DATA FIELD 长度可以为 0。帧格式如下图所示:
Here Insert Picture Description
一个完整的数据帧(忽略位填充的情况下)图示如下:
Here Insert Picture Description
Here Insert Picture Description
下面详细介绍一下每一部分。

帧起始(START OF FRAME)

  标志着 DATA FRAME 和 REMOTE FRAME 的开始。它占 1 个比特位,必须为显性电平
  只有在总线空闲时才允许站点开始传输(参见 BUS IDLE)。 所有站必须同步到由首先开始传输的站的 START OF FRAME(参见’HARD SYNCHRONIZATION’)引起的前沿。

仲裁域(ARBITRATION FIELD)

由 IDENTIFIER 和 RTR-BIT 组成。共占 12 个比特位。如下图:
Here Insert Picture Description

  • 标识符(IDENTIFIER): IDENTIFIER 的 长度为 11 个比特位。 这些位按 ID10 ~ ID0 的顺序发送。 最低有效位是 ID0。7 个最重要的位(ID10 ~ ID4)不能全部为隐性电平
  • RTR 位(RTR BIT): 全称 Remote Transmission Request BIT。占 1 个比特位。在 DATA FRAME 中,RTR BIT 必须是 显性电平。 在 REMOTE FRAME 内 RTR BIT 必须是 隐性电平

在数据帧和具有相同标识符的远程帧同时发送的情况下,由于数据帧标识符之后的 RTR 位是显性,它将赢得仲裁。

控制域(CONTROL FIELD)

  由六个比特位组成。 它包括 DATA LENGTH CODE 和 为未来扩展保留的两位。 保留位必须为显性电平。 接收器在所有组合中接受“显性电平”和“隐性电平”位。
Here Insert Picture Description
  DATA LENGTH CODE 指示了 DATA FIELD 中的字节数,使用如下的代码指示。该数据长度为4个比特位
Here Insert Picture Description

从物理上来说,4 位的数据长度代码还可以传输 9-15 的值,但是数据段依旧被限制到 0 ~ 8。部分控制器允许传输或接收大于 8 的 DATA LENGTH CODE 值,但是实际数据长度仍然限制在 8 位。

数据域(DATA FIELD)

  在 DATA FRAME 内要传输的数据。 它可以包含 0 ~ 8 个字节,每个字节包含 8 位,首先传输 MSB。

CRC 域(CRC FIELD)

  由 CRC SEQUENCE 和 CRC DELIMITER 两者组成。共占 16 个比特位(15 + 1)
Here Insert Picture Description

  • CRC SEQUENCE: 多项式为 X15 + X14 + X10 + X8 + X7 + X4 + X3 + 1。计算范围:帧起始,仲裁字段,控制字段,数据字段(如果存在)。
  • CRC DELIMITER: 必须是一个比特位的隐性电平

应答域(ACK FIELD)

  ACK FIELD 占 2 个比特位,ACK SLOT 和 ACK DELIMITER 各占一个比特位。
Here Insert Picture Description

  • ACK SLOT: 发送器发送数据时,必须发送隐性电平。当接收器正确接收到数据(已经接收到匹配的 CRC SEQUENCE)后,接收器将 ACK SLOT 置为显性电平,将此情况报告给发送器。
  • ACK DELIMITER: 必须一直是 1 个比特位的隐性电平

帧结束(END OF FRAME)

  每个 DATA FRAME 和 REMOTE FRAME 由一个由 7 个比特位的隐性电平位组成的标志序列分隔。

远程帧(REMOTE FRAME)

  通过发送 REMOTE FRAME,需要数据的节点可以请求另一节点发送相应的 DATA FRAME。 DATA FRAME 和相应的 REMOTE FRAME 由相同的 IDENTIFIER 命名。
  通常,数据传输是在数据源节点(例如传感器)发出数据帧的情况下自主执行的。但是,目标节点也可以通过发送远程帧来从信息源请求数据。
  远程帧由以下 6 个不同的位域组成:START OF FRAME、ARBITRATION FIELD、CONTROL FIELD、CRC FIELD、ACK FIELD、END OF FRAME。格式如下图所示:
Here Insert Picture Description
  与 DATA FRAME 相反,REMOTE FRAME 的 RTR 位是 1 个比特位的隐性电平。 没有 DATA FIELD。CONTROL FIELD 中的 DATA LENGTH CODE 字段表示所请求的消息的数据长度(可以是0 ~ 8),而不是发送的数据长度。

在数据帧和具有相同标识符的远程帧同时发送的情况下,由于数据帧标识符之后的 RTR 位是显性,它将赢得仲裁。

错误帧(ERROR FRAME)

  CAN 网络具有严格的错误诊断功能,该功能都是直接在 CAN 芯片中集成的,硬件直接处理整个过程。一旦错误被检测,正在传送的数据帧将会立即停止而待总线空闲时再次重发直至发送成功,该过程并不需要 CPU 的干涉除非错误累计该发送器退隐(Bus Off)。
  在发送或者接收报文时,总线上的节点如果检测出了错误,那么该节点就会发送 ERROR FRAME,以通知总线上的其他节点。ERROR FRAME 由 Error Flag 和 Error Del imiter 两个不同的位域组成。长度为 6 ~ 12个比特位的显性电平或者是隐性电平
Here Insert Picture Description

  • Error Flag: 是不同节点提供的错误标志(ERROR FLAG)的叠加。错误标志分为两种:
    • 主动错误标志(ACTIVE ERROR FLAG): 6 个比特位的显性电平,这将破坏“位填充”原则。由总线上错误状态为“主动错误”的出错的节点传送
    • 被动错误标志(PASSIVE ERROR FLAG): 6 个比特位的隐性电平,由总线上错误状态为“被动错误”的出错的节点传送
  • Error Delimiter: 是错误界定符。8 个比特位的隐性电平。在传输 ERROR FLAG 后,每个站先发送 1 个比特位的隐性电平,然后监视总线,直到它检测到隐性电平 之后它开始传输剩余 7 个比特位的隐性电平

  检测到错误状态的“错误激活”站通过传输 ACTIVE ERROR FLAG 来发出信号。 ERROR FLAG 的形式违反了从 START OF FRAME 到 CRC DELIMITER 应用于所有字段的位填充法(参见CODING)或破坏固定格式 ACK FIELD 或 END OF FRAME 字段。 结果,所有其他站检测到错误状况,并且他们也开始传输错误标记。 因此,实际上可以在总线上监视的“显性”比特序列是由各个站发送的不同ERROR FLAG的叠加产生的。 该序列的总长度在最小值6和最多12位之间变化。
  检测到错误条件的“错误被动”站试图通过传输被动错误标志来发出信号。 “错误被动”站从 PASSIVE ERROR FLAG 开始处等待六个相等极性的连续位。 当检测到这 6 个相等位时,PASSIVE ERROR FLAG 完成。

规范中第 6 个章节专门介绍错误处理
啥是被动错误?啥是主动错误?规范中第 7 个章节专门介绍错误界定!

过载帧(OVERLOAD FRAME)

  当某个节点快要忙死的时候,规范规定节点可以告诉其他节点,我要休息一会!方式就是发送过载帧,但是,过载帧不是你发就能发的。必须得注意时机。
  OVERLOAD FRAME 包含两个位字段 OVERLOAD FLAG 和 OVERLOAD DELIMITER。有两种过载条件可导致过载帧的传输:

  1. 接收器的内部条件,要求延迟下一个数据帧或远程帧。这种情况下只允许在预期的 INTERMISSION 的第一位时间开始发送过载帧
  2. INTERMISSION 期间检测到一个比特位的显性电平。在检测到显性位后一位开始发送过载帧。
      INTERMISSION 由 3 个比特位的隐性电平组成,只有在第 1 个比特位或者第 2 个比特位检测到显性电平,才允许从第三个比特位开始发送过载帧。如果在第 3 个比特位检测到“显性”电平,则其他节点将不会正确解释 OVERLOAD FLAG。而是将这6个“显性”位中的第一个比特位解释为 START OF FRAME。 第六个“显性”位违反了位填充规则导致错误条件

  由于存在多个节点同时过载且过载帧发送有时间差问题,可能出现过载标志叠加。最多可生成两个 OVERLOAD FRAME 以延迟下一个数据帧或远程帧
Here Insert Picture Description

  • OVERLOAD FLAG: 由 6 个比特位的显性电平组成。OVERLOAD FLAG 的所有形式和错误帧(ERROR FRAME)中主动错误标志的所有形式是一样的。
      由 6 个比特位的显性电平组成的 OVERLOAD FLAG 会破坏 INTERFRAME SPACING 中 INTERMISSION 字段的固定形式。 因此,所有其他站也会检测到 OVERLOAD 条件,并且开始传输过载标志。
  • OVERLOAD DELIMITER: 由 8 个比特位的隐性电平组成。OVERLOAD DELIMITER 与 ERROR DELIMITER 的格式相同。 在传输 OVERLOAD FLAG 后,该站监视总线,直到它检测到从“显性”位到“隐性”位的转换。 此时,每个总线站都已完成发送其 OVERLOAD FLAG,并且所有站都开始传输 7 个及以上的比特位的隐性电平

帧间间隔(INTERFRAME SPACING)

  DATA FRAME 和 REMOTE FRAME 与前面的帧(数据帧、远程帧、错误帧、过载帧)通过一个称为 INTERFRAME SPACING 的位字段分隔开。
Here Insert Picture Description
重载帧和错误帧之前没有 INTERFRAME SPACING,多个重载帧之间也没有 INTERFRAME SPACING。帧间隔过后,如果无节点发送帧,则总线进入空闲。

对于非“错误被动”或已接收上一条消息的站:
Here Insert Picture Description
对于已经传输上一条消息的“错误被动”的站:
Here Insert Picture Description

  • INTERMISSION: 3 个比特位的隐性电平。在 INTERMISSION 期间,不允许任何站发起 DATA FRAME 或 REMOTE FRAME 传输。 唯一可做的就是发出 OVERLOAD 条件。
  • BUS IDLE: 可以是任意长度个比特位的隐性电平。总线被认为是空闲的时候,任何有东西要传输的站都可以访问总线。如果在其他消息传输期间挂起了本消息,那么被挂起的消息必须在 INTERMISSION 的后一个比特位开始传输。总线上检测到的显性电平 的位可被解释为帧的起始。
  • SUSPEND TRANSMISSION: “错误被动”站发送消息后,在开始发送另一条消息或识别总线空闲之前,它会在中断后发送 8 个比特位的隐性电平。如果与此同时另一站开始发送消息(由另一站引起),则此站就作为这个消息的接收者。
    Here Insert Picture Description

接收器/发送器

TRANSMITTER: 发起消息的单元称为该消息的 “TRANSMITTER”。 设备保持 TRANSMITTER 直到总线空闲或设备丢失 ARBITRATION。
  如果在 END OF FRAME 结束之前没有错误,则该消息对发送器有效; 如果消息出现了错误,则将根据优先级自动执行重新传输。 为了能够与其他消息竞争总线访问,一旦总线空闲,就必须重新开始重传。
RECEIVER: 如果一个单元不是该消息的 TRANSMITTER 并且总线不空闲,则该单元被称为消息的 “RECEIVER”。
  如果在 END OF FRAME 的最后一位之前没有错误,则该消息对接收器有效。

参考

  1. 维基百科—— CAN BUS
  2. BOSCH CAN2.0 规范 Part A 部分
  3. https://blog.csdn.net/u012252959/article/details/83054474
Published 101 original articles · won praise 370 · views 530 000 +

Guess you like

Origin blog.csdn.net/ZCShouCSDN/article/details/90645548