CAN Communication Protocol
CAN Communication Protocol
Agenda
• Communication Basics
• In-Vehicle communication
• CAN Protocol 2.0B
• CAN Physical
• CAN inside a Microcontroller
• Exercises and Projects
Introduction
Communication:
Sharing information between two or more bodies
Basic elements
• Transmitter, Speaker, Publisher, Receiver, Audience, Subscribers, etc. (User
wants to Say info and User want to listen Info)
• Message/Information(Type of Information)
• Medium/Channel
• And ???
RULES!!!
Cont..
Communication network:
• Way/method of information flow within the group of bodies participating
in exchange of information
Why Rules???
• Understandable
• Clarity
• Correctness
• Completeness
Addressing
• Destination dependent
• MAC addressing(Ethernet)
• Slave address (I2C, SPI, USB, UART)
Topologies
• Star
• Bus
• Ring, etc..
• Grouping/Packet/Packing/Parsing
Open Systems Interconnection – Communication model
Communication Protocols
(Common for In-Vehicle communication)
❑ CAN
❑ Flexray
❑ LIN
❑ Ethernet
❑ MOST
and so on…
CAN Protocol
• The CAN bus was developed by BOSCH as a multi-master, message broadcast system that
specifies a maximum signaling rate of 1 megabit per second (bps).
• In a CAN network, many short messages like temperature or RPM are broadcast to the
entire network, which provides for data consistency in every node of the system.
Low cost: Since a CAN serial bus uses two wires (with high-volume and low-cost production), it
offers a good price-to-performance ratio.
Reliable: CAN offers excellent error-detection and error-handling mechanisms, which provides
highly reliable transmission. It’s also largely immune to electromagnetic interference.
Flexible: CAN nodes are not limited by the protocol and can be easily connected or
disconnected.
Fast: CAN supports a data rate of 1 MBit/s @ 40m bus length.
Multi-master communication: Any node can access the bus
Fault confinement: Faulty nodes do not disturb the communication.
Broadcast capabilities: Messages can be sent to one /many/all nodes.
Standardized: ISO has standardized the CAN protocol via ISO-DIS 11898 (for high-speed
applications) and ISO-DIS 11519-2 (for low-speed applications). The CAN protocol is also
standardized by industry organizations, such as the SAE-Society of Automotive Engineers.
Terminologies
Message:
Set of Information to be transferred over the CAN bus.
Along with information, important Protocol supporting elements are also
necessary
Terminologies
Arbitration: ???
• IDENTIFIER – It serves dual purpose one, to determine which node has access to the bus and
second to identify the type of message.
• RTR – Remote Transmission Request. It identifies whether it’s a data frame or a remote frame
.RTR is dominant when it is a data frame and recessive when it is a remote frame.
• IDE – Identifier Extension. It is used to specify the frame format. Dominant bit is for standard
frame and recessive for extended frame.
• R0 – Reversed bit. Not used currently and kept for future use.
• DLC – Data Length Code. It is 4 bit data length code that contains the number of bytes being
transmitted.
CAN Protocol: Standard Frame fields continue …
• DATA– Used to store up to 64 data bits of application data to be transmitted.
• CRC– Cyclic Redundancy Check. The 16-bit (15 bits plus delimiter) cyclic redundancy check
(CRC) contains the checksum of the preceding application data for error detection.
• ACK – Acknowledge (ACK) field. It compromises of the ACK slot and the ACK delimiter.
When the data is received correctly the recessive bit in ACK slot is overwritten as dominant bit
by the receiver.
• EOF– End of Frame (EOF). The 7-bit field marks the end of a CAN frame (message) and
disables Bit – stuffing, indicating a stuffing error when dominant.
• IFS – Inter Frame Space that specifies minimum number of bits separating consecutive
messages. It provides the intermission between two frames and consists of three recessive
bits known as intermission bits. This time allows nodes for internal processing before the start
of next frame.
CAN Protocol: Extended Frame fields
CAN Protocol: Extended Frame fields
• It is same as 11-bit identifier with some added fields
• SRR- Substitute Reverse Request. The SRR bit is always transmitted as a recessive bit to ensure
that, in the case of arbitration between a Standard Data Frame and an Extended Data Frame, the
Standard Data Frame will always have priority if both messages have the same base (11 bit)
identifier.
• R1- It is another bit not used currently and kept for future use.
Data Length Code
Frame Types
- Based on purpose of frame:
- Data frame: a frame containing node data for transmission
- Remote frame: a frame requesting the transmission of a specific identifier
- Error frame: a frame transmitted by any node detecting an error
- Overload frame: a frame to inject a delay between data or remote frame
The CAN standard requires that the implementation must accept the base frame format and
may accept the extended frame format, but must tolerate the extended frame format.
CAN Protocol: 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.
There are two differences between a data frame and a remote frame. Firstly the RTR-bit is
transmitted as a dominant bit in the data frame and secondly in the remote frame there is no
data field. The DLC field indicates the data length of the requested message (not the
transmitted one).
In the event of a data frame and a remote frame with the same identifier being transmitted at
the same time, the data frame wins arbitration due to the dominant RTR bit following the
identifier.
CAN Protocol: ERROR Frame
The error frame consists of two different fields:
The first field is given by the superposition of ERROR FLAGS (6–12 dominant/recessive bits)
contributed from different stations.
The following second field is the ERROR DELIMITER (8 recessive bits).
There are two types of error flags:
Active Error Flag : six dominant bits – Transmitted by a node detecting an error on the network
that is in error state "error active".
Passive Error Flag : six recessive bits – Transmitted by a node detecting an active error frame on
the network that is in error state "error passive".
There are two error counters in CAN:
Transmit error counter (TEC) and Receive error counter (REC)
When TEC or REC is greater than 127 and less than 255, a Passive Error frame will be
transmitted on the bus.
When TEC and REC is less than 128, an Active Error frame will be transmitted on the bus.
When TEC is greater than 255, then the node enters into Bus Off state, where no frames will be
transmitted.
CAN Protocol: OVERLOAD Frame
The overload frame contains the two bit fields Overload Flag and Overload Delimiter. There are
two kinds of overload conditions that can lead to the transmission of an overload flag:
The internal conditions of a receiver, which requires a delay of the next data frame or remote
frame.
Detection of a dominant bit during intermission.
The start of an overload frame due to case 1 is only allowed to be started at the first bit time of
an expected intermission, whereas overload frames due to case 2 start one bit after detecting
the dominant bit. Overload Flag consists of six dominant bits. The overall form corresponds to
that of the active error flag.
The overload flag's form destroys the fixed form of the intermission field. As a consequence, all
other stations also detect an overload condition and on their part start transmission of an
overload flag. Overload Delimiter consists of eight recessive bits. The overload delimiter is of
the same form as the error delimiter.
Important Points to be known in CAN Arch
- Acceptance filtering
- Arbitration
- Encapsulation / Decapsulation
- Bit stuffing
- Serialization/ De-Serialization
- Ack
- Error types
Acceptance filtering:
Basic CAN: Basic CAN has only one Message buffer for Receive and Transmit messages. The
received message is accepted or ignored after acceptance filtering. The decision to process a
message or to ignore it is also achieved by acceptance filtering. This acceptance filtering of the
node is done by software in Basic CAN. To reduce the software load at the nodes, there is a
possibility to ignore some messages by ignoring specific identifiers. This is realized by bit mask
for the message identifiers.
Full CAN: In Full CAN, there are 8 to 16 memory buffers for every transmitted or received
message. Here the acceptance filtering is done by hardware and not by the software. Every
buffer can be configured to accept messages with specific ID’s.
Since the acceptance filtering is done by hardware, the software load is greatly reduced. With
different buffers for different messages ensures more time for the processing of the received
messages and the transmitted message can be handled according to the priority levels.
Configuring each buffer for every message ensures also the data consistency in Full CAN
Arbitration:
• It is a mechanism which resolves the conflict when two or more nodes try to send the
message at the same time.
• In this technique whenever the bus is free any unit can transmit a message. If two or more
units starts transmitting at the same time access to the bus is conflicted, but this problem can
be solved by arbitration using identifier.
• During arbitration every transmitter compares the value of transmitted bit with bit value on
the bus. If the bit value is same, the node continues to send the bits. But at any time if
transmitted bit value is different from bus value the dominant bit overwrites the recessive
bits.
• The arbitration field of the CAN message consists of an 11- or 29-bit identifier and a remote
transmission (RTR) bit. The identifier having lowest numerical value has the highest priority.
• RTR simply distinguishes between remote frame for which RTR is recessive and data frame for
which RTR is dominant. If both data frame and remote frame with the same identifier is
initiated at the same time data frame will prevail over remote frame.
• With the concept of arbitration neither information nor time is lost.
Error Types:
- CRC Error
- Form error
- Ack Error
- Bit Error
- Stuff Error
Error types continue …
CRC error: In this stage a 15-bit cyclic redundancy check value is calculated by transmitting
node and is transmitted in the CRC field. This value is received by all nodes. Then all the nodes
calculate CRC value and matches the results with the transmitted value. If values differ than an
Error Frame is generated. Since one of the nodes did not receive the message properly it is
resent.
ACK error: When transmitting node sends a
message, a recessive bit is sent in
acknowledgement slot. After message is
Form error: End of frame, Inter-frame space, received acknowledge slot is replaced by
Acknowledge Delimiter are fields that are dominant bit which would acknowledge that at
always recessive, if any node detects least one node correctly received the message. If
dominant bit in one of these fields than CAN this bit is recessive, then none of the node has
protocol calls it a violation and a Form Frame received the message properly.
is generated and original message is resent
after certain period.
Error types continue …
Bit error: A node that is sending the bit always monitors the bus. If the bit sent by transmitter
differs from the bit value on the bus then error frame is generated. But there is an exception in
case of arbitration field or Acknowledge slot where a recessive bit is sent and a dominant bit is
received. Then no Bit Error is occurs when dominant bit is monitored.
Stuff error: Bit stuffing – It is a very common technique used in telecommunication and data
transmission to insert non -informative bits to have same bit rates or to fill the frames .These
extra bits are removed by data link layer to retrieve the original message. This same technique
is used in bit error. CAN bus is never idle because it uses NRZ method. After five consecutive
bits of the same value, a bit with a complement or opposite value is stuffed into the bit stream.
If six bits of the same value are detected between SOF and CRC delimiter, error frame is
generated. Upon detection of errors, the transmission is aborted and frame is repeated. If
errors continue, then the station or node may switch itself off to prevent the bus from being
tied up
CAN HW implementation
CAN Physical : Voltage levels
CAN Physical : Voltage levels
Normal
CAN Physical : Voltage levels
Bit Timing
CAN Physical : Transceiver
A properly configured bus looks like this diagram:
References:
• ISO11898
• ISO7498 -1