CAN bus frequency

24 Feb 2010 . Edited: 24 Feb 2010

Hi,

I found a bug (and worked out a way around it; thank you Simon for your post about the mbed registers :-) in the CANbus frequency setting. Basically, using can.frequency() doesn't work for all frequencies (speeds) and since it's a 'void' there is no return value to let you know it hasn't worked.

Would it be possible to make can.frequency() an 'int' so that it returns a pass/fail result. An even bigger modification which might be better is if it was possible to be dual format; use decimal numbers for those speeds that work, but use hex numbers with the 0x prefix to write to the BTR register instead. e.g.

can2.frequency(600000)      //sets CAN2 speed to 600kbps

can2.frequency(0x280002)   //writes 0x280002 to BTR register for 615kbps

I've posted a topic, CANbus frequency setting, in the other mbed forum with more details and the way I worked around the problem

Thanks in advance.

Sophie x

26 Feb 2010

You could also do with being able to set the sample point.

And changing the names in the library as the terms are incorrect.

27 Feb 2010

Hi Andrew,

Luckily we can do whatever we want with the LPC_CAN2->BTR = method. The down side is that it takes a lot of working out :-( I've found out that other people use a different setting to the one I've found so now I'm using BTR = 0x370002. Everything you need to know is in the user manual. But I agree, it would be a lot easier to do things if the library did more of the work :-)

To the MBED team  -  I'd be willing to try to update the library if I knew how...

Sophie x

28 Feb 2010

There are algorithms to do this, std bus speeds such as 1MBit or 500k for standard clocks are quite easy to calculate when TSeg1/2/SJW/BRP are all integers.

615KBit is an obscure setting and probably deliberate.

06 Apr 2010 . Edited: 06 Apr 2010

Hi,

Someone else has also fallen foul of this limitation, but fortunately been able to work out what they need to do from my other post. Maybe I've missed a whole section on the website but I haven't been able to find a description of what the built-in drivers CAN or CANnot do (lol). Can any of the mbed team comment on this please?

Thanks in advance,

Sophie x

29 Jan 2011

I know this is an old post but I'll post here since it's related...

I need to set my CAN frequency at 83Kbs... In my old CANUSB code I would set the frequency by BTR1 abd BTR2. The value would be written like this...

sBitRate = "0x05:0x1c"; 83Kbs

In my mBed when I try and do this it does not like it...

can1.frequency(0x05:0x1c);

What am I doing wrong?

Tim

-

29 Jan 2011

Never mind... It was easier then I thought...

I just needed to use the hex value for 83000...

can1.frequency(0x14438);

--

31 Jan 2011

Or just put 83000, whether it's hex or not is irrelevant.