Run two boards with different crystals (MCP2515 specifically)

cancrystal

I have one CAN bus interface that's using a 16 MHz crystal, and I want to set up my own interface to talk / simulate CAN packets with first one. I do have 20 MHz crystals for my own interface, but whenever I connect those two together, setup my own to 500 kbaud, the other one discovers only 50 kbaud… therefore this question.

It is worth to mention that the already-setup interface does work flawlessly with vehicle CAN and is verified to work as expected.

Does it matter (in CAN) if the other device uses different crystal?

For those who wonder, this is an Arduino setup though I'm generally curious about this in an electronics setup.

Best Answer

Does it matter (in CAN) if other device uses different crystal ?

No, of course not. Simply set the baudrate correctly for each node. Verify with an oscilloscope.

The CAN spec recommends using quartz oscillators for baudrates above 125kHz. As a rule of thumb, you should pick a crystal value that gives you a maximum deviation of 1% from the optimal baudrate.

You will have to determine which crystal values that are suitable by reading how the clock pre-scaler works for the specific CAN controller. This should be much easier when you have an external controller as in your case, rather than have a built-in one (which is far more common). Just provide a dedicated clock to it.

Also note that clock pre-scalers for CAN might be rather intricate, as you'll have to consider how many time quanta to use per bit and where the sync point ends up. This is usually the hardest part to get right when writing a CAN driver.