Datasheet

Copyright © 2013 ARM Ltd. All rights reserved
CAN: Controller Area Network Lab using ST STM32 Cortex-M processors. www.keil.com
6
The CAN Frame:
The CAN frame has many fields but we can simplify this to a Programming Model as shown. These fields are accessed by
your software through the CAN controller registers. The
configuration registers are not included here.
IDE: Identifier Extension: 1 bit - specifies if the ID
field to be transmitted is 11 or 29 bits:
If IDE = 0, then the ID is 11 bits.
If IDE = 1, then the ID is 29 bits.
ID: Identifier: 11 or 29 bits as set by the IDE field.
This part of the CAN frame sets the priority.
DLC: Data Length Code: 4 bits - specifies number of
data bytes in the frame from 0 through 8.
Data Bytes: 0 through 8 bytes.
TIP: A CAN frame with an ID field of either 11 or 29 bits and with zero data bytes is valid and useful.
TIP: You tell the transmitter size of ID and number of data bytes. The receiver tells you these values when it gets a frame.
ID: Identifier: 11 or 29 bits
The Identifier can be used for any purpose. It is often used as a node address or to identify requests and responses. CAN
does not specify any mandatory ID values. 11 bit is often called Standard CAN and 29 bit is often called Extended CAN.
1. If two or more CAN messages are put on the bus at the same time; the one with the highest priority (the lowest
value) ID will immediately get through. The others will be delayed and will be resent at the next bus idle time.
2. An ID of 0 has the highest priority and will always get through. When the first 11 bits of an 11 and 29 bit ID are the
same, the 11 bit ID has priority over the 29 bit ID. This is because the IDE bit = 0 for 11 bits and wins arbitration.
3. You can have any mixture of 11 and 29 bit IDs on the bus. The controller can easily sort this out.
4. Messages tend to start transmitting at the same time. A CAN node is not allowed to start transmitting a frame in the
middle of another node’s frame. This will cause a bus error. Can controllers will not make this mistake.
5. CAN controllers can be configured to pass only certain received messages to its host processor. Choose your ID
values carefully to take advantage of this if needed. This will reduce the workload of a node’s CPU.
This is why some systems use 29 bit IDs even though they do not need that many addresses. This facilitates
grouping of IDs for easier filtering since acceptance filters usually do not usually have a very fine granularity.
6. You can use the ID for data, node addressing, commands and request/response sequences. Commercial protocols
use any of these in practice. You can create your own method if that best suits your purpose.
TIP: Make sure two nodes will never send the same ID value at the same time. It is illegal but possible to do this. If two
messages sent at the same time are completely identical, they will be seen on the bus as one. If the data bytes are different, a
bus error will result and the frames will be resent continuously and havoc is created on the bus for a short time until a bus-off.
Data Bytes:
You can select from 0 to 8 data bytes using the 4 bit DLC field. A valid DLC is returned when a frame is received.
1. You can have any number of data bytes in frames on the CAN bus. The controller can easily sort this out.
2. If you always use only one number of data bytes, your software will be much simpler to write and debug.
3. The data bytes can contain anything. It is not prioritized like the ID is. CAN does not specify mandatory data.
4. Protocols such as J1939 specify these for data as well as control bits for multi-frame transmission schemes.
Remote Frames:
These are not used much anymore but are worth mentioning. A remote frame is a quick method of getting a response from
another node(s). It is a request for data. The requesting node sends out a shortened CAN frame with only a user specified ID
number and the number of data bytes it expects to receive (the DLC is set). No data field is sent. The responding node(s)
sees this frame, recognizes that it has the desired information and sends back a standard CAN frame with the same ID, DLC
and with data bytes attached. All of this (except that the response node recognizes the ID and DLC) is implemented in the
CAN controller hardware. Everything else must be configured by the user software.
IDE (1 bit)
11 bit ID if IDE = 0
29 bit ID if IDE = 1
DLC (4 bits)
Data Bytes: 0, 1, 2, 3, 4, 5, 6, 7 or 8 bytes (up to 64 bits)
DLC = 0 through 8 and specifies # of data bytes
CAN Frame Programming Model