Datasheet
Copyright © 2013 ARM Ltd. All rights reserved
CAN: Controller Area Network Lab using ST STM32 Cortex-M processors. www.keil.com
29
TIP: If you have more than one CAN controller in your processor you can operate these as parallel receivers. Divide the
messages up with the Acceptance Filters. This will help capture all the messages on a very busy bus minimizing or
eliminating data frame losses. Each CAN controller will handle its share of the messages. This effectively multiplies the
number of FIFO buffer memories which is an excellent method of capturing all the CAN frames
How to determine the frequency of a CAN signal:
This is the best and sometimes only way to determine this.
1. Connect an oscilloscope to CAN Hi or CAN Lo and ground. You do not need a high speed scope – almost any will
suffice. You can also connect a scope to the CAN controller Tx output pin and ground for a very clean signal.
2. Display a trace. You might need a storage scope to see just one trace due to the non-repetitive nature of CAN.
3. Pick the smallest width signal pulse and measure its time period in seconds as accurately as you can.
4. Invert this value (divide into 1) and you have the CAN speed in bits per second. i.e. 2 µsec = 500 Kbps.
Four Newbie CAN Mistakes you can avoid:
1. You need at least two CAN nodes in order to get past the first initial message. This is a very common mistake.
2. There is a bug in CAN that was turned into a feature. What happens is some noise on the bus causes a transmitter to
think its first message was corrupted and it sends out a copy. However, the other nodes think the first message was
valid and accept it and also the second copy. Therefore, they see two identical and valid messages. Therefore do
not increment or toggle values or states. Send the actual value you want to nodes to receive. This situation occurs
rarely but with millions of CAN frames and millions of networks, it does happen and it can be a problem.
3. The CAN controller will add (or not) a bit to the bitstream to ensure there are never more than five unchanging bits.
This changes the CAN message length. When such messages are viewed on an oscilloscope – they look like jitter.
It is not: this is how CAN works. Do not chase problems in your network on a false assumption you have jitter.
4. Avoid doing tricky and complicated things like changing the CAN frequency. Just keep it simple and stable.
5. One more tip just for luck: Do not try and design your own CAN controller. There are secrets that will stop you.
Useful Documents:
1. The Definitive Guide to the ARM Cortex-M3 by Joseph Yiu. (he has one for the Cortex-M0) Search the web.
2. MDK-ARM Compiler Optimizations: Appnote 202: www.keil.com/appnotes/files/apnt202.pdf
3. Lazy Stacking and Context Switching Appnote 298: www.arm.com and search for 298
4. A list of resources is located at: http://www.arm.com/products/processors/cortex-m/index.php
Click on the Resources tab. Or search for “Cortex-M3” on www.arm.com and click on the Resources tab.
5. ARM Infocenter: http://infocenter.arm.com Look for Application Notes and Cortex-M listings.
6. http://forums.arm.com
How can I learn more about these CAN examples ?
Easy ! With a hardware board you can generate and receive real CAN messages and connect to other nodes or a CAN test
analyzer. You can use the Cortex-M Serial Wire Viewer to see the CAN messages and interrupts displayed in real time. You
can compile these examples with the evaluation version of the software.
Keil has evaluation boards for the many ST processors. See http://www.keil.com/arm/boards/cortexm.asp.
Keil supports many STMicroelectronics boards. Many have CAN examples. See www.keil.com/st for more information.
Keil completely supports the new Cortex-M0 and Cortex-M0+ processors. DS-5 supports ST Cortex-A9 processors such as
SPEAr. See www.arm.com/ds5. You now know how CAN works and are familiar with the Keil software and will have no
problem getting a real CAN system operating. You have already ran an accurate simulation of a CAN network. If you obtain
other target hardware such as the MCBSTM32F400, you can connect up to any CAN network and communicate with it.
Keil offers a complete CAN stack for all ARM7™, ARM9™ and Cortex-M4/M3/M1/M0/M0+ processors. This comes as
part of MDK Professional. It was previously known as RL-ARM™. Please visit
UUwww.keil.com/rl-arm/UU for details.
This middleware package contains USB, TCP/IP networking, Flash file system and the CAN interface.
The Keil RTX™ RTOS now comes with a BSD type license. Source is provided. See www.arm.com/cmsis.