Home / Learn Chip Programming / STM32 CAN: Filters, Mailboxes and Bit Timing
STM32 CAN: Filters, Mailboxes and Bit Timing
Configure bxCAN or FDCAN with correct bit timing and acceptance filters.
In shortConfigure bxCAN or FDCAN with correct bit timing and acceptance filters.
Theory in plain words
What it is
The CAN peripheral has transmit mailboxes, receive FIFOs and acceptance filters. Bit timing comes from the prescaler and time segments BS1/BS2.
Why we use it
A wrong sample point gives errors. Without filters the CPU is flooded with every frame on the bus.
How it works
Bit rate = f_pclk / (prescaler x (1 + BS1 + BS2)). Aim for sample point 75 to 87.5 %. Filter by ID/mask to receive only needed messages.
Where it is used
- Car OBD-II reader
- Motor drive network
- Sensor nodes
Bit timing calculator
Find prescaler, BS1, BS2Try it Yourself
All nodes on a bus must use the same bit rate and similar sample points.
| Filter mode | Meaning | Example |
|---|---|---|
| ID mask | accept IDs where (id & mask) == value | accept 0x100..0x10F: value 0x100, mask 0x7F0 |
| ID list | accept only listed IDs | 0x123 and 0x456 |
| Accept all | mask = 0 | sniffer |
| Extended 29 bit | ID with IDE bit | J1939 trucks |
Careful:Always add a CAN transceiver (TJA1050/SN65HVD230). STM32 pins are logic level, not the CANH/CANL differential bus. 120 ohm termination at both ends.
Quick quiz
1. Sample point is best around...
Common recommendation for CAN.
2. Why filters?
Hardware filters discard others.