Datasheet

Copyright © 2013 ARM Ltd. All rights reserved
CAN: Controller Area Network Lab using ST STM32 Cortex-M processors. www.keil.com
11
Sequence of Receiving data from the CAN Bus:
1. All nodes except those currently transmitting frames and those in bus-off mode are in listening mode.
2. A CAN frame is sent using the procedure as described previously:
Sequence of Transmitting Data on the CAN Bus:
3. This sent frame is received by all listening nodes. If deemed to be a valid CAN message with no errors – the ACK
bit is set by all listeners. In CAN terminology, this set to the “dominant” state as opposed to the recessive state.
4. The frame is sent through the controller’s acceptance filter mechanism if it is enabled. If this frame is rejected: it is
discarded. If accepted, it is sent to the controller FIFO memory. If the FIFO is full, the oldest frame is lost.
5. The host processor is alerted to the fact a valid frame is ready to be read from the FIFO. This is done either by an
interrupt or a bit set in a controller register. This frame must be read as soon as possible.
6. You do not tell the receiver what the ID size is or the number of data bytes to be received. When the receiver gets a
valid frame, it deciphers this information and provides you with the appropriate IDE and DLC register values.
7. The host processor decides what to do with this message as determined by your software.
TIP: You must decide whether to use polling or interrupts to alert the host processor a frame is available. Polling is where
the host processor “polls” or continuously tests the bit mentioned in # 5. Polling runs the risk of losing or “dropping” a frame
but is sometimes easier to implement and debug. Using interrupts is the recommended method and causes the CPU to jump
to a handler to read the frame from the controller. Make sure your processor can handle 100% bus load bursts.
Receiving Notes:
1. What happens if a message is “dropped” ?
This can cause some problems as CAN itself does not have a mechanism for acknowledging a CAN frame. If you
want this, you must add it to your software. In the case of Periodic Messages, it doesn’t normally matter much as a
replacement message will be along shortly. This appears to be designed into CAN to handle dropped messages.
2. How fast do I have to read the FIFO to not drop messages ?
It depends on the CAN speed, frame size, and bus loading. It is a good idea to read these frames as soon as possible
since once a frame is dropped, it cannot be recovered or automatically resent by the transmitting node. It is gone
forever unless you provide a suitable mechanism in your software to have it resent.
It is possible to have a burst of CAN traffic approaching 100% bus loading when the controller dumps all its data on
the bus. Your system must be prepared for this event. The CAN specification does not space out frames.
3. How do the CAN controllers stay in sync when there is only the bus idle voltage (0) and no transistions:
The CAN controller depends on its internal clock to stay as close to the design frequency as possible. Upon receipt
of the start bit, an internal counter starts counting the “time quanta” (TQ) that further divide the bit time. The
number of TQs in a bit period is set in the controller by the user. The controller will automatically add or subtract
TQs to adjust its effective operation frequency.
CAN bit time transitions are used to calculate the correct number of TQs needed to keep the receivers in sync.
See the data sheet for your CAN controller for details.
4. I have a high bus loading factor. How can I reduce the pressure on my CAN controller ?
There are many ways and here are several:
Use the acceptance filters to ignore any messages your processor does not need. Ignored messages will
never be sent to the processor. They are discarded very quickly by the CAN controller.
Use more than one CAN controller in your processor to receive CAN frames. Set the acceptance filters to
divide the messages by ID (or even 1
st
data byte) to each of the controllers. Your processor must still have
the ability to process the messages. For transmit: use mailboxes to alternatively transmit the CAN frames.
Space the messages sent by the nodes.
Use sub-nodes. Sometimes using a different protocol than CAN is appropriate.
Use a faster ARM processor or increase the bus speed if practical. Or use a combination of these tactics.
5. Where do I get the values for the timing registers BTR0 and BTR1 ?
The controller data sheet will provide the formulae to configure these timing registers. Suggested values for various
bus frequencies are usually provided. It is especially important to get the sampling point correctly set.