Overview

The CAN (Controller Area Network) block family enables robust, multi-master communication on CAN bus networks. CAN is widely used in automotive, industrial automation, and embedded systems for reliable data exchange in electrically noisy environments.

The MCHP Blockset provides three blocks for CAN communication: CAN Config for peripheral setup, CAN Tx for message transmission, and CAN Rx for message reception with flexible filtering. These blocks support both CAN 2.0 (standard) and CAN-FD (flexible data-rate) protocols.

CAN Protocol Features

  • Multi-master architecture: Any node can initiate communication
  • Message prioritization: Lower IDs have higher priority (automatic arbitration)
  • Error detection: CRC, ACK, frame check, bit monitoring, bit stuffing
  • Fault confinement: Automatic bus-off recovery and error counting
  • Deterministic: Guaranteed message latency based on priority
  • Flexible data rates: CAN 2.0 up to 1 Mbps, CAN-FD up to 8 Mbps (data phase)

Available Blocks

CAN Config

Configures the CAN peripheral including bit timing (baud rate), message buffer allocation, and pin assignments. This block is required before using CAN Tx or CAN Rx blocks.

Key Parameters:

  • Baud rate (50 kbps to 1 Mbps)
  • Bit timing (auto-calculated)
  • CAN-FD support (SAM devices)
  • Buffer allocation (auto-configured) [View Documentation →]

CAN Tx

Transmits CAN messages on the bus with configurable ID, data length, and priority. Supports standard (11-bit) and extended (29-bit) identifiers, RTR frames, and both FIFO and buffer modes.

Key Parameters:

  • Message ID (standard/extended)
  • Data size (0-8 bytes CAN, 0-64 bytes CAN-FD)
  • Transmission mode (FIFO/buffer)
  • RTR support [View Documentation →]

CAN Rx

Receives CAN messages with flexible filtering options. Supports exact match, range, and mask-based filters for both standard and extended IDs. Configurable storage in FIFOs or dedicated buffers.

Key Parameters:

  • Filter type (classic/dual/range)
  • Message ID and mask
  • Buffer mode (FIFO/dedicated)
  • Data size configuration [View Documentation →]

Block Selection Guide

When to Use Each Block

TaskBlock to UseConfiguration Notes
Initialize CAN peripheralCAN ConfigRequired first step - one per CAN module
Send periodic sensor dataCAN Tx(FIFO mode)
Send critical commandCAN Tx(buffer mode)
Receive specific messageCAN Rx(exact filter)
Receive message groupCAN Rx(range filter)
Receive broadcastCAN Rx(mask filter)

Device Family Support

Device FamilyCAN TypeMax ModulesCAN-FDMax Baud RateStatus
SAM E70/S70/V70/V71MCAN (Bosch M_CAN)2✓ Yes1 Mbps (nominal), 8 Mbps (data)Supported
SAM E5x (E51/E53/E54)CAN2✓ Yes1 Mbps (nominal), 5 Mbps (data)Supported
SAM C20/C21CAN2✓ Yes1 Mbps (nominal), 5 Mbps (data)Supported
SAM D51CAN2✓ Yes1 Mbps (nominal), 5 Mbps (data)Supported
dsPIC30F/33FECAN1-2✗ No1 MbpsFuture
dsPIC33E/PIC24EECAN1-2✗ No1 MbpsFuture
dsPIC33C/CH/CKCAN-FD (select models)1-2Device-dependent1-5 MbpsFuture
PIC32MX/MZCAN1-2✗ No1 MbpsFuture

Typical CAN Network Example

CAN Network Topology (250 kbps):

┌─────────────┐         ┌─────────────┐         ┌─────────────┐
│  Master ECU │         │ Motor Node  │         │ Sensor Node │
│             │         │             │         │             │
│ CAN Config  │         │ CAN Config  │         │ CAN Config  │
│ CAN Tx      │         │ CAN Rx      │         │ CAN Tx      │
│ CAN Rx      │         │ CAN Tx      │         │ CAN Rx      │
└─────┬───────┘         └─────┬───────┘         └─────┬───────┘
      │                       │                       │
    ──┴───────────────────────┴───────────────────────┴──
      CAN_H ────────────────────────────────────────────
      CAN_L ────────────────────────────────────────────
      │                                                 │
    [120Ω]                                           [120Ω]
    Termination                                   Termination

Message Flow:
  Master → All:    ID 0x000 (broadcast commands)
  Master → Motor:  ID 0x100 (speed setpoint)
  Motor → Master:  ID 0x200 (status feedback)
  Sensor → All:    ID 0x300 (sensor data)

Priority Order (Lower ID = Higher Priority):
  0x000: Highest (emergency broadcast)
  0x100: High (motor control)
  0x200: Medium (status)
  0x300: Lower (sensor data)

CAN vs CAN-FD Comparison

FeatureCAN 2.0CAN-FD
Maximum Data Bytes8 bytes64 bytes
Bit RateUp to 1 Mbps (fixed)Up to 1 Mbps (arbitration), up to 8 Mbps (data)
Protocol Overhead~47 bits (8 bytes data)~64 bits (64 bytes data)
Throughput (1 Mbps)~8 kB/sec~40 kB/sec (at 5 Mbps data phase)
Error Detection15-bit CRC17/21-bit CRC (enhanced)
CompatibilityUniversalBackward compatible during arbitration
Use CasesGeneral control, periodic dataFirmware updates, diagnostics, high-speed logging

Getting Started

Quick Setup (3 Steps)

  • Add CAN Config Block

  • Drag from MCHP Blockset → BUS CAN → CAN_Config

  • Select CAN module (CAN0/CAN1/MCAN0/MCAN1)

  • Choose baud rate (e.g., 250000 for 250 kbps)

  • Assign RX/TX pins

  • Add CAN Tx Block (Optional)

  • Drag from MCHP Blockset → BUS CAN → CAN_Tx

  • Set message ID (e.g., 0x100)

  • Configure data size (e.g., 8 bytes)

  • Connect MsgLen and Tx data inputs

  • Add CAN Rx Block (Optional)

  • Drag from MCHP Blockset → BUS CAN → CAN_Rx

  • Set message ID and filter (e.g., 0x200, mask 0x7FF)

  • Configure data size (e.g., 8 bytes)

  • Use MsgID, MsgLen, and Rx data outputs

Best Practice: Start with a simple loopback test (one Tx, one Rx, same ID) to verify CAN peripheral configuration before building complex networks.

Common Use Cases

1. Motor Control Network

Application: Distributed motor control with central controller

  • Master sends speed commands (ID 0x100-0x10F, one per motor)
  • Motors respond with status (ID 0x200-0x20F)
  • Emergency stop broadcast (ID 0x000)
  • Baud rate: 500 kbps, update rate: 100 Hz

2. Sensor Data Acquisition

Application: Multiple sensors reporting to data logger

  • Each sensor transmits with unique ID (0x300-0x3FF)
  • Logger uses range filter (0x300-0x3FF) to receive all
  • Timestamp included in message payload
  • Baud rate: 250 kbps, periodic transmission (10-50 Hz)

3. Firmware Updates (CAN-FD)

Application: Over-the-air firmware update via CAN-FD

  • Update packets with 64-byte payload (ID 0x500)
  • Acknowledgment messages (ID 0x501)
  • Data phase at 2-5 Mbps for fast transfer
  • CRC verification and retry mechanism

Troubleshooting Guide

ProblemPossible CauseSolution
No communicationMissing CAN Config blockAdd CAN Config block, verify CAN module matches
Baud rate errorsIncorrect bit timingUse standard baud rates, verify clock frequency
Messages not receivedFilter misconfiguredStart with exact match (mask=0x7FF), test with analyzer
Bus-off stateMissing termination or noiseCheck 120Ω resistors at both ends, inspect cabling
Data corruptionCache coherency (ARM)Use non-cached memory or cache maintenance functions
  • [UART Communication Blocks] - Serial communication alternative
  • [SPI Communication Blocks] - High-speed synchronous communication
  • [I2C Communication Blocks] - Multi-device bus communication
  • [Digital I/O Blocks] - CAN transceiver control

References

  • ISO 11898-1:2015 - Road vehicles — Controller area network (CAN)
  • Bosch CAN FD Specification Version 1.0
  • [SAM E70/S70/V70/V71 Family Datasheet (DS60001527)] - MCAN Peripheral
  • [SAM E5x/D5x Family Datasheet (DS60001507)] - CAN Peripheral
  • Application Note: CAN Network Design and Best Practices (search [Microchip Portal])
  • Application Note: CAN-FD Migration Guide (search [Microchip Portal])

See Also

Datasheets

Other