The CAN Rx block receives CAN messages from the CAN bus network and outputs the message ID, data length, and payload data. The block supports flexible message filtering with standard (11-bit) and extended (29-bit) identifiers, multiple filter types (exact match, range, mask), and configurable storage in dedicated buffers or FIFOs.
This block requires a CAN Config block in the same model to configure the CAN peripheral. Multiple CAN Rx blocks can be used to receive different messages on the same CAN module, each with its own filter configuration.
| Port Name | Data Type | Size | Description |
|---|---|---|---|
| MsgID | uint16 or uint32 | Scalar (1) | Received message identifier (uint16 for standard, uint32 for extended) |
| MsgLen | uint8 | Scalar (1) | Number of data bytes received (0-8 for CAN 2.0, 0-64 for CAN-FD) |
| Rx[N] | uint8 | Vector (1-64) | Received message data bytes |
| Parameter | Description | Valid Values | Default |
|---|---|---|---|
| CAN Module | Selects which CAN peripheral to use (must match CAN Config block) | CAN0, CAN1, MCAN0, MCAN1 (device-dependent) | CAN0 or MCAN0 |
| Parameter | Description | Valid Values | Default |
|---|---|---|---|
| Message Type | Identifier format to receive | Standard (11-bit ID), Extended (29-bit ID) | Standard |
| Filter Type | How to match incoming messages | Classic (Mask), Dual ID, Range | Classic |
| Parameter | Description | Valid Values | Default |
|---|---|---|---|
| Message ID | CAN identifier to match (hexadecimal) | 0x000-0x7FF (standard), 0x00000000-0x1FFFFFFF (extended) | 0x100 |
| Message ID Mask | Bitwise mask (1=must match, 0=don’t care) | 0x000-0x7FF (standard), 0x00000000-0x1FFFFFFF (extended) | 0x7FF (exact match) |
| Parameter | Description | Valid Values | Default |
|---|---|---|---|
| Message ID 1 | First CAN identifier to accept | 0x000-0x7FF (standard), 0x00000000-0x1FFFFFFF (extended) | 0x100 |
| Message ID 2 | Second CAN identifier to accept | 0x000-0x7FF (standard), 0x00000000-0x1FFFFFFF (extended) | 0x101 |
| Parameter | Description | Valid Values | Default |
|---|---|---|---|
| Message ID 1 (Min) | Minimum CAN identifier in range | 0x000-0x7FF (standard), 0x00000000-0x1FFFFFFF (extended) | 0x100 |
| Message ID 2 (Max) | Maximum CAN identifier in range | 0x000-0x7FF (standard), 0x00000000-0x1FFFFFFF (extended) | 0x10F |
| Parameter | Description | Options | Default |
|---|---|---|---|
| Data Store | Reception buffer type | RX FIFO 0, RX FIFO 1, Rx Buffer | RX FIFO 0 |
Tip: Use Rx Buffer for single high-priority messages that must never be lost. Use RX FIFO 0/1 for multiple messages of the same type that can be queued.
| Parameter | Description | Valid Values | Default |
|---|---|---|---|
| Data Type | Data output port type | uint8, uint16, uint32 | uint8 |
| Data Size | Size of data output port | 1-8 (CAN 2.0), 1-64 (CAN-FD) | 8 |
Compares incoming message ID with configured ID using bitwise AND with mask:
Filter Logic:
Accept if: (Incoming_ID & Mask) == (Filter_ID & Mask)
Example 1 - Exact Match:
Filter ID: 0x123
Mask: 0x7FF (all bits must match)
Accepts: 0x123 only
Rejects: 0x122, 0x124, all others
Example 2 - Partial Match:
Filter ID: 0x100
Mask: 0x7F0 (ignore lower 4 bits)
Accepts: 0x100, 0x101, 0x102...0x10F (16 IDs)
Rejects: 0x110, 0x0FF, all others
Example 3 - Don't Care Bits:
Filter ID: 0x200
Mask: 0x700 (only check upper 3 bits)
Accepts: 0x200-0x2FF (256 IDs)
Rejects: 0x100, 0x300, all others
Accepts messages matching either of two specific IDs:
Filter Logic:
Accept if: (Incoming_ID == ID1) OR (Incoming_ID == ID2)
Example:
ID1: 0x200
ID2: 0x300
Accepts: 0x200, 0x300 only
Rejects: All other IDs
Use Case:
- Two related messages to same processing
- Status from two different sources
- Command and acknowledgment pairing
Accepts any message ID within a specified range (inclusive):
Filter Logic:
Accept if: (ID1 <= Incoming_ID <= ID2)
Example:
ID1 (Min): 0x100
ID2 (Max): 0x10F
Accepts: 0x100, 0x101, 0x102...0x10F (16 IDs)
Rejects: 0x0FF, 0x110, all others
Use Case:
- Group of related sensors (0x200-0x20F)
- Module address range (0x300-0x3FF)
- Priority band filtering
When multiple filters are configured, the CAN controller processes them in order:
Incoming Message (ID: 0x105)
β
βΌ
βββββββββββββββββββ
β Standard Filters β (processed first)
β Filter 1: 0x100-0x10F (Range) β MATCH! β RX FIFO 0
β Filter 2: 0x105 (Exact) β (not checked, already matched)
βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β Extended Filters β (only if no standard match)
β Filter 3: ...
βββββββββββββββββββ
Result: Message accepted by Filter 1, stored in RX FIFO 0
| Feature | RX FIFO 0/1 | Rx Buffer |
|---|---|---|
| Storage Type | First-In-First-Out queue | Dedicated single message buffer |
| Capacity | Multiple messages (configured depth) | One message per buffer |
| Overflow Behavior | Newest message overwrites oldest (watermark) | New message rejected if not read |
| Use Case | Multiple messages of same type, bursty traffic | Single critical message, guaranteed delivery |
| Filter Sharing | Multiple filters can target same FIFO | One filter per buffer |
| Read Access | Sequential (FIFO order) | Direct (always latest) |
/* CAN Rx Implementation */
/* Extract message header */
msg->id = rxBuf->ID;
msg->extended = rxBuf->XTD;
msg->rtr = rxBuf->RTR;
msg->dlc = rxBuf->DLC;
/* Determine actual data length from DLC */
/* Copy data from buffer */
/* Get filter index that matched */
msg->filter_idx = rxBuf->FIDX;
/* Acknowledge reception */
### Filter Configuration (SAM E5x/C2x)
/* Standard ID Filter Setup */ void CAN_ConfigStandardFilter(uint8_t filterIdx, uint16_t id1, uint16_t id2, FilterType_t type,
/* Configure filter based on type */
case FILTER_DUAL:
filter->MCAN_SIDFE_0 =
MCAN_SIDFE_0_SFT(1) | // Dual ID filter
MCAN_SIDFE_0_SFID1(id1) | // First ID
MCAN_SIDFE_0_SFID2(id2) | // Second ID
MCAN_SIDFE_0_SFEC(action);
break;
case FILTER_CLASSIC:
filter->MCAN_SIDFE_0 =
MCAN_SIDFE_0_SFT(2) | // Classic filter
MCAN_SIDFE_0_SFID1(id1) | // Filter ID
MCAN_SIDFE_0_SFID2(id2) | // Mask
MCAN_SIDFE_0_SFEC(action);
break;
}
/* Flush cache to ensure filter is written */
SCB_CleanDCache_by_Addr((uint32_t*)filter, sizeof(*filter));
}
## Block Usage Examples
### Example 1: Single ID Reception
**Application:** Receive motor speed command (ID 0x100)
Simulink Model: CAN Rx (ID: 0x100) ββββββββββββ CAN Bus βββββββββββ MsgID ββββββ [Check ID = 0x100] β MsgLen ββββββ [Validate length] β Rx[8] ββββββ [speed_cmd, mode, …] ββββββββββββ
Configuration:
Filter Behavior: Accepts: ID 0x100 only Rejects: All other IDs
### Example 2: ID Range Reception
**Application:** Receive sensor data from multiple nodes (ID 0x200-0x20F)
Simulink Model: CAN Rx (ID: 0x200-0x20F) ββββββββββββ CAN Bus βββββββββββ MsgID ββββββ [Node ID = MsgID - 0x200] β MsgLen ββββββ [Validate] β Rx[4] ββββββ [temp, hum, pres, rsv] ββββββββββββ β βΌ βββββββββββββββ β Demux by ID β β (Switch) β βββββββββββββββ β β β β βΌ βΌ βΌ βΌ Node0…Node15
Configuration:
Filter Behavior: Accepts: 0x200, 0x201, 0x202…0x20F (16 IDs) Rejects: 0x1FF, 0x210, all others
### Example 3: Broadcast Reception
**Application:** Receive network-wide broadcast messages
Network Topology: ββββββββ ββββββββ ββββββββ ββββββββ βNode 1β βNode 2β βNode 3β βNode 4β βββββ¬βββ βββββ¬βββ βββββ¬βββ βββββ¬βββ ββββββββββββ΄βββββββββββ΄βββββββββββ CAN Bus (250 kbps)
Master broadcasts: ID 0x000 (time sync, emergency stop) All nodes receive using CAN Rx:
Configuration:
Broadcast Use Cases:
### Example 4: Multi-Filter Node
**Application:** Motor controller receiving commands and status
Motor Control Node: ββββββββββββββββββββββββββββββββββββββ β β β CAN Rx (0x100) β β β Motor Command β β [speed_setpoint][mode][enable] β β β β CAN Rx (0x200-0x20F) β β β Sensor Feedback Range β β [sensor_id][value][status] β β β β CAN Rx (0x000) β β β Emergency Broadcast β β [emergency_stop][reason] β β β ββββββββββββββββββββββββββββββββββββββ β² β CAN Bus
Filter Configuration (3 CAN Rx blocks):
Priority:
### Example 5: CAN-FD Reception (SAM E7x)
**Application:** Receive firmware update packets with 64-byte payload
Firmware Update Protocol: CAN Rx (CAN-FD) (ID: 0x500) ββββββββββββββββ CAN-FD Bus ββββββββ MsgID ββββββ 0x500 (update packet) (2 Mbps data) β MsgLen ββββββ 64 (bytes) β Rx[64] ββββββ [packet_data] ββββββββββββββββ β βΌ ββββββββββββββββ β Packet Parserβ β [seq][data] β ββββββββββββββββ
Configuration:
Performance:
## Troubleshooting
### Common Reception Issues
Missing CAN Config block in model
CAN module mismatch between Config and Rx blocks
Incorrect filter configuration (ID/mask mismatch)
No messages with matching ID on bus
Bus-off error state or physical connection issue
Solutions:
Verify CAN Config block exists and matches Rx block CAN module
Use CAN bus analyzer to confirm expected messages are present
Test with broadest filter first (mask=0x000, accept all)
Check filter type matches incoming message type (standard vs extended)
Verify bus termination and hardware connections
Cache coherency issues (ARM Cortex-M7 with DCache)
Data type mismatch between Tx and Rx
Buffer overrun (FIFO overflow)
Endianness mismatch (multi-byte values)
Solutions:
Place CAN buffers in non-cached memory (TCM) on SAM E7x
Use cache invalidate before reading (SCB_InvalidateDCache_by_Addr)
Ensure consistent data types across network nodes
Increase FIFO depth or use dedicated Rx buffer
Verify byte order for 16/32-bit values
Verify message type matches (standard vs extended ID)
Check mask calculation: 1=must match, 0=don't care
Test with exact match first (mask=0x7FF or 0x1FFFFFFF)
Verify ID1 β€ ID2 for range filters
Check for filter ordering conflicts (first match wins)
### FIFO Overflow Handling
| Issue | Symptom | Solution |
|---|---|---|
| Messages lost | Missing sequence numbers, gaps in data | Increase FIFO depth, reduce message rate, process faster |
| FIFO full error | Overflow interrupt, watermark exceeded | Monitor fill level, implement flow control |
| Old data received | Stale messages processed | Flush FIFO on overflow, timestamp validation |
| Unpredictable behavior | Intermittent message loss | Use dedicated buffer for critical messages |
### Debug Checklist
- β Verify CAN Config block present and configured correctly
- β Check CAN module selection matches between Config and Rx blocks
- β Confirm message type (standard/extended) matches filter configuration
- β Test filter with broadest setting first (accept all IDs)
- β Use CAN bus analyzer to verify transmitted messages
- β Check filter mask calculation (1=match, 0=ignore)
- β Verify data size matches expected message length
- β Monitor FIFO fill level for overflow conditions
- β Test with simple constant ID before complex filtering
- β Check cache coherency on ARM Cortex-M7 devices
## Filter Configuration Examples
### Common Filter Patterns
/* Example 1: Accept single ID (0x123) */ Message ID: 0x123 Mask: 0x7FF (all bits must match) Result: Accepts 0x123 only
/* Example 2: Accept range (0x100-0x10F) */ Filter Type: Range ID1 (Min): 0x100 ID2 (Max): 0x10F Result: Accepts 16 IDs from 0x100 to 0x10F
/* Example 3: Accept two specific IDs */ Filter Type: Dual ID1: 0x200 ID2: 0x300 Result: Accepts 0x200 or 0x300 only
/* Example 4: Accept group (0x200-0x2FF, ignore lower byte) */ Message ID: 0x200 Mask: 0x700 (check upper 3 bits only) Result: Accepts 0x200-0x2FF (256 IDs)
/* Example 5: Accept all (broadcast receiver) */ Message ID: 0x000 Mask: 0x000 (no bits need to match) Result: Accepts all IDs (0x000-0x7FF)
## Related Blocks
- [CAN Config] - Configure CAN peripheral and buffers
- [CAN Tx] - Transmit CAN messages
- [Digital Output] - Control CAN transceiver enable pins
- [Interrupt Config] - Configure CAN reception interrupts
## References
- ISO 11898-1:2015 - CAN Protocol Specification
- Bosch CAN FD Specification Version 1.0
- [SAM E70/S70/V70/V71 Family Datasheet (DS60001527)] - MCAN Module
- [SAM E5x/D5x Family Datasheet (DS60001507)] - CAN Module
- Application Note: CAN Message Filtering and Buffer Management (search [Microchip Portal])
- Application Note: CAN-FD Implementation and Migration (search [Microchip Portal])
## See Also
### Datasheets
- [SAM E70/S70/V70/V71 Family Datasheet (DS60001527)](https://www.microchip.com/DS60001527)
- [SAM E5x/D5x Family Datasheet (DS60001507)](https://www.microchip.com/DS60001507)
### Other
- [Microchip Portal](https://www.microchip.com/en-us/search)
- [Microchip Portal](https://www.microchip.com/en-us/search)