现象描述: 现象一、基于STM32F103C8T6单机CAN接收板,当CAN接收板与CAN分析仪连接通讯时,分析仪一帧一帧的发送数据给CAN接收板,CAN接收板能正确接收并解析出ID及数据;
现象二、当CAN接收板与汽车上的OBD连接时,接收板只能接收少数几个(4个)ID数据帧。
产生现象二是由什么原因造成的呢。已经试过利用滤波器滤出自己需要的10个ID数据帧,但是CAN接收板还是只能接收到汽车OBD上固定的ID数据帧,请教各位大侠遇到过这种情况没呢?或者看看错误出现在什么地方呢?谢谢各位了。
CAN收发器电路图:
[img]file:///C:UsersAdministratorDocumentsTencent Files780501415ImageC2C\_DB`P[FAZ_R`I[$[url=mailto
@ZTZ932.png]D@ZTZ932.png[/url][/img]
CAN配置代码如下:
u32 std_id1=0X728,std_id2=0X621,std_id3=0X392,std_id4=0X390,std_id5=0X470,std_id6=0X50,std_id7=0X280,std_id8=0X320,std_id9=0X729,std_id10=0X570;//滤波ID
void Configure_CAN_OBD(void)
{
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
/* CAN register init */
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
/* CAN cell init */
CAN_InitStructure.CAN_TTCM=DISABLE;
CAN_InitStructure.CAN_ABOM=ENABLE;
CAN_InitStructure.CAN_AWUM=ENABLE;
CAN_InitStructure.CAN_NART=DISABLE;
CAN_InitStructure.CAN_RFLM=DISABLE;
CAN_InitStructure.CAN_TXFP=DISABLE;
CAN_InitStructure.CAN_Mode=CAN_Mode_Silent;//CAN_Mode_Normal;//;CAN_Mode_LoopBack//
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1=CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2=CAN_BS2_2tq;
CAN_InitStructure.CAN_Prescaler=12;
CAN_Init(CAN1,&CAN_InitStructure);
CAN_FilterInitStructure.CAN_FilterNumber=1;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdList;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh=std_id1<<5;
CAN_FilterInitStructure.CAN_FilterIdLow=0|CAN_ID_STD;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=std_id2<<5;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0|CAN_ID_STD;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber=2;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdList;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh=std_id3<<5;
CAN_FilterInitStructure.CAN_FilterIdLow=0|CAN_ID_STD;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=std_id4<<5;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0|CAN_ID_STD;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber=3;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdList;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh=std_id5<<5;
CAN_FilterInitStructure.CAN_FilterIdLow=0|CAN_ID_STD;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=std_id6<<5;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0|CAN_ID_STD;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber=4;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdList;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh=std_id7<<5;
CAN_FilterInitStructure.CAN_FilterIdLow=0|CAN_ID_STD;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=std_id8<<5;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0|CAN_ID_STD;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber=5;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdList;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh=std_id9<<5;
CAN_FilterInitStructure.CAN_FilterIdLow=0|CAN_ID_STD;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=std_id10<<5;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0|CAN_ID_STD;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
/* CAN FIFO0 message pending interrupt enable */
CAN_ITConfig(CAN1,CAN_IT_FMP0, ENABLE);
}
//CAN接收中断服务函数
u32 x0,x1,x2,x3,x4,x5,x6,x7;
u32 y1;
void USB_LP_CAN1_RX0_IRQHandler(void)
{
CAN_ClearITPendingBit(CAN1, CAN_IT_FMP0);
CAN_Receive(CAN1, CAN_FIFO0, &RxMessage); //′óCAN2¿ú»o3åÆ÷FIFO 0½óêÕ±¨ÎÄμ½RxMessage
x0=RxMessage.Data[0];
x1=RxMessage.Data[1];
x2=RxMessage.Data[2];
x3=RxMessage.Data[3];
x4=RxMessage.Data[4];
x5=RxMessage.Data[5];
x6=RxMessage.Data[6];
x7=RxMessage.Data[7];
y1=RxMessage.StdId;
CAN_FIFORelease(CAN1,CAN_FIFO0); //ÇåÖD¶Ï½óêÕ±êÖ¾
}
原子哥有没有遇到这种情况呢?从你的角度上面考虑,是硬件方面的还是软件上面的问题呢?
一周热门 更多>