贴代码:
Filter代码:
//CAN过滤器设置
CAN_FilterInitStructure.CAN_FilterNumber=0;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh=(((u32)CAN_ID<<3)&0xFFFF0000)>>16;
CAN_FilterInitStructure.CAN_FilterIdLow= (((u32)CAN_ID<<3)&0xFFFF);
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0xFFFF;
CAN_FilterInitStructure.CAN_FilterMaskIdLow= 0xFFF8;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber=1;
CAN_FilterInitStructure.CAN_FilterIdHigh=(((u32)CAN_ID1<<3)&0xFFFF0000)>>16;
CAN_FilterInitStructure.CAN_FilterIdLow= (((u32)CAN_ID1<<3)&0xFFFF);
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0xFFFF;
CAN_FilterInitStructure.CAN_FilterMaskIdLow= 0xFFF8;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO1;
CAN_FilterInit(&CAN_FilterInitStructure);
/*允许FMP0中断*/
CAN_ITConfig(CAN1,CAN_IT_FMP0|CAN_IT_FMP1, ENABLE);
}
中断函数:
void USB_LP_CAN1_RX0_IRQHandler(void)
{
CanRxMsg RxMessage;
CAN_Receive(CAN1,CAN_FIFO0, &RxMessage);
CAN_Receive(CAN1,CAN_FIFO1, &RxMessage);
if((RxMessage.Data[0]==0x11)&&(RxMessage.Data[1]==0x22)&&(RxMessage.Data[2]==0x33)&&(RxMessage.Data[3]==0x44))
{
Receive_flag=1;
}
if((RxMessage.Data[0]==0x88)&&(RxMessage.Data[1]==0x77)&&(RxMessage.Data[2]==0x66)&&(RxMessage.Data[3]==0x55))
{
Receive_flag1=1;
}
}
过滤器分别指向了FIIO0和FIFO1,发现不能正常收发数据,那位朋友设置过,希望指点一二! |