CAN Config Block Icon
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.

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 Support

Device FamilyCAN TypeMaximum ModulesCAN-FD SupportFeatures
SAM E70/S70/V70/V71MCAN (Bosch M_CAN)2YesAdvanced filtering, timestamping, DMA-based buffers
SAM E5x (E51/E53/E54)CAN2YesStandard/Extended ID, FIFO mode, dedicated buffers
SAM C20/C21CAN2YesStandard/Extended ID, message filtering
SAM D51CAN2YesStandard/Extended ID, FIFO mode
dsPIC30F/33F/33E/33C---Not currently supported (future enhancement)
PIC32MX/MZ---Not currently supported (future enhancement)

Block Parameters

CAN Module Selection

ParameterDescriptionValid ValuesDefault
CAN ModuleSelects which CAN peripheral to configure (CAN0, CAN1, MCAN0, MCAN1)Device-dependent dropdownCAN0 or MCAN0

Bit Timing Configuration

ParameterDescriptionValid ValuesDefault
Baud RateCommunication speed in bits per second50 kbps to 1000 kbps (standard values)250000 (250 kbps)
Propagation Segment (PRSEG)Compensates for physical delays in the network1-8 TQ (Time Quanta)Auto-calculated
Phase Segment 1 (PHSEG1)First phase buffer segment for bit synchronization1-8 TQAuto-calculated
Phase Segment 2 (PHSEG2)Second phase buffer segment for bit synchronization1-8 TQAuto-calculated
Synchronization Jump Width (SJW)Maximum time by which the bit can be lengthened or shortened1-4 TQAuto-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.

Pin Configuration

ParameterDescriptionValid Values
CAN RX PinGPIO pin for CAN receive signalDevice-specific pin list (e.g., PA12, PB15)
CAN TX PinGPIO pin for CAN transmit signalDevice-specific pin list (e.g., PA13, PB14)

Buffer Configuration

ParameterDescriptionConfigured By
Rx Dedicated BuffersNumber of dedicated receive buffers (one per unique message ID)Auto-detected from CAN_Rx blocks
Rx FIFO 0 SizeNumber of messages in receive FIFO 0Auto-detected from CAN_Rx blocks
Rx FIFO 1 SizeNumber of messages in receive FIFO 1Auto-detected from CAN_Rx blocks
Tx Dedicated BuffersNumber of dedicated transmit buffersAuto-detected from CAN_Tx blocks
Tx FIFO SizeNumber of messages in transmit FIFOAuto-detected from CAN_Tx blocks

CAN-FD Configuration (SAM E5x/E7x/C2x Only)

ParameterDescriptionValid ValuesDefault
Enable CAN-FDEnable CAN with Flexible Data rate supportOn / OffOff
Data Buffer SizeMaximum data bytes per message (CAN 2.0: 8 bytes, CAN-FD: up to 64 bytes)8 (standard) or 64 (CAN-FD)8

Interrupt Configuration

ParameterDescriptionValid ValuesDefault
Rx Interrupt PriorityPriority level for receive interrupts (0 = highest priority)0-73

CAN Bit Timing Fundamentals

Time Quantum (TQ) and Bit Segments

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%)
  • SYNC Segment: Always 1 TQ, used for synchronization
  • Propagation Segment (PRSEG): Compensates for signal propagation delays (1-8 TQ)
  • Phase Segment 1 (PHSEG1): Buffer segment before sample point (1-8 TQ)
  • Phase Segment 2 (PHSEG2): Buffer segment after sample point (1-8 TQ)

Baud Rate Calculation

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

Sample Point Location

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

Implementation Details

SAM E7x MCAN Peripheral Registers

/* 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;
}

SAM E5x/C2x CAN Peripheral Registers

/* 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;
}

Block Usage Examples

Example 1: Standard CAN at 250 kbps

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)
 */

Example 2: High-Speed CAN at 1 Mbps

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)
 */

Example 3: CAN-FD with Data Phase at 2 Mbps

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
 */

Example 4: Multi-Node Network Configuration

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

Filter Configuration (Auto-Managed)

The CAN Config block automatically configures message filters based on CAN_Rx blocks in your model:

Filter Types

Filter TypeDescriptionConfigurationUse Case
Classic (Mask)ID AND mask comparisonMessage ID + MaskAccept messages with specific bits matching
Dual IDAccept either of two IDsID1 OR ID2Two specific message types to same buffer
RangeAccept ID rangeID_Min to ID_MaxGroup of related messages (e.g., 0x100-0x10F)

Filter Configuration Examples

/* 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

Troubleshooting

Common Issues and Solutions

            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

Bit Timing Issues

IssueSymptomSolution
Sample point too earlyFrequent bit errors, poor noise immunityIncrease PHSEG1, decrease PHSEG2 (move sample point to 75-87.5%)
Sample point too lateSynchronization errors on long cablesDecrease PHSEG1, increase PHSEG2
SJW too smallPoor resynchronization, oscillator drift issuesIncrease SJW (typically set to min(4, PHSEG2))
Baud rate mismatchNo communication, constant errorsVerify identical baud rate on all nodes, check clock source accuracy

Hardware Troubleshooting Checklist

  • βœ“ Verify 120Ξ© termination resistors at both ends of CAN bus
  • βœ“ Check CAN_H voltage: 3.5V (recessive), 2.5V (dominant)
  • βœ“ Check CAN_L voltage: 1.5V (recessive), 2.5V (dominant)
  • βœ“ Measure differential voltage: ~0V (recessive), ~2V (dominant)
  • βœ“ Inspect for ground loops or poor grounding
  • βœ“ Verify twisted-pair cable for CAN_H/CAN_L
  • βœ“ Check maximum cable length for baud rate (40m @ 1Mbps, 1000m @ 50kbps)
  • βœ“ Confirm CAN transceiver is powered and not in standby mode
  • [CAN Tx] - Transmit CAN messages
  • [CAN Rx] - Receive CAN messages with filtering
  • [Digital Output] - Control CAN transceiver enable/standby pins
  • [Interrupt Config] - Advanced interrupt priority configuration

References

  • ISO 11898-1:2015 - Controller Area Network (CAN) specification
  • Bosch CAN FD Specification Version 1.0
  • SAM E70/S70/V70/V71 Datasheet ([DS60001527])
  • SAM E5x/D5x Family Datasheet ([DS60001507])
  • Application Note: CAN Bus Network Design and Troubleshooting

See Also

Datasheets