【STM32FXXX|STM32f107 CAN滤波器设置】STM32f107 CAN滤波器设置
F107有CAN1、CAN2两路,其滤波设置类似
stm32f10x系列CAN滤波器:
两种模式:列表模式、屏蔽位模式
有分组**,*CAN1:0->13组,CAN2:14->28组;
滤波器组时间是***同或***关系
以下只讨论屏蔽位模式、扩展帧滤波器
u32 ID1=0x10203008;
//此ID与实际传输ID存在右移3位的关系,即实际传输ID为0x02040601
u32 ID2=0x50607008;
/
//CAN1
/
CAN_FilterInitStructure.CAN_FilterNumber=0;
//滤波器0组
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
//屏蔽位模式
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
//滤波器32位
CAN_FilterInitStructure.CAN_FilterIdHigh= (ID1&0xFFFF0000)>>16;
//取ID1高四位0x1020
CAN_FilterInitStructure.CAN_FilterIdLow= (ID1|CAN_ID_EXT)&0xFFFF;
//取ID1低四位0x3008
CAN_FilterInitStructure.CAN_FilterMaskIdHigh= 0x00FF;
//高四位 ,FF为必须匹配,即收到的帧ID必须为0x0020
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0;
//低四位
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FilterFIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber=1;
//滤波器1组
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
//屏蔽位模式
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
//滤波器32位
CAN_FilterInitStructure.CAN_FilterIdHigh= (ID2&0xFFFF0000)>>16;
//取ID1高四位0x5060
CAN_FilterInitStructure.CAN_FilterIdLow= (ID2|CAN_ID_EXT)&0xFFFF;
//取ID1低四位0x7008
CAN_FilterInitStructure.CAN_FilterMaskIdHigh= 0xFFFF;
//高四位 ,FF为必须匹配,即收到的帧ID必须为0x5060
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0;
//低四位
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FilterFIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
/
//CAN2
/
CAN_FilterInitStructure.CAN_FilterNumber=14;
//滤波器14组
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
//屏蔽位模式
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
//滤波器32位
CAN_FilterInitStructure.CAN_FilterIdHigh= (ID1&0xFFFF0000)>>16;
//取ID1高四位0x1020
CAN_FilterInitStructure.CAN_FilterIdLow= (ID1|CAN_ID_EXT)&0xFFFF;
//取ID1低四位0x3008
CAN_FilterInitStructure.CAN_FilterMaskIdHigh= 0x00FF;
//高四位 ,FF为必须匹配,即收到的帧ID必须为0x0020
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0;
//低四位
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FilterFIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber=15;
//滤波器15组
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
//屏蔽位模式
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
//滤波器32位
CAN_FilterInitStructure.CAN_FilterIdHigh= (ID2&0xFFFF0000)>>16;
//取ID1高四位0x5060
CAN_FilterInitStructure.CAN_FilterIdLow= (ID2|CAN_ID_EXT)&0xFFFF;
//取ID1低四位0x7008
CAN_FilterInitStructure.CAN_FilterMaskIdHigh= 0xFFFF;
//高四位 ,FF为必须匹配,即收到的帧ID必须为0x5060
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0;
//低四位
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FilterFIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
l