Hello All,
I wanted to shortly ask you if it is possible to communicate with the alternative baud rate values (which are not existing in the list of seeed-supported baudrates)? The reason is, I have to “listen” another product which is sending data at 31.25kbps. Here comes the question, is it possible and if so where to start?
Note: the above snippet in “mcp_can.cpp” MUST be placed in the baud switch & case correctly or it will fail to function. Just as long as the above is pasted like this:
[existing code...]
break;
(Paste the code here!)
case(some_baud_rate):
[...existing code]
This should allow you to use ‘CAN_31K25BPS’ as a baud rate. I dont have anything to test that rate with, but the bit timing calculations should be correct if your MCP2515 is using a 16MHz crystal (Which all CAN_Shields I’ve seen are).
cory.j.fowler thank you very much for support. I have currently updated my libs and bot of the shields are communicating now with the new baud rate. Moreover can you briefly explain how you found out the values for a given baud rate? I do not want to disturb you guys everytime when I need something else…
The datasheet (section 5) explains it the best that I could even try to.
Basically, the first six bits of register CNF1 are used for the Baud Rate Prescaler (BRP) which generates the Time Quantum (TQ). The time quantum is just a time duration that we will add together to create the Bit Time.
The Bit Time is composed up of:
SyncSeg with a fixed duration of one time quantum
PropSeg with a configurable duration of one to eight time quantum
PhaseSeg1 (PS1) with a configurable duration of one to eight time quantum
PhaseSeg2 (PS2) with a configurable duration of one to eight time quantum
Section 5.3 shows a few crucial requirements about the relationship of PropSeg, PS1, PS2, TDelay, and SJW.
PropSeg + PS1 >= PS2
PropSeg + PS1 >= Tdelay
PS2 > SJW
So for a BRP of 15 and using a 16MHz crystal, you end up with a 2 microsecond TQ.
At a baudrate of 31.25k, you would have a Bit Time of 32 microseconds.
Dividing the Bit Time by the TQ gives the total number of TQ needed to create the baudrate.
Essentially,
PS1 7
PS2 6
PropSeg 2
SyncSeg 1
SJW 1
Total 16
So, I ended up making a spreadsheet to calculate the bits…