Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 2 months ago.
CANbus baud rate detection
Is there a standard way to automatically detect the CAN baud rate? I need to build a device that will be moved between 250K and 500K networks. The speed will not be known prior to shipping the device.
Also, is there a good way to determine average bus load over a given timeframe?
I am using the CAN controller on the LPC1768.
Thanks
1 Answer
7 years, 2 months ago.
hi Sonny,
I don't know about "standard" methods, but there are some things you might consider.
First, and you likely know this, if one node connects to the network at one speed, and other devices connect at a different speed, nobody gets their message through - they are both misinterpreting, and asserting error frames to each others messages.
Let's say all other devices are at a fixed bit-rate, or your device is the last to join. This is about as good as it can get for auto-baud.
So, the "glitchy" way is:
- Connect at 250K.
- If you see CAN errors, switch to 500K.
- Monitor at the new speed, and assess error counters (in case you switched when you should not have).
A clean way:
- Configure your CAN controller to *NOT* assert the hardware acknowledge.
- Connect at one speed and listen .
- If you see CAN errors, switch to the other speed.
- If you see no CAN errors, reconfigure to enable hardware acknowledge.
Another way:
- Most CAN transceivers have a pin that can put the chip into a listen only mode.
- Wire that pin to a micro pin.
- Configure the transceiver for listen only.
- Configure CAN for one speed and listen.
- If you see CAN errors, switch to the other speed.
- If you see no CAN errors, toggle the pin to the CAN transceiver to enable the full mode.
The LPC1768 has a register for LOM - Listen Only Mode. I don't think the standard APIs give you access to that, so you may need to create your own code to modify that bit, but this avoids giving up another micro pin to control the transceiver.
Lastly, and I haven't researched this - if the CAN Rx pin on the micro could be configured to grab a hardware timestamp, then you might be able to measure the time of CAN pulses. It would need to capture many, to ensure it found the smallest pulse. Then compute the bit-rate and configure the CAN controller.
Oh, the next "last" thing. If all the nodes are auto-baud, it is hard to predict what speed the network would end up at - if it stabilized at all. And there are other features in CAN (Bus-Off) that can help take a rogue node off the network - but those too require some software to manage.