CAN bus ("Controller Area Network") is widely used in the automotive, aerospace, maritime, industrial and medical industries.

​Bus General

Microcontroller CAN Bus Pins (Pre CAN Transceiver)

High = recessive bus state (bus not driven), Low = dominant bus state (bus is driven by transceiver)

Multi Master serial bus.

TX and RX pins from the bus transceiver:

The CAN bus TX line (pre transceiver) idles high.

RX should exactly match TX when transmitting and it is analyzed by the CAN peripheral to see if another device on the bus is transmitting (Low) at the same time.  If you see RX low when TX isn't low then you have another device transmitting at the same time or if your TX pulses simply appear longer then you probably don't have correct bus termination.

Clocking

Uses a lossless bit-wise arbitration method of contention resolution which requires all nodes on the CAN network to be synchronized to sample every bit on the CAN network at the same time. This is why some call CAN synchronous, however it is in fact asynchronous as the data is transmitted without a clock signal.

As well as receivers all needing to always listen to the data on the CAN network, the transmitting node must also to so it can detect if its transmission is colliding with another node.

If a logical 1 is transmitted by all transmitting nodes at the same time a logical 1 is seen by all of the nodes, including both the transmitting node(s) and receiving node(s).

If a logical 0 is transmitted by all transmitting node(s) at the same time then a logical 0 is seen by all nodes.

If a logical 0 is being transmitted by one or more nodes, and a logical 1 is being transmitted by one or more nodes, then a logical 0 is seen by all nodes including the node(s) transmitting the logical 1.

When a node transmits a logical 1 but sees a logical 0, it realizes that there is a contention and it quits transmitting. By using this process, any node that transmits a logical 1 when another node transmits a logical 0 "drops out" or loses the arbitration. A node that loses arbitration re-queues its message for later transmission and the CAN frame bit-stream continues without error until only one node is left transmitting. This means that the node that transmits the first 1 loses arbitration. Since the 11 or 29 bit identifier is transmitted by all nodes at the start of a CAN frame, the node with the lowest identifier transmits more zero's at the start of the frame, and that is therefore the node that wins the arbitration or has the highest priority.

Data Size

Data section of frames is up to 8 bytes long.

Speed & Cable Lengths

25kbps to 1Mbps

50 kbps – max network length 1600m​ (max cable length)

100 kbps – max network length 500m​

500 kbps – max network length 100m

1 Mbps – max network length 40m

​Max cable stub length (i.e. connection from a node to the main daisy chained bus): 0.3m

Connectors

Connector types are not officially specified.

D9 connector is often used:

pin 2: CAN-
pin 3: GND
pin 7: CAN+
pin 9: CAN V+ (Power)

Termination

120ohm resistors are used at each end of the bus.

Maximum Number Of Nodes On The Bus

Dependant on a few factors such as cable specification, capacitance, speed, drivers, etc.

Electrically many of the drivers are rated at 120 nodes.

Engineers experienced with CAN bus often can't emphasize enough the importance of quality of wiring and connections/connectors with this have a direct effect on the maximum number of nodes.

Addressing

All messages on a CAN bus are broadcast with receiving nodes deciding if they want the data.  It is quite normal for more than one node to act on data passed over a CAN bus by another node.

The data and remote data frames use an identifier:

A standard frame has an 11 bit identifier in the arbitration field that allows up to 2048 unique messages on the BUS

An extended frame has a 29 bit identifier that allows up over 536 million unique messages on the BUS

If there are no errors with a message sent by a node all other nodes will “ack” the message by transmitting a dominant bit value onto the BUS while the Transmitting Node is listening.  This notifies the transmitter that at least one receiver validates the message.

Arbitration

CAN data transmission uses a lossless bit-wise arbitration method. There are "dominant" bits (logical 0 – actively driven to a voltage by the transmitter) and "recessive" bits (logical 1 – passively returned to a voltage by a resistor). The idle state is the recessive level (Logical 1). If one node transmits a dominant bit and another node transmits a recessive bit then there is a collision and the dominant bit "wins". There is no delay to the higher-priority message, and the node transmitting the lower priority message backs off and will automatically attempts to re-transmit six bit clocks after the end of the dominant message. This makes CAN very suitable as a real time prioritized communications system.

For example, consider an 11-bit ID CAN network, with two nodes with IDs of 15 (binary representation, 00000001111) and 16 (binary representation, 00000010000). If these two nodes transmit at the same time, when the 8th bit is transmitted the node with the ID of 15 transmits a 0 (dominant) for its ID. When this happens, the node with the ID of 16 knows it transmitted a 1, but sees a 0 and realizes that there is a collision and it lost arbitration. Node 16 stops transmitting which allows the node with ID of 15 to continue its transmission without any loss of data. The node with the lowest ID will always win the arbitration, and therefore has the highest priority.

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.