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

CAN bit timeSync seg 1 tqProp+BS1sample pointBS2
CAN bit time

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 modeMeaningExample
ID maskaccept IDs where (id & mask) == valueaccept 0x100..0x10F: value 0x100, mask 0x7F0
ID listaccept only listed IDs0x123 and 0x456
Accept allmask = 0sniffer
Extended 29 bitID with IDE bitJ1939 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...

2. Why filters?