🛠 Log CAN FD Data on XIAO STM32C5

Seeed Studio XIAO STM32C5 · intermediaire · Configurez le bus CAN FD pour capturer et stocker des trames de données sur le stockage externe de la carte.

Objectives

This tutorial aims to configure the integrated CAN FD controller (FDCAN2) of the XIAO STM32C5 to receive data frames and log them to the 16 MB external flash memory. You will learn how to initialize the CAN bus, manage interrupts, and use the file system for persistent storage.

Required Hardware

Steps

  1. Project Initialization: Create a new project in STM32CubeIDE by selecting the STM32C5A3CG microcontroller. Enable the 48 MHz external clock to ensure the timing accuracy required by CAN FD.
  1. FDCAN2 Configuration: In the device configurator, enable FDCAN2. Note that the TCAN3403-Q1 transceiver is already connected with a 120 Ω termination resistor. Configure the bus speed (e.g., 500 kbps for arbitration, 2 Mbps for data) and enable receive interrupts.
  1. External Memory Management: The board features 16 MB of external flash. Configure the corresponding QSPI or SPI driver in the code to access this memory. Initialize a simple file system (like LittleFS) to structure data into files.
  1. Reception and Storage Code: Implement the CAN interrupt callback function. Upon each received frame, read the ID and data. Write this information to a text or binary file on the external flash. Ensure you add a timestamp for each entry.
  1. Compilation and Upload: Compile the project and upload it to the board via the USB-C port. Open the serial monitor to verify debug messages indicating successful CAN and file system initialization.

Verification

Connect a CAN device to the FDCAN2 bus. Send data frames. Check on the serial monitor that frames are detected. Use a file read command to confirm that data is persisted in external memory after a board restart.

Going Further

Explore using the LSM6DS3TR-C inertial sensor to enrich CAN data with motion measurements. Activate the PWM-programmable heating circuit to stabilize measurements before logging them, creating a high-precision logbook.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials