Electrical – Required crystal frequency for MCP2515 with ATmega328P

atmega328pcancrystal

I want to connect a number of ATmega328P microcontrollers over a CAN bus. I found out that I will need some MCP2515 and MCP2551 ICs. In different schemas I sometimes see a 8 MHz crystal on the MCP2515 and sometimes a 16 MHz crystal.

This is the desired setup:

Multiple ATmega328P chips for a home automation project. The amount of data to be sent is really limited: switch on relay, switch off relay… so the speed on the CAN bus can be low.

What frequency should I take? Or doesn't it matter? Do I need to specify anything else needed to make the decision?

Is the use of a crystal on the ATmega required? Or can I use the internal clock of 8 MHz or 16 MHz?

Best Answer

The clock frequency must be picked so that it suits the divisor hardware of the CAN controller. What's suitable is different from controller to controller, but often the clock depends on how many time quanta you use per baud rate. You should aim to use one of the CANopen standardized baud rates and sample points, since these are industry standard (like 250 kbps or 125 kbps). The standard is available for free somewhere at https://www.can-cia.org if you register and download.

When you have determined how many time quanta that's needed to achieve a certain baud rate, you should pick a clock that gives a divisor error of less than 1%. CAN is picky with this: inaccurate divisors may cause the whole node to fail. Therefore you must always use crystal oscillators for CAN communication; built-in RC oscillators are too bad to be used.