我想使用
STM32F042 从 CAN 总线接收消息,但我遇到了问题,因为中断不起作用。
我可以毫无问题地发送消息,问题只在于接收。
我已经设置了过滤器,如下所示(目前我想在不过滤的情况下接收来自 CAN 总线的所有消息):
- HAL_CAN_ConfigFilter(&hcan,&canfil); //Initialize CAN Filter
- HAL_CAN_Start(&hcan); //Initialize CAN Bus
- HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO0_MSG_PENDING);// Initialize
- canfil.FilterBank = 0;
- canfil.FilterMode = CAN_FILTERMODE_IDMASK;
- canfil.FilterFIFOAssignment = CAN_RX_FIFO0;
- canfil.FilterIdHigh = 0;
- canfil.FilterIdLow = 0;
- canfil.FilterMaskIdHigh = 0;
- canfil.FilterMaskIdLow = 0;
- canfil.FilterScale = CAN_FILTERSCALE_32BIT;
- canfil.FilterActivation = ENABLE;
- canfil.SlaveStartFilterBank = 14;
当中断被触发时,我想运行这段代码:
- void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan1)
- {
- HAL_CAN_GetRxMessage(hcan1, CAN_RX_FIFO0, &rxHeader, canRX); //Receive CAN bus message to canRX buffer
- HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_0);// toggle PA0 LED
- HAL_UART_Transmit(&huart2, canRX, 8, 1000);
- HAL_UART_Transmit(&huart2, "n",1, 1000);
- }
我可以从哪里开始搜索问题?我确定
HAL_CAN_RxFifo0MsgPendingCallback 中断代码没有运行,因为我用调试器检查过它。我已经
通过 EXTI 线 27 启用了 HDMI-CEC 和 CAN 全局中断/HDMI 唤醒中断,但它没有帮助。