The Microchip MCP2515 is a standalone CAN controller used to provide CAN bus communication to microcontrollers like Arduino or ESP32. Setting the correct baud rate is critical because every node on a CAN network must operate at the exact same bit timing to ensure message integrity and prevent bus errors.
Key Timing Components
Fosc: This is the frequency of the crystal or clock source connected to the MCP2515. Typical values are 8MHz and 16MHz.
Time Quantum (TQ): The basic unit of time for the CAN controller. It is derived from the oscillator and the Baud Rate Prescaler (BRP).
Bit Segments: A single CAN bit is divided into four segments:
Sync Segment: Always 1 TQ. Used to synchronize nodes on the bus.
Propagation Segment (PropSeg): Compensates for physical delays in the network.
Phase Segment 1 (PS1): Compensates for edge phase errors.
Phase Segment 2 (PS2): Used to adjust the sample point.
How the Calculation Works
The total number of Time Quanta per bit is the sum: 1 (Sync) + PropSeg + PS1 + PS2. The MCP2515 requires this sum to be between 8 and 25 TQ for reliable operation.
The sample point is the moment when the CAN controller reads the state of the bus. It is calculated as: (1 + PropSeg + PS1) / Total TQ. For high-speed CAN (ISO 11898), a sample point around 75% to 87.5% is typically recommended.
Register Descriptions
Register
Function
CNF1
Controls the Synchronization Jump Width (SJW) and the Baud Rate Prescaler (BRP).
CNF2
Configures the Propagation Segment, PS1, and determines if PS2 is programmable.
CNF3
Defines Phase Segment 2 and Wake-up filters.
Example: Setting 500kbps with 16MHz Crystal
To achieve 500kbps with a 16MHz oscillator:
Set BRP to 0. TQ = 2 * (0 + 1) / 16,000,000 = 125ns.
Set Total TQ per bit to 16. (16 * 125ns = 2000ns = 1/500,000).