STM32 CAN总线应用程序,调试通过仅供参考(4)
- UID
- 1029342
- 性别
- 男
|
STM32 CAN总线应用程序,调试通过仅供参考(4)
6、中断接收函数
voidUSB_LP_CAN1_RX0_IRQHandler(void) //CAN中断函数
{
CanRxMsgRxMessage;
u8 i;
RxMessage.StdId=0x00; //初始化接收数据池
RxMessage.ExtId=0x00;
RxMessage.IDE=0;
RxMessage.DLC=0;
RxMessage.FMI=0;
RxMessage.Data[0]=0x00;
RxMessage.Data[1]=0x00;
RxMessage.Data[2]=0x00;
RxMessage.Data[3]=0x00;
RxMessage.Data[4]=0x00;
RxMessage.Data[5]=0x00;
RxMessage.Data[6]=0x00;
RxMessage.Data[7]=0x00;
//while(CAN_IT_FF0==0);
for(i=0;i<8;i++)
{
if(Can_Receive_Flag[i] == 0)
{
if(CAN_IT_FF0 >0)
{
CAN_Receive(CAN1, CAN_FIFO0,&RxMessage); //从CAN1口缓冲器FIFO 0接收报文到 RxMessage
CAN_Receive_data[i][0] =(RxMessage.StdId>>8)&0xff;
CAN_Receive_data[i][1] = (RxMessage.StdId)&0xff;
CAN_Receive_data[i][2] = RxMessage.Data[0];
CAN_Receive_data[i][3] = RxMessage.Data[1];
CAN_Receive_data[i][4] = RxMessage.Data[2];
CAN_Receive_data[i][5] = RxMessage.Data[3];
CAN_Receive_data[i][6] = RxMessage.Data[4];
CAN_Receive_data[i][7] = RxMessage.Data[5];
CAN_Receive_data[i][8] = RxMessage.Data[6];
CAN_Receive_data[i][9] = RxMessage.Data[7];
CAN_Receive_data[i][10] = 0xff;
Can_Receive_Flag[i] = 1;
break;
}
if(CAN_IT_FF1 > 0)
{
CAN_Receive(CAN1, CAN_FIFO1,&RxMessage); //从CAN1口缓冲器FIFO 0接收报文到 RxMessage
CAN_Receive_data[i][0] =(RxMessage.StdId>>8)&0xff;
CAN_Receive_data[i][1] = (RxMessage.StdId)&0xff;
CAN_Receive_data[i][2] = RxMessage.Data[0];
CAN_Receive_data[i][3] = RxMessage.Data[1];
CAN_Receive_data[i][4] = RxMessage.Data[2];
CAN_Receive_data[i][5] = RxMessage.Data[3];
CAN_Receive_data[i][6] = RxMessage.Data[4];
CAN_Receive_data[i][7] = RxMessage.Data[5];
CAN_Receive_data[i][8] = RxMessage.Data[6];
CAN_Receive_data[i][9] = RxMessage.Data[7];
CAN_Receive_data[i][10] = 0xff;
Can_Receive_Flag[i] = 1;
break;
}
}
}
CAN_ClearITPendingBit(CAN1, CAN_IT_FMP0);
}
附录:
接收与发送函数为目前项目中测试程序代码,根据实际情况可调整。 |
|
|
|
|
|