CANbus frequency setting

22 Feb 2010 . Edited: 22 Feb 2010


I'm a bit confused about the CANbus frequency setting, does anyone know if I can use any value to set up the frequency or is there a limited set of frequencies? e.g 50kHz, 125kHz, 250kHz, 500kHz, 800kHz and 1MHz seem to be the standard ones I've seen when looking around on the web.

I ask because I need to be able to use 47,619Hz, 500kHz or 615kHz and results have not been promising; I don't see anything happen when I use those frequencies. Eventually, after a lot of experimentation I had some success with 600kHz. I was able to receive some of the messages I was sending (I think the CANbus receives it's own messages if everything is OK) but it's all a bit random. I've read that this can happen if the frequency is not exactly right. So far I haven't been able to receive any messages from my ECU box either.

Any help or clues would be very much appreciated, thanks in advance,

Sophie x

[edit: remove space at end of my post lol]

22 Feb 2010 . Edited: 22 Feb 2010

Firstly Controller Area Network is a digital communication system, the transmission rate is specified in Bits/Sec not Hz.

So its 1MBit not 1MHz. Like broadband.

ETA: Really the library should have the parameter as bus speed or baud rather than frequency and hz as its not technically correct.

Secondly CAN requires a line driver IC such as the MCP2551, which is not fitted to the mbed.

Thirdly the Bus needs to be terminated. Typically this involves fitting 2 120ohm resistors between the CAN High and Low lines at either end of the cable.


A simple test to see if the bus is operating correctly is to use a multimeter and measure the voltage. If its active and working it will show 2.5v, if not it will be 0v as one of the CAN controllers on the network is pulling the bus low (known as Bus Off)


What device are you trying to connect to?

22 Feb 2010

Hi Andrew,

Thanks for your help and corrections :-)

I'm using this: to connect to my car's ECU. The bus speeds used are either 47,619, 500k from here: and here: or 615k from here: To be honest I don't know which speed is right, but at least when I set the speed to 600k (600000) something happens :-)

Sophie x

23 Feb 2010 . Edited: 23 Feb 2010

Just a guess, but Id say your 450 thousand out. Generally the interiour bus is a slower 20k -> 50k. Id try 50k and see how u go, as higher speeds are found on the C-BUS/P-BUS.




can.frequency(50000); // 50kbit i-can

23 Feb 2010 . Edited: 23 Feb 2010

Hi All and thanks for your tips :-)

By a stroke of luck Simon Ford had posted a very informative answer in this topic: Problems with Memory Pointers to mbed NXP1768 Peripherals which gave me the idea of delving into how the CANbus is setup. I tried setting different CANbus speeds and reading the value of LPC_CAN2->BTR for each setting - this is what I found:

speed = 50000 LPC_CAN2->BTR = 0x52002F
speed = 100000 LPC_CAN2->BTR = 0x520017
speed = 500000 LPC_CAN2->BTR = 0x410005
speed = 600000 LPC_CAN2->BTR = 0x520003
speed = 1000000 LPC_CAN2->BTR = 0x410002

but with the (unusual?) values I want I saw this:

speed = 47619 LPC_CAN2->BTR = 0xFFC3FF
speed = 615000 LPC_CAN2->BTR = 0xFFC3FF

Which very much looks like the CANbus frequency (sorry Andrew, speed ;-) setting doesn't work properly for all speeds.

With a not so quick reading of the NXP LPC176x User Manual and a lot of help from the CANbus guide on this site: , particularly the section on CAN bit timing, I was able to work out that mbed must have a 24 MHz speed/frequency (whichever one it is!). Knowing that I was able to find the BTR values for 615000 had to give a division of 39 from 24MHz:
24,000,000 / 615,000 = 39.024; 39 is the closest number and 24MHz/39 = 615,385 which hopefully would be close enough :-)

39 = 3 x 13 which makes things a bit easier and I used 3 for the BPR value. I noticed that seems to suggest that the TSEG1 value is usually larger than TSEG2 and I chose TSEG1 = 9 and TSEG2 = 3

BPR = 3 (put 2 in the BTR register because mbed adds 1 to this value)
TSEG1 = 9 (put 8 in the BTR register because mbed adds 1 to this value)
TSEG2 = 3 (put 2 in the BTR register because mbed adds 1 to this value)
and an extra 1 for the sync bit (which isn't included in the BTR register!!!)

So I tried setting LPC_CAN2->BTR = 0x280002 like this:

can2.frequency(600000); // nearest mbed MBED CAN speed setting to the one I want
LPC_CAN2->BTR = 0x280002; // correct BTR setting for 615k speed

Now I've got CANbus messages reliably going between my mbed and my car - phew!!! (now all I need to do to is make sense of them lol)

BTW, following's guideline of making TSEG1 bigger than TSEG2 would imply that the CANbus library isn't quite right in this respect and maybe the values should be:
speed = 50000 LPC_CAN2->BTR = 0x25002F
speed = 500000 LPC_CAN2->BTR = 0x140005

Perhaps someone on the mbed team can check my working out :-)

Sophie x

23 Feb 2010

ah well good luck, I used this calculator to help me with setting the timing on the MCP2515 ic. It might help



03 Apr 2010

Thanks a bunch for this post.... I couldn't figure out why I was unable to listen to my Dodge Charger's 83.3 k baud rate CAN bus.  I looked at the BTR and found that it looked wrong, so I set it manually.. and voila it worked!!!

FYI 83.3 k baud rate BTR = 0x52001C


This mbed board is fantastic!



17 Jun 2010

Version 23 of the library is now live, and should fix these CAN frequency problems. Any problems, drop a line in the Bugs & Suggestions forum!