automatic baud rate detection in CAN bus network MCP2515 MCP2551

Some time ago, people indicated that automatic baud rate detection in a CAN bus network is not practical in the "real world". Using the Seeed CAN_BUS_Shield-Master library, we have been unsuccessful. Given more time has passed, has anyone successfully done auto-detection?

One way to do auto baud detection is to set the interface to listen only with a guessed baud rate. If that’s the right speed and there is traffic then you’ll get some traffic and know it worked. If it doesn’t work then you try another baud rate. Being in listen only mode means that you won’t break the bus if you’re on the wrong speed. All that will happen is that it won’t work.

So, the method would be to generate a list of candidate baud rates in descending order of likelihood and then try each one in turn until traffic shows up. Obviously you can only do this on a live bus with traffic.

See autobaud.ino example sketch from due_can library:

If you want to join an existing active bus, checkout post #4 CAN Shield - Exhibition - Arduino Forum
Essentially you put the new device into listen mode (to stop ACK bits messing up the bus), set a baud rate and check for errors. Repeat for the next baud rate and so on.

How long this takes depends on how many baud rates you are checking and how active the CAN bus is.

Alternatively, ignore the MCP2515 and use the Arduino to measure the minimum pulse width of signals coming from the transceiver and infer the baud rate.

@mikb55 - We tried the code you suggested and it compiles and runs with minor tweaking (#include "arduino.h" #include "SPI.h" #include "MCP2515.h" #include "MCP2515_defs.h"). Also had to put "0" in the baud rate field of the "baudRate=CAN.Init(0,16);" command of the main sketch. However, it doesn't find the baud rate even though there are two nodes sending messages every 1/2 second. What constitutes; "...two other nodes active"?

Our board works well for sending and receiving messages using another sketch (with interrupts), so hardware is all OK.

Initializing ...
MCP2515 Init Failed ...
Ready ...

davidcyr2000:
@mikb55 - We tried the code you suggested and it compiles and runs with minor tweaking (#include “arduino.h” #include “SPI.h” #include “MCP2515.h” #include “MCP2515_defs.h”). Also had to put “0” in the baud rate field of the “baudRate=CAN.Init(0,16);” command of the main sketch. However, it doesn’t find the baud rate even though there are two nodes sending messages every 1/2 second. What constitutes; “…two other nodes active”?

Our board works well for sending and receiving messages using another sketch (with interrupts), so hardware is all OK.

Initializing ...

MCP2515 Init Failed …
Ready …

It works for me.
Make sure that you set the correct crystal frequency. It’ll probably be 8 instead of 16.

int baudRate=CAN.Init(0,8);

The scanning algorithm uses a default step size of 5k. This may be too coarse. Try setting it to 1k.

int MCP2515::Init(int CAN_Bus_Speed, byte Freq) {
 if(CAN_Bus_Speed>0) {
   if(_init(CAN_Bus_Speed, Freq, 1, false)) return CAN_Bus_Speed;
 } else {
     int i=0;
     byte interruptFlags = 0;
     for(i=10; i<1000; i++) {// step size
      Serial.print("CAN Freq = ");
      Serial.println(i);

Initializing …
CAN Freq = 10
CAN Freq = 11
CAN Freq = 12
CAN Freq = 13
CAN Freq = 14
CAN Freq = 15
CAN Freq = 16
CAN Freq = 17
CAN Freq = 18
CAN Freq = 19
CAN Freq = 20
MCP2515 Init OK …
Baud Rate (kbps): 20
Ready …

@mikb55 - Thanks for the feedback! Got it working once I realized the INT_PIN was not the attachInterrupt "number" as described in the last paragraph and the table at: attachInterrupt() - Arduino Reference
Works great! Thanks!!!