|
|
CAN (Controller Area Network) is an advanced serial bus system that efficiently supports distributed control systems. It is internationally standardized by the International Standardization Organization (ISO) and Society of Automotive Engineers (SAE). Main CAN features:
Basic Concepts
There are two possible bus states - called "dominant" and "recessive". They are usually (but not always) equal to logic "Zero" and "One". Bus logic uses a "Wired-AND" mechanism, that is, "dominant" bits (zeros) overwrite the "recessive" bits (ones). Only if all nodes transmit recessive bits, the bus is in recessive state. If only one node transmit dominant bits it forces dominant bus state. That mechanism is used for arbitration.
The CAN protocol handles bus accesses according to the concept called "Carrier Sense Multiple Access with Arbitration on message priority". This arbitration concept avoids collisions of messages whose transmission was started by more than one node simultaneously and makes sure that most important message is sent first without time loss.
If two or more bus nodes start their transmission at the same time after having found the bus to be idle, collision of messages are avoided by bitwise arbitration. Each node sends the bits of its message identifier and monitors the bus level. When a dominant bit is being sent, the resulting bus state according to wired-AND principle is also dominant. Otherwise, if a recessive bit is being sent, the resulting bus state depends on what other nodes are sending in the same time. The recessive bus state means that there is no collision, the dominant state means that at least one node is sending dominant bit. When the node receives a dominant bit during sending a recessive one, it loses the arbitration and withdraws from the transmission. It means that messages with "Zeros" on higher bits (lower ID values) have higher priority.
Nodes that loses arbitration automatically try to repeat their transmission once the bus return to the idle state.
Frame Formats There are few frame formats existing:
The most important and composite is Data Frame which will be fully discussed. Other frames will be treated only briefly.
Remote Frame Generally data transmission is performed on an autonomous basis with the data source node (e.g a sensor) sending out a Data Frame. It is also possible, however, for a destination node to request the data from the source by sending a Remote Frame. If a node wishes to request the data from the source, it sends a Remote Frame with an identifier that matches the identifier of the required Data Frame. The appropriate data source node will then send a Data Frame as a response to this remote request. In Remote Frame RTR bit is sent as recessive so in the very unlikely event when two nodes are sending simultaneously a message with the same identifier (one as a Data Frame and second as a Remote Frame), the node sending Data Frame wins the arbitration and requested data is sent without any time loss. Remote Frame contains no data so Data Field doesn't exist. Error Frame An Error Frame is generated by any node that detects a bus error. That frame consists of two fields - an Error Flag field followed by an Error Delimiter field. The Error Delimiter consist of 8 recessive bits and allows the bus nodes to restart bus communications cleanly after an error. The form of the Error Flag field depends on the "error status" of the node that detects the error. If an "error active" node detects a bus error then the node interrupts transmission by sending Error Flag consist of 6 consecutive dominant bits that violates bit stuffing rule. All other stations recognize the resulting bit stuffing error and in turn generate Error Frames themselves. The Error Flag field therefore consists of between six and twelve consecutive dominant bits (generated by one or more nodes). The Error Delimiter field completes the Error Frame. After completion of the Error Frame bus activity returns to normal and the interrupted node attempts to resend the aborted message. If an "error passive" node detects a bus error then the node transmits an "passive Error Flag" followed, again, by the Error Delimiter field. The "passive Error Flag" consists of six consecutive recessive bits, and therefore the Error Frame (for an "error passive" node) consists of 14 recessive bits (i.e. no dominant bits). From this it follows that, unless the bus error is detected by the node that is actually transmitting (i.e. is the bus master), 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 resulting bit stuffing violation. Overload Frame An Overload Frame has the same format as an "active" Error Frame. An Overload Frame, however can only be generated during Interframe Space. This is the way than an Overload Frame can be differentiated from an Error Frame (an Error Frame is sent during transmission of a message). An Overload Frame can be generated by a node if due to internal conditions the node is not yet able to start reception of the next message. A node may generate a maximum of 2 sequential Overload Frames to delay the start of the next message. Interframe Space An Interframe Space separates a proceeding frame (of whatever type) from a following Data or Remote Frame. The Interframe Space is composed of at least 3 recessive bits, these bits are termed the Intermission. This time is provided to allow nodes time for internal processing before the start of the next message frame. After the Intermission, for error active CAN nodes the bus line remains in the recessive state (Bus Idle) until the next transmission starts. The Interframe Space has a slightly different format for an error passive CAN nodes which were the transmitter of the previous message. In this case, these nodes have to wait another eight recessive bits called Suspend Transmission before the bus turns into bus idle for them after Intermission and they are allowed to send again. Due to this mechanism error active nodes have the chance to transmit their messages before the error passive nodes are allowed to start transmission. Error Handling
The CAN protocol provides sophisticated error detection mechanisms discussed below. All detected errors are made public to all nodes via Error Frames. The transmission of the erroneous message is aborted and the frame is repeated as soon as possible. Moreover each node has it's own error counters (receive and transmit) that determine the error state of this node.
"Error active" state is the usual state after reset and is valid as long as both error counters are smaller than or equal to 127. "Error active" nodes can receive and transmit messages and transmit active Error Frames (made of dominant bits) without any restrictions.
"Error passive" state is reached when either error transmit or receive error counter is higher than 128. In this state message can still be received and transmitted but only passive error frame (made of recessive bits) can be generated. That provides that possibly damaged node won't disturb bus by continuously sending of Error Frames. When both error counters go below 128 again due to successful bus communication, the node switches back to the error-active state.
The "bus-off" state is entered if the transmit error counter exceeds the value of 255. All bus activities are stopped which makes it temporarily impossible for the station to participate in the bus communication. During this state, messages can be neither transmitted nor received. To return to the error active state and to reset the error counter values, the CAN node has to be reinitialized.
then a Form Error has occurred and an Error Frame is generated. The Message will then be repeated.
Bus synchronization and bit time
CAN handles message transfers synchronously. All nodes are synchronized at the beginning of each message with the first falling edge of frame which belongs to the Start of Frame bit - this is called "Hard Synchronization".
To ensure correct sampling up to the last bit, the CAN nodes need to resynchronize throughout the entire frame. This is done on each recessive to dominant edge. That is the reason why Bit Stuffing is being done.
One CAN bit time is specified as four non-overlapping time segments. Each segment is constructed from an integer multiple of the Time Quantum which is the smallest discrete timing resolution used by CAN node. Its length is generated by programmable divide of the CAN node's oscillator frequency.
The bit time, and therefore the bit rate, is selected by programming the width of the Time Quantum (TQ) and the number of TQ in the various segments. One bit time may be consist of 8 to 25 TQ.
As the result of resynchronization, Phase Buffer Segment 1 may be lengthened or Phase Buffer Segment 2 may be shortened to compensate for oscillator tolerances within the different CAN nodes. If, for example, the transmitter oscillator is slower than the receiver one, the next falling edge used for resynchronization may be delayed. So Phase Buffer Segment 1 is lengthened. The limit of the amount of lengthening or shortening of the phase buffer segments is set by the Resynchronization Jump Width. It may be between 1 and 4 Time Quanta, but it may not be longer than Phase Buffer Segment 2. For many CAN modules implementations, the Propagation Time Segment and Phase Buffer Segment 1 are combined, for ease of programming, into one segment often called Timing Segment 1. Phase Buffer Segment 2 is then known as Timing Segment 2.
The original specifications (Versions 1.0, 1.2 and 2.0A) specify an 11 bit message identifier. This is known as "Standard CAN". Those Data Frames and Remote Frames, which contain 11-bit identifier are therefore called Standard Frames. Up to 2048 different messages can be identified.
To remove this possible message number limitation specification V2.0A has since been update to version 2.0B. This version is referred to as "Extended CAN". Extended Frames contain a 29-bit identifier which allows over 536 Million message identifiers. The 29-bit identifier is made up of the 11-bit identifier ("Base ID") and the 18-bit Extended Identifier ("ID Extension")
CAN specification Version 2.0B still allows message identifier lengths of 11 bits to be used.
There are three different types of CAN modules available: |
Home
Site map
Contact Us


