The CAN Config block configures the Controller Area Network (CAN) peripheral for communication on CAN bus networks. This block sets up essential parameters including bit timing (baud rate), message buffer allocation, filtering configuration, and interrupt priorities. The CAN Config block must be present in your model before using CAN Tx or CAN Rx blocks.
CAN is a robust, multi-master serial bus system designed for networking intelligent devices. It is widely used in automotive, industrial automation, and embedded systems for reliable communication in electrically noisy environments. The protocol features automatic message prioritization, error detection, and fault confinement mechanisms.
| Device Family | CAN Type | Maximum Modules | CAN-FD Support | Features |
|---|---|---|---|---|
| SAM E70/S70/V70/V71 | MCAN (Bosch M_CAN) | 2 | Yes | Advanced filtering, timestamping, DMA-based buffers |
| SAM E5x (E51/E53/E54) | CAN | 2 | Yes | Standard/Extended ID, FIFO mode, dedicated buffers |
| SAM C20/C21 | CAN | 2 | Yes | Standard/Extended ID, message filtering |
| SAM D51 | CAN | 2 | Yes | Standard/Extended ID, FIFO mode |
| dsPIC30F/33F/33E/33C | - | - | - | Not currently supported (future enhancement) |
| PIC32MX/MZ | - | - | - | Not currently supported (future enhancement) |
| Parameter | Description | Valid Values | Default |
|---|---|---|---|
| CAN Module | Selects which CAN peripheral to configure (CAN0, CAN1, MCAN0, MCAN1) | Device-dependent dropdown | CAN0 or MCAN0 |
| Parameter | Description | Valid Values | Default |
|---|---|---|---|
| Baud Rate | Communication speed in bits per second | 50 kbps to 1000 kbps (standard values) | 250000 (250 kbps) |
| Propagation Segment (PRSEG) | Compensates for physical delays in the network | 1-8 TQ (Time Quanta) | Auto-calculated |
| Phase Segment 1 (PHSEG1) | First phase buffer segment for bit synchronization | 1-8 TQ | Auto-calculated |
| Phase Segment 2 (PHSEG2) | Second phase buffer segment for bit synchronization | 1-8 TQ | Auto-calculated |
| Synchronization Jump Width (SJW) | Maximum time by which the bit can be lengthened or shortened | 1-4 TQ | Auto-calculated |
Tip: The blockset automatically calculates optimal bit timing parameters to achieve the selected baud rate with a sample point around 87.5% of the bit time, which is ideal for most CAN networks.
| Parameter | Description | Valid Values |
|---|---|---|
| CAN RX Pin | GPIO pin for CAN receive signal | Device-specific pin list (e.g., PA12, PB15) |
| CAN TX Pin | GPIO pin for CAN transmit signal | Device-specific pin list (e.g., PA13, PB14) |
| Parameter | Description | Configured By |
|---|---|---|
| Rx Dedicated Buffers | Number of dedicated receive buffers (one per unique message ID) | Auto-detected from CAN_Rx blocks |
| Rx FIFO 0 Size | Number of messages in receive FIFO 0 | Auto-detected from CAN_Rx blocks |
| Rx FIFO 1 Size | Number of messages in receive FIFO 1 | Auto-detected from CAN_Rx blocks |
| Tx Dedicated Buffers | Number of dedicated transmit buffers | Auto-detected from CAN_Tx blocks |
| Tx FIFO Size | Number of messages in transmit FIFO | Auto-detected from CAN_Tx blocks |
| Parameter | Description | Valid Values | Default |
|---|---|---|---|
| Enable CAN-FD | Enable CAN with Flexible Data rate support | On / Off | Off |
| Data Buffer Size | Maximum data bytes per message (CAN 2.0: 8 bytes, CAN-FD: up to 64 bytes) | 8 (standard) or 64 (CAN-FD) | 8 |
| Parameter | Description | Valid Values | Default |
|---|---|---|---|
| Rx Interrupt Priority | Priority level for receive interrupts (0 = highest priority) | 0-7 | 3 |
A CAN bit time is divided into four segments, each measured in Time Quanta (TQ):
|<---- Nominal Bit Time ---->|
|SYNC| PROP | PHASE1 | PHASE2 |
1TQ 1-8TQ 1-8TQ 1-8TQ
^Sample Point (typically 87.5%)
The CAN baud rate is determined by:
Baud Rate = F_CAN / (BRP Γ (SYNC + PRSEG + PHSEG1 + PHSEG2))
Where:
F_CAN = CAN peripheral clock frequency
BRP = Baud Rate Prescaler (1-1024)
Time Quantum (TQ) = BRP / F_CAN
The sample point is where the CAN controller reads the bus level. Optimal location is typically 87.5% of the bit time:
Sample Point (%) = (SYNC + PRSEG + PHSEG1) / Total TQ Γ 100
Recommended: 75-90% for networks up to 1 Mbps
Typical: 87.5% provides good tolerance
/* CAN Module Initialization (SAME7x) */
/* Configure bit timing */
MCAN0_REGS->MCAN_NBTP =
MCAN_NBTP_NSJW(SJW - 1) |
MCAN_NBTP_NBRP(BRP - 1) |
MCAN_NBTP_NTSEG1(TSEG1 - 1) |
MCAN_NBTP_NTSEG2(TSEG2 - 1);
/* Configure filters */
MCAN0_REGS->MCAN_SIDFC =
MCAN_SIDFC_LSS(numStandardFilters);
MCAN0_REGS->MCAN_XIDFC =
MCAN_XIDFC_LSE(numExtendedFilters);
/* Configure Rx buffers and FIFOs */
MCAN0_REGS->MCAN_RXBC =
MCAN_RXBC_RBSA(rxBufferAddress);
MCAN0_REGS->MCAN_RXF0C =
MCAN_RXF0C_F0SA(rxFifo0Address) |
MCAN_RXF0C_F0S(rxFifo0Size);
/* Configure Tx buffers and FIFO */
MCAN0_REGS->MCAN_TXBC =
MCAN_TXBC_TBSA(txBufferAddress) |
MCAN_TXBC_TFQS(txFifoSize);
/* Enable interrupts */
MCAN0_REGS->MCAN_IE = MCAN_IE_RF0NE | MCAN_IE_RF1NE;
NVIC_EnableIRQ(MCAN0_INT0_IRQn);
/* Enable CAN module */
MCAN0_REGS->MCAN_CCCR &= ~MCAN_CCCR_INIT;
}
/* CAN Module Initialization (SAMx5/C2x) */
/* Enable CAN peripheral in MCLK */
MCLK->AHBMASK.bit.CAN0_ = 1;
/* Configure bit timing */
CAN0->NBTP.reg =
CAN_NBTP_NSJW(SJW - 1) |
CAN_NBTP_NBRP(BRP - 1) |
CAN_NBTP_NTSEG1(TSEG1 - 1) |
CAN_NBTP_NTSEG2(TSEG2 - 1);
/* Configure standard ID filters */
CAN0->SIDFC.reg = CAN_SIDFC_LSS(numStdFilters);
/* Configure extended ID filters */
CAN0->XIDFC.reg = CAN_XIDFC_LSE(numExtFilters);
/* Configure Rx FIFO 0 */
CAN0->RXF0C.reg =
CAN_RXF0C_F0SA(fifo0Addr >> 2) |
CAN_RXF0C_F0S(fifo0Size);
/* Configure Tx buffer/FIFO */
CAN0->TXBC.reg =
CAN_TXBC_TBSA(txBufAddr >> 2) |
CAN_TXBC_TFQS(txFifoSize);
/* Enable interrupts */
CAN0->IE.reg = CAN_IE_RF0NE | CAN_IE_TCFE;
NVIC_EnableIRQ(CAN0_IRQn);
/* Release initialization mode */
CAN0->CCCR.bit.INIT = 0;
}
Application: Industrial control network with 8-byte data messages
Configuration:
- CAN Module: CAN0
- Baud Rate: 250000 (250 kbps)
- RX Pin: PA23 (CAN0_RX)
- TX Pin: PA22 (CAN0_TX)
- Message Format: Standard 11-bit ID
- Data Length: 8 bytes (CAN 2.0)
- Rx Interrupt Priority: 2
/* Resulting bit timing parameters (F_CAN = 60 MHz):
* BRP = 12
* SYNC = 1 TQ
* PRSEG = 3 TQ
* PHSEG1 = 10 TQ
* PHSEG2 = 6 TQ
* Total = 20 TQ
* Baud = 60MHz / (12 Γ 20) = 250 kbps
* Sample Point = (1+3+10)/20 = 70% (acceptable range)
*/
Application: Automotive ECU communication with minimal latency
Configuration:
- CAN Module: MCAN0 (SAM E70)
- Baud Rate: 1000000 (1 Mbps)
- RX Pin: PD28 (MCAN0_RX)
- TX Pin: PD12 (MCAN0_TX)
- Message Format: Extended 29-bit ID
- Data Length: 8 bytes
- Network: Short bus (<40 meters)
/* Resulting bit timing (F_CAN = 60 MHz):
* BRP = 6
* SYNC = 1 TQ
* PRSEG = 1 TQ
* PHSEG1 = 4 TQ
* PHSEG2 = 4 TQ
* Total = 10 TQ
* Baud = 60MHz / (6 Γ 10) = 1 Mbps
* Sample Point = (1+1+4)/10 = 60% (suitable for short bus)
*/
Application: High-throughput sensor data acquisition (SAM E70 only)
Configuration:
- CAN Module: MCAN1
- Enable CAN-FD: On
- Nominal Baud Rate: 500000 (500 kbps, arbitration phase)
- Data Baud Rate: 2000000 (2 Mbps, data phase)
- RX Pin: PC12 (MCAN1_RX)
- TX Pin: PC14 (MCAN1_TX)
- Data Buffer Size: 64 bytes
/* CAN-FD allows different bit rates for arbitration and data phases:
* Nominal Phase (arbitration): 500 kbps
* Data Phase (payload): 2 Mbps
*
* Advantages:
* - Up to 64 bytes per message (vs 8 for CAN 2.0)
* - Faster data transfer during payload transmission
* - Backward compatible with CAN 2.0 nodes during arbitration
*/
Application: Motor controller with sensor nodes and HMI
Network Topology:
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β Motor Controlβββββββ Sensor Node βββββββ HMI β
β (Controller)β β (Node 1) β β Display β
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β β β
ββββββββββββββββββββββ΄ββββββββββββββββββββββ
CAN Bus (250 kbps)
Configuration per node:
- Baud Rate: 250 kbps (all nodes must match)
- Termination: 120Ξ© at each end of bus
- Message IDs:
0x100-0x10F: Motor control commands
0x200-0x20F: Sensor data
0x300-0x30F: HMI updates
The CAN Config block automatically configures message filters based on CAN_Rx blocks in your model:
| Filter Type | Description | Configuration | Use Case |
|---|---|---|---|
| Classic (Mask) | ID AND mask comparison | Message ID + Mask | Accept messages with specific bits matching |
| Dual ID | Accept either of two IDs | ID1 OR ID2 | Two specific message types to same buffer |
| Range | Accept ID range | ID_Min to ID_Max | Group of related messages (e.g., 0x100-0x10F) |
/* Classic filter: Accept ID 0x123 only */
Filter ID: 0x123
Filter Mask: 0x7FF (all 11 bits must match)
Result: Accepts only 0x123
/* Range filter: Accept 0x100-0x10F */
ID1: 0x100 (minimum)
ID2: 0x10F (maximum)
Result: Accepts any ID from 0x100 to 0x10F
/* Dual ID filter */
ID1: 0x200
ID2: 0x300
Result: Accepts either 0x200 or 0x300
Incorrect bit timing (baud rate mismatch)
Missing or incorrect termination resistors
Excessive noise or EMI on bus
Hardware fault (shorted lines)
Solutions:
Verify all nodes use identical bit timing settings
Check for 120Ξ© termination at both ends of bus
Inspect CAN_H and CAN_L signals with oscilloscope
Implement automatic bus-off recovery in software
Verify CAN Config block is present in model
Check filter configuration in CAN_Rx block
Ensure message ID matches filter settings
Verify buffer allocation (FIFO vs dedicated buffer)
Check if buffer overflow occurred
Review message ID assignment (lower ID = higher priority)
Reduce bus load (transmission frequency)
Use Tx buffers instead of Tx FIFO for time-critical messages
Implement priority-based message scheduling
| Issue | Symptom | Solution |
|---|---|---|
| Sample point too early | Frequent bit errors, poor noise immunity | Increase PHSEG1, decrease PHSEG2 (move sample point to 75-87.5%) |
| Sample point too late | Synchronization errors on long cables | Decrease PHSEG1, increase PHSEG2 |
| SJW too small | Poor resynchronization, oscillator drift issues | Increase SJW (typically set to min(4, PHSEG2)) |
| Baud rate mismatch | No communication, constant errors | Verify identical baud rate on all nodes, check clock source accuracy |