STM32bxCAN设置Filter指向不同FIFO不成功,请指点!

SPEED   2010-6-23 19:56 楼主
贴代码:
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,发现不能正常收发数据,那位朋友设置过,希望指点一二!

回复评论 (4)

                                 你先不设置过滤器试试,看能不能接受数据
点赞  2010-6-23 21:24
我不设置过滤可是收到数据,第一个过滤也可以收到数据
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0;这样也可以收到数据,但是
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO1;就不可以收到数据!
点赞  2010-6-24 07:28
                                 会不会你把你要收的ID给滤掉了
点赞  2010-6-24 08:51
                                 应该还是过滤器的设置有问题
点赞  2010-6-24 09:03
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复