CAN-BUS shield 50kbps with coryjfowler library

Hi,
I'm heavily using Cory J. Fowler library

in many of my projects.
Today I need to set up speed of 50 kbps with no success.
Everything above 50 kbps works like a charm but below 100 kbps nothing works, neither sending nor receiving, like there was no traffic on the bus.

Entering Configuration Mode Successful!
Setting Baudrate Successful!
Setting CAN0 to 50kbps for Fiat 500
Error Sending Message...

I'm trying to make 2 devices to talk to each other, my other CAN modules (not Arduino) work and communicate with each other @ 50, 20, 10 kbps etc. but not the Arduino one. I have updated the library to recent one but still no luck.
Any ideas? I tried with and without termination, wires are only 20 cm long.

Thanks for help

See Modifying Cory Fowler's CAN bus MCP2515 library for use at slow data rates - Networking, Protocols, and Devices - Arduino Forum

You'll need to modify the library to fix the hard coded timeout for the send message function that was designed for high baud rates (~250 kpbs) and as a consequence is too short for slow baud rates because it doesn't give enough time for a message to be sent.

The whole idea of using a blocking send function is also a bad design choice.

One possible hack is to increase the TIMEOUTVALUE in the mcp_can_dfs.h file. Note, despite its name, this is not a time value, it's a loop counter which by virtue of the hardware speed results in a time period. Altering this setting will affect all baud rates.

In my own version of the library I make the function return immediately and it returns whether or not it was able to put the data into one of the transmit buffers. It doesn't wait for the message to be sent.

Thank you very much mikb55. I have changed 50 to 300, closed and reopened Arduino IDE, compiled and uploaded new sketch and still the same.

if(CAN0.begin(MCP_ANY, CAN_100KBPS, MCP_16MHZ) == CAN_OK) {
CAN0.setMode(MCP_NORMAL);
}

Above code works, devices do talk to each other.
If I only change "100KBPS" to "50KBPS" (or 20, 10) and obviously set the other device to same speed, Arduino doesn't send and doesn't receive anything.

I tried CAN_receive sketch from examples folder. I set my other known working device to send messages in loop.
If I set sender to 100KBPS Arduino receives all, if I change sender to 50 and Arduino to 50 Arduino doesn't receive anything.

I tried CAN_loopback sketch with CAN0.setMode(MCP_NORMAL); commented and it works on 50KBPS.

Modify the example programs to display the numeric values returned by sendMsg().

mikb55:
Modify the example programs to display the numeric values returned by sendMsg().

Excuse my ignorance... any clue how to do that..?

Under
byte sndStat = CAN0.sendMsgBuf(0x100, 0, 8, data);
Add a line that says
Serial.println(sndStat);

Thank you very much mikb55.
So sndStat returns "0" in 100kbps mode but in 50kbps mode it returns "7" for first 6 messages and then "6" for rest.
I can see that it does send something, 1st attached picture shows 100kbps and the 2nd shows 50kbps frame however the 50kbps frame doesn't get to receipient and again, Arduino doesn't read any 50kbps frames.

This might not be the cure but I had this trouble using 33K3BPS as i want to access the SWCAN in GM/Vauxhall/Opel cars.

I have a couple of thoughts.
First, modify the timeout value in mcp_can_dfs.h, don't just redefine it later in the code - doing this didn't work for me and a proper edit of the header file was needed. I changed it to 500 because why the dickens not. Save, close, restart Arduino IDE. I can see that your first CAN message is actually being sent but it doesn't look complete so the code might be cutting the transmission off early.

Secondly, make sure the board is set to the correct crystal - i assumed it was 16MHz when it was 8MHz and it's a well documented error.

Lastly, make sure the board is getting 5V! Don't assume it is. The red light is just as bright but I promise you, I've wasted DAYS thinking it was powered fine when I only fed it 3v3.

Thank you very much dandymon.
I did change timeout from 50 to 300 as suggested by mikb55.
I didn't have time yet to play with it, to check if it works on another board but I definitely will.
I know about cristal, a while ago I bought "CAN module" from ali as it was cheaper and easier than buying MCP2515+MCP2551 in DIL package and use it on breadboard (I have hundreds but SOICs and QFNs). That module used 8MHz crystal, it took me a while to figure out why it doesn't work :wink:
And yes the board does get solid 5V, it's my own design board, not some breadboard madness.

It may be a hardware problem. Be sure the physical ends of the CAN bus are properly terminated and no long stubs. Also they should also have a common ground. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil