CAN (Controlled Area Network) Protocol:
The CAN communication protocol is a carrier-sense, multiple-access protocol with collision detection and arbitration on message priority (CSMA/CD+AMP). CSMA means that each node on a bus must wait for a prescribed period of inactivity before attempting to send a message. CD+AMP means that collisions are resolved through a bit-wise arbitration, based on a preprogrammed priority of each message in the identifier field of a message. The higher priority identifier always wins bus access.
CAN has two formats
1.standard 11-bit identifier, provides for signaling rates from 125 kbps to 1 Mbps
- The standard 11-bit identifier field in provides for 211, or 2048 different message identifiers
- The standard was later amended with the “extended” 29-bit identifier .
- the extended 29-bit identifier provides for 229, or 537 million identifiers.
The Bit Fields of Standard CAN and Extended CAN
Standard CAN :
SOF– The single dominant start of frame (SOF) bit marks the start of a message, and is used to synchronize the nodes on a bus after being idle.
Identifier-The Standard CAN 11-bit identifier establishes the priority of the message. The lower thebinary value, the higher its priority.
RTR– The single remote transmission request (RTR) bit is dominant when information is required from another node. All nodes receive the request, but the identifier determines the specified node. The responding data is also received by all nodes and used by any node interested. In this way, all data being used in a system is uniform.
IDE– A dominant single identifier extension (IDE) bit means that a standard CAN identifier with noextension is being transmitted.
r0– Reserved bit (for possible use by future standard amendment).
DLC– The 4-bit data length code (DLC) contains the number of bytes of data being transmitted.
Data– Up to 64 bits of application data may be transmitted.
CRC– The 16-bit (15 bits plus delimiter) cyclic redundancy check (CRC) contains the checksum(number of bits transmitted) of the preceding application data for error detection.
ACK– Every node receiving an accurate message overwrites this recessive bit in the original message with a dominate bit, indicating an error-free message has been sent. Should a receiving node detect an error and leave this bit recessive, it discards the message and the sending node repeats the message after rearbitration. In this way, each node acknowledges (ACK) the integrity of its data. ACK is 2 bits, one is the acknowledgment bit and the second is a delimiter.
EOF– This end-of-frame (EOF), 7-bit field marks the end of a CAN frame (message) and disablesbit-stuffing, indicating a stuffing error when dominant. When 5 bits of the same logic level occur insuccession during normal operation, a bit of the opposite logic level is stuffed into the data.
IFS– This 7-bit interframe space (IFS) contains the time required by the controller to move a correctly
received frame to its proper position in a message buffer area.
Extended CAN :
SRR– The substitute remote request (SRR) bit replaces the RTR bit in the standard message location as a placeholder in the extended format.
IDE– A recessive bit in the identifier extension (IDE) indicates that more identifier bits follow. The 18-bit extension
r1– Following the RTR and r0 bits, an additional reserve bit has been included ahead of the DLC bit.
If two nodes try to occupy the bus simultaneously, access is implemented with a nondestructive, bit-wise arbitration. Nondestructive means that the node winning arbitration just continues on with the message, without the message being destroyed or corrupted by another node. The allocation of priority to messages in the identifier is a feature of CAN that makes it particularly attractive for use within a real-time control environment. The lower the binary message identifier number, the higher its priority. An identifier consisting entirely of zeros is the highest priority message on a network because it holds the bus dominant the longest. Therefore, if two nodes begin to transmit simultaneously, the node that sends a last identifier bit as a zero (dominant) while the other nodes send a one (recessive) retains control of the CAN bus and goes on to complete its message. A dominant bit always overwrites a recessive bit on a CAN bus.
The four different message types, or frames that can be transmitted on a CAN bus
The data frame is the most common message type, and comprises the Arbitration Field, the Data Field, the CRC Field, and the Acknowledgment Field. The Arbitration Field contains an 11-bit identifier and the RTR bit, which is
dominant for data frames, in Extended Frame it contains the 29-bit identifier and the RTR bit. Next is the Data Field which contains zero to eight bytes of data, and the CRC Field which contains the 16-bit checksum used for error
detection. Last is the Acknowledgment Field.
The intended purpose of the remote frame is to solicit the transmission of data from another node. The remote frame is similar to the data frame, with two important differences. First, this type of message is explicitly marked as a remote frame by a recessive RTR bit in the arbitration field, and secondly, there is no data.
The error frame is a special message that violates the formatting rules of a CAN message. It is transmitted when a node detects an error in a message, and causes all other nodes in the network to send an error frame as well. The original transmitter then automatically retransmits the message. An elaborate system of error counters in the CAN controller ensures that a node cannot tie up a bus by repeatedly transmitting error frames.
The overload frame is mentioned for completeness. It is similar to the error frame with regard to the format, and it is transmitted by a node that becomes too busy. It is primarily used to provide for an extra delay between messages.
There are five error conditions that are defined in the CAN protocol
A 15-bit Cyclic Redundancy Check (CRC) value is calculated by the transmitting node and this 15-bit value is transmitted in the CRC field. All nodes on the network receive this message, calculate a CRC and verify that the CRC values match. If the values do not match, a CRC error occurs and an Error Frame is generated. Since at least one node did not properly receive the message, it is then resent after a proper intermission time.
In the Acknowledge Field of a message, the transmitting node checks if the Acknowledge Slot (which it has sent as a
recessive bit) contains a dominant bit. This dominant bit would acknowledge that at least one node correctly received the message. If this bit is recessive, then no node received the message properly. An Acknowledge Error has occurred. An Error Frame is then generated and the original message will be repeated after a proper intermission time.
If any node detects a dominant bit in one of the following four segments of the message: End of Frame, Interframe Space, Acknowledge Delimiter or CRC Delimiter, the CAN protocol defines this to be a form violation and a Form
Error is generated. The original message is then resent after a proper intermission time. (see Figure 2 and/or Figure 3 for where these segments lie in a CAN message).
A Bit Error occurs if a transmitter sends a dominant bit and detects a recessive bit, or if it sends a recessive bit and
detects a dominant bit when monitoring the actual bus level and comparing it to the bit that it has just sent. In the case where the transmitter sends a recessive bit and a dominant bit is detected during the Arbitration Field or Acknowledge Slot, no Bit Error is generated because normal arbitration or acknowledgment is occurring. If a Bit Error is detected, an Error Frame is generated and the original message is resent after a proper intermission time.
CAN protocol uses a Non-Return–to-Zero (NRZ) transmission method. This means that the bit level is placed on the bus for the entire bit time. CAN is also asynchronous, and bit stuffing is used to allow receiving nodes to synchronize by recovering clock information from the data stream. Receiving nodes synchronize on recessive to dominant transitions. If there are more than five bits of the same polarity in a row, CAN will automatically stuff an opposite polarit y bit in the data stream. The receiving node(s) will use it for synchronization, but will ignore the stuff bit for data purposes. If, between the Start of Frame and the CRC Delimiter, six consecutive bits with the same polarity are detected, then the bit stuffing rule has been violated. A Stuff Error then occurs, an Error Frame is sent, and the message is repeated.
Key Attributes :
- Multimaster priority-based serial communications protocol supporting distributed real-time control and multiplexing using non-destructive contention-based arbitration
- Bit rates: 1 Mbit/s (with 40m bus), 100 kbit/s (with 500m bus)
- Encoding: non return to zero (NRZ)
- Message length: 0 to 8 bytes
- Classes of service: periodic and sporadic
- Media access: carrier sense multiple access with collision avoidance (CSMA/CA)
- Topology: terminated differential two wire bus
- Media: screened or unscreened twisted pair or flat pair telephone cable