嗨,我正在尝试在 CAN 总线上进行
通信,我之前已经成功地使用
STM32F103C8 和 STM32F091RC 进行了通信,但我无法使其在 STM32F407VET 上工作它不会触发消息接收中断。这个 MCU 有什么不同?我需要启用不同的功能吗?
MCU时钟168Mhz,APB1 42Mhz,CAN BUS速度为100000bit/s,在NVIC中启用“CAN1 RX0中断”,代码:
- hcan1.Instance = CAN1;
- hcan1.Init.Prescaler = 28;
- hcan1.Init.Mode = CAN_MODE_NORMAL;
- hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
- hcan1.Init.timeSeg1 = CAN_BS1_12TQ;
- hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;
- hcan1.Init.TimeTriggeredMode = DISABLE;
- hcan1.Init.AutoBusOff = ENABLE;
- hcan1.Init.AutoWakeUp = DISABLE;
- hcan1.Init.AutoRetransmission = DISABLE;
- hcan1.Init.ReceiveFifoLocked = DISABLE;
- hcan1.Init.TransmitFifoPriority = DISABLE;
- if (HAL_CAN_Init(&hcan1) != HAL_OK)
- {
- Error_Handler();
- }
- CAN_FilterTypeDef sFilterConfig;
- sFilterConfig.FilterBank = 0;
- sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
- sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
- sFilterConfig.FilterIdHigh = 0x0000;
- sFilterConfig.FilterIdLow = 0x0000;
- sFilterConfig.FilterMaskIdHigh = 0x0000;
- sFilterConfig.FilterMaskIdLow = 0x0000;
- sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
- sFilterConfig.FilterActivation = ENABLE;
- sFilterConfig.SlaveStartFilterBank = 14;
- if (HAL_CAN_ConfigFilter(hcan1, &sFilterConfig) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_CAN_Start(hcan1) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_CAN_ActivateNotification(hcan1, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)
- {
- Error_Handler();
- }
我期待得到回调:
- void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
- {
- }
但它从未执行过。我试图设置断点,但它并没有在那里刹车:
- /**
- * @brief This function handles CAN1 RX0 interrupts.
- */
- void CAN1_RX0_IRQHandler(void)
- {
- /* USER CODE BEGIN CAN1_RX0_IRQn 0 */
- /* USER CODE END CAN1_RX0_IRQn 0 */
- HAL_CAN_IRQHandler(&hcan1);
- /* USER CODE BEGIN CAN1_RX0_IRQn 1 */
- /* USER CODE END CAN1_RX0_IRQn 1 */
- }
可能是什么问题呢?
我不知道接下来要解决什么问题。