CAN communication basics

Everything regarding communication-protocols like CAN, OBD, LIN, JTAG, BDM, I2C, SPI, ...
Post Reply
Go4IT
Pro
Posts: 967
Joined: 08 Feb 2019, 12:25

CAN communication basics

Post by Go4IT »

In this article i will describe and discuss some basic CAN communications. There are sooo many ISO standards and details, but i try to not to go into deep, because there are enough learning ressources on the Web and i will cover only basics. So here i talk about the most basic one, the so called "High speed" CAN-Bus with "Standard Frames". "High speed" and "Low speed" CAN differs on the voltage levels used, so don't mix up with transmition speeds like 125 or 500 kbaud.
b1549218978.43532.png
CAN on the physical layer (Physical Bit transportation)

On the physical side, CAN data is send as Bits (woooaah, what news, eh? :D). Each logical bit (0, 1) is transformed into a voltage level and vice versa. To make transmition robust against electrical yams and jitter two wires are use with differential signals, named "CAN_H" and "CAN_L" (both measured against GND!). A logical "0" is represented as 2,5V on both wires, a logical "1" as 3,5V on CAN_H and 1,5V on CAN_L. Here an diagram how the CAN wires behave in relation of the Bits to transfer:
can-bus_levels.png
Multiple CAN modules built a single bus by connecting their CAN_H and CAN_L wires in parallel. For electrical reasons the bus has to be "terminated" with an 120 Ohm resistor between those wires on both ends. This builds a bus this way:
can-bus.png
A logical "0" is also called "dominant" and "1" "recessive". This is to handle collosions on the bus. A logical "1" is equal to the silence level of the bus, only a logical 0 can be determined. So if a sender is sending a "1" he does in fact not changing any levels, only a "0" changes them. In the case of collissions (one node sends 1 and the other 0), the one sending 0 "wins". The other node will detect this collission because he received every bit he sends and if they don't match he knows there is something wrong. In this case the sender will pause for a short time and restart transmittion. Also senders do not start if they "hear" transmition on the bus, to not interrupt it.

This collision avoidence and resolve schema is called "CSMA/CA", which means:
"CS" = "Carrier Sense" = Each node monitors the CAN Bis all the time, for forgein and own transmissions.
"MA" = "Multiple Access" = Nodes can send at any time, when bus is free
"CA" = "Collision Avoidance" = If several nodes start sending at the same time, all but one stops sending. So at leat one transmission is done, the one with the highest priority (=lowest CAN ID)

On the logical side it uses NRZ (non-return-to-zero) bitstreams, whereas on the physicsl side it makes use of stuff-bits to detect bus errors.

CAN on the logical layer (Message frames)

Now that we can send and receive Bits over the bus, we come up to the next layer where we form messages (frames). In short the standard frame message (CAN 2.0A) format is this:
can_frame.png
Here just the logical parts of it, grouped and colored:
can_frame_logical.jpg
  • You can see that each frame starts with a dominant "0" (SOF = Start-Of-Frame), and if you have read and understood the above section you know why :-)
  • Next is the ID of the message (orange block). The ID is related to the sender (node) of the network (bus) and may not emitted by more than one sender. The ID is 11 Bits in size, so the ID-range is from 0x000 up to 0x7FF. Like on other networks, the highest and lowest possible ID is never used, only inbetween, which reduces the available space to 0x001 - 0x7FE. On the nature of dominant and recessive levels, the lower the ID the more likely it will "win" when other nodes try to send at the same time. This is why the ID is also the priority of the message.
  • In the "green" section you find the DLC (Data length code) which tells about the number of payload bytes follows. The DLC is 4 Bit in size and can therefore indicate 1-8 bytes (value 0x1 to 0x7). As Zero-Length message is not provided in the standard.
  • The deep purple group is symbolic for at least one payload Byte.
  • The blue group contains the CRC and CRC delimiter. It is used for receivers to check if all bits in the frame are received correctly.
  • The yellow bit is used for the sender to determine if any node has received his message and so to detect bus isolation. The sender keeps this bit set to "1" (recessive). If another node receives the last CRC bit, he sends an dominant "0" to indicate full reciveal of the frame. The sender detects this and can tell the controller "the message has successfully received by one of the other nodes". Otherwise it try to retransmitt the frame.
  • The light purple "End of frame" bits are just like a pause to give others time to gain access to the bus.
For many applications, this is all it needs to communicate! Most CAN messages on the Ford CAN-busses are this way, just plain and simple.

Besides the often used "Message Frame", there are also some others, which i list here for completeness: "Remote Frame", "Overload Frame", "Error Frame".


Message segmentation and transport

If a sender needs to transfer more than 8 bytes on a single ID, it mostly uses ID-multiplexing by using the first byte of the payload as an index.

Besides of ID-multiplexing, there are also ISO standards for transmitting large data, e.g. a firmware or a car configuration setup.



Application (OSI Layer 7)
You do not have the required permissions to view the files attached to this post.
Post Reply