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.
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:
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:
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:
| Task | Block to Use | Configuration Notes |
|---|---|---|
| Initialize CAN peripheral | CAN Config | Required first step - one per CAN module |
| Send periodic sensor data | CAN Tx | (FIFO mode) |
| Send critical command | CAN Tx | (buffer mode) |
| Receive specific message | CAN Rx | (exact filter) |
| Receive message group | CAN Rx | (range filter) |
| Receive broadcast | CAN Rx | (mask filter) |
| Device Family | CAN Type | Max Modules | CAN-FD | Max Baud Rate | Status |
|---|---|---|---|---|---|
| SAM E70/S70/V70/V71 | MCAN (Bosch M_CAN) | 2 | ✓ Yes | 1 Mbps (nominal), 8 Mbps (data) | Supported |
| SAM E5x (E51/E53/E54) | CAN | 2 | ✓ Yes | 1 Mbps (nominal), 5 Mbps (data) | Supported |
| SAM C20/C21 | CAN | 2 | ✓ Yes | 1 Mbps (nominal), 5 Mbps (data) | Supported |
| SAM D51 | CAN | 2 | ✓ Yes | 1 Mbps (nominal), 5 Mbps (data) | Supported |
| dsPIC30F/33F | ECAN | 1-2 | ✗ No | 1 Mbps | Future |
| dsPIC33E/PIC24E | ECAN | 1-2 | ✗ No | 1 Mbps | Future |
| dsPIC33C/CH/CK | CAN-FD (select models) | 1-2 | Device-dependent | 1-5 Mbps | Future |
| PIC32MX/MZ | CAN | 1-2 | ✗ No | 1 Mbps | Future |
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)
| Feature | CAN 2.0 | CAN-FD |
|---|---|---|
| Maximum Data Bytes | 8 bytes | 64 bytes |
| Bit Rate | Up 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 Detection | 15-bit CRC | 17/21-bit CRC (enhanced) |
| Compatibility | Universal | Backward compatible during arbitration |
| Use Cases | General control, periodic data | Firmware updates, diagnostics, high-speed logging |
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.
Application: Distributed motor control with central controller
Application: Multiple sensors reporting to data logger
Application: Over-the-air firmware update via CAN-FD
| Problem | Possible Cause | Solution |
|---|---|---|
| No communication | Missing CAN Config block | Add CAN Config block, verify CAN module matches |
| Baud rate errors | Incorrect bit timing | Use standard baud rates, verify clock frequency |
| Messages not received | Filter misconfigured | Start with exact match (mask=0x7FF), test with analyzer |
| Bus-off state | Missing termination or noise | Check 120Ω resistors at both ends, inspect cabling |
| Data corruption | Cache coherency (ARM) | Use non-cached memory or cache maintenance functions |