Q: How to implement CAN bus communication on STM32 with bxCAN or FDCAN?
Answer
The bxCAN peripheral on STM32F2xx/F4xx supports CAN 2.0A/B at up to 1 Mbps. Configure TX and RX pins with appropriate alternate functions. Set the baud rate: Baud = APB clock / (prescaler x (SJW + BS1 + BS2)). The APB bus clock must be at least 1 MHz for 1 Mbps operation. Use three transmit mailboxes with priority based on message ID. Configure two receive FIFOs with 3-message depth each and filter banks to accept only relevant IDs. For FDCAN (STM32G0/H7) use the new FDCAN API with 64-byte payload and bit-rate switching support. Always terminate the CAN bus with 120 Ohm at both ends.
Filed under: FAQ
