Controller Area Network(CAN) is a serial communication protocol that employs the usage of two differential lines as its bus. It has a shared bus, like I2C, meaning there is no true master.
Each CAN node has an ID. Whenever a node wants to transmit data, it starts by transmitting their ID. The node with a lower ID "wins" the arbitration. A node can read back the data it transmits, and if a node transmits and reads back its ID, it knows that it now has control of the bus and can transmit data.
There are two lines used here, they are -
The CAN lines are twisted together (to reduce EM interference) and also connected with a resistor to reduce reflections. The default idle state is the difference between CANH and CANL being close to 0 (recessive).
Each CAN signal (or dataframe) has 64 bits. A dataframe has this structure -
The can-utils metapackage comes with tools like cansend
and candump
. cansend <id>#<data>
can be used to send data onto the bus with a specified CAN ID. candump -x any
dumps data from the CAN bus which was sent by any of the nodes on the bus.
An example message being sent