FDCAN配置 主要是标准帧滤波器, 扩展帧滤波器设置, 开启新消息接收中断, 开启Bus-Off中断, 设置发送传输延时补偿等. FDCAN_FilterTypeDef sFilterConfig1;
void fdcan1_config(void) { sFilterConfig1.IdType = FDCAN_STANDARD_ID; sFilterConfig1.FilterIndex = 0; sFilterConfig1.FilterType = FDCAN_FILTER_RANGE; sFilterConfig1.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; sFilterConfig1.FilterID1 = 0x00; sFilterConfig1.FilterID2 = 0x7FF; if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig1) != HAL_OK) { Error_Handler(); }
sFilterConfig1.IdType = FDCAN_EXTENDED_ID; sFilterConfig1.FilterIndex = 0; sFilterConfig1.FilterType = FDCAN_FILTER_RANGE; sFilterConfig1.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; sFilterConfig1.FilterID1 = 0x00; sFilterConfig1.FilterID2 = 0x1FFFFFFF; if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig1) != HAL_OK) { Error_Handler(); }
/* Configure global filter on both FDCAN instances: Filter all remote frames with STD and EXT ID Reject non matching frames with STD ID and EXT ID */ if (HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK) { Error_Handler(); }
/* Activate Rx FIFO 0 new message notification on both FDCAN instances */ if (HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK) { Error_Handler(); }
if (HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_BUS_OFF, 0) != HAL_OK) { Error_Handler(); }
/* Configure and enable Tx Delay Compensation, required for BRS mode. TdcOffset default recommended value: DataTimeSeg1 * DataPrescaler TdcFilter default recommended value: 0 */ HAL_FDCAN_ConfigTxDelayCompensation(&hfdcan1, hfdcan1.Init.DataPrescaler * hfdcan1.Init.DataTimeSeg1, 0); HAL_FDCAN_EnableTxDelayCompensation(&hfdcan1);
HAL_FDCAN_Start(&hfdcan1); }
|