[应用相关] STM32 CAN滤波器设置 Identifier filter

[复制链接]
 楼主| 过期的塔头 发表于 2021-7-23 23:33 | 显示全部楼层 |阅读模式
stm32的屏蔽滤波功能对ID是有要求的,mpc2515你可以直接写ID,但在STM32 这里ID必须进行移位处理.
 楼主| 过期的塔头 发表于 2021-7-23 23:34 | 显示全部楼层
对照下表: 8539860fae16d6245c.png
 楼主| 过期的塔头 发表于 2021-7-23 23:34 | 显示全部楼层
Extended Id滤波器设置(已验证,只接受Receive_ID节点的数据):

/* CAN filter init */ //设置成只能接受主节点 Extended Id:01 的数据 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);
 楼主| 过期的塔头 发表于 2021-7-23 23:35 | 显示全部楼层
Standard Id滤波器设置: 4583560fae1a44fd54.png
 楼主| 过期的塔头 发表于 2021-7-23 23:36 | 显示全部楼层
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.

我们这里全部设置成1 ,也就是只接受CAN_Filter中设置的节点的数据
您需要登录后才可以回帖 登录 | 注册

本版积分规则

85

主题

999

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部

85

主题

999

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部