CAN on the physical layer (Physical Bit transportation)
On the physical side, CAN data is send as Bits (woooaah, what news, eh?
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
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: Here just the logical parts of it, grouped and colored:
- 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.
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)