大神们好,我先说下我的环境,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
");
}
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
");
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
{
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
}
}
一周热门 更多>