STM32 CAN濾波器設(shè)置 Identifier filter
對(duì)照下表:
本文引用地址:http://m.butianyuan.cn/article/201611/316410.htmExtended Id濾波器設(shè)置(已驗(yàn)證,只接受Receive_ID節(jié)點(diǎn)的數(shù)據(jù)):
/* CAN filter init */ //設(shè)置成只能接受主節(jié)點(diǎn) Extended Id:01 的數(shù)據(jù) reference manual p557
CAN_FilterInitStructure.CAN_FilterNumber=0;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
//CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdList;//###########################################
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh=(((u32)Receive_ID<<3)&0xFFFF0000)>>16;
CAN_FilterInitStructure.CAN_FilterIdLow=(((u32)Receive_ID<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0xFFFF;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0xFFFF; // 1 :must match” or 0: as “don’t care
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
Standard Id濾波器設(shè)置:
CAN_FilterMaskId 位的含義是
Mask
Each bit of the register specifies whether the bit of the associated identifier register must
match with the corresponding bit of the expected identifier or not.
0: Don’t care, the bit is not used for the comparison
1: Must match, the bit of the incoming identifier must have the same level has specified in
the corresponding identifier register of the filter.
我們這里全部設(shè)置成1 ,也就是只接受CAN_Filter中設(shè)置的節(jié)點(diǎn)的數(shù)據(jù)
評(píng)論