canfd-transmit.ino
Configures the FDCAN2 controller to send periodic frames via the integrated transceiver.
Uses FDCAN2 connected to the TCAN3403-Q1 with 120Ω termination. Ensure FDCAN2 TX/RX pins are correctly mapped in CubeMX. Classic mode is used here for compatibility, but FD mode is supported by the hardware.
canfd-transmit.ino
#include "stm32c5xx_hal.h"
FDCAN_HandleTypeDef hfdcan2;
FDCAN_FilterTypeDef sFilterConfig;
FDCAN_TxHeaderTypeDef TxHeader;
uint8_t TxData[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
int main(void) {
HAL_Init();
// Init FDCAN2 (connecté au TCAN3403)
hfdcan2.Instance = FDCAN2;
hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1;
hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; // Ou FDCAN_FRAME_FD_BRS pour FD
hfdcan2.Init.Mode = FDCAN_MODE_NORMAL;
// ... configuration timing ...
HAL_FDCAN_Init(&hfdcan2);
HAL_FDCAN_Start(&hfdcan2);
TxHeader.Identifier = 0x123;
TxHeader.IdType = FDCAN_STANDARD_ID;
TxHeader.TxFrameType = FDCAN_DATA_FRAME;
TxHeader.DataLength = 8;
TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
TxHeader.FDFormat = FDCAN_CLASSIC_CAN;
TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
TxHeader.MessageMarker = 0;
while(1) {
HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan2, &TxHeader, TxData);
HAL_Delay(1000);
}
}