大神们好,我先说下我的环境,keil 5, cubemx,其中在使用can中断接收HAL_CAN_Receive_IT时发现,如果单纯接收的话,是没有问题的, 但是如果接收和发送同时开启的时候,就经常会调用HAL_CAN_Receive_IT函数失败,后面就没法再接收了,不知道是什么问题,会不会是hal库的bug? 我看例程里是在回调中调用下一次中断接收的,也就这样做了,回调函数如下: void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan) { if(hcan->Instance == CAN2) { g_bcan_rx_flag = 1; osSemaphoreRelease(BcanBinarySemHandle); if(HAL_OK != HAL_CAN_Receive_IT(&hcan2, CAN_FIFO0)) { printf("bx IT error\n"); } return ; } if(hcan->Instance == CAN1) { osSemaphoreRelease(PcanBinarySemHandle); g_pcan_rx_flag = 1; if(HAL_OK != HAL_CAN_Receive_IT(&hcan1, CAN_FIFO0)) //__HAL_CAN_ENABLE_IT(hcan, CAN_IT_FMP0); { printf("px IT error\n"); } } } |
if(HAL_OK != HAL_CAN_Receive_IT(&hcan2, CAN_FIFO0))
{
printf("bx IT error\n");
} 这个经常出错,导致没办法继续接收can包
评分
查看全部评分
但是如果接收和发送同时开启的时候,就经常会调用HAL_CAN_Receive_IT函数失败,后面就没法再接收了,不知道是什么问题,求解答!!!
{
if(hcan->pRxMsg->IDE == CAN_ID_STD)
{
u32CanId = hcan->pRxMsg->StdId;
}
else
{
u32CanId = hcan->pRxMsg->ExtId;
}
osSemaphoreRelease(PcanBinarySemHandle);
g_pcan_rx_flag = 1;
//============================================
if (HAL_CAN_Receive_IT(&hcan1, CAN_FIFO0) != HAL_OK)
{
/* Reception Error */
__HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_FMP0);// set interrupt flag for RX FIFO0 if CAN locked
}
}