您的位置 首页 模拟

STM32 CAN滤波器设置 Identifier filter

stm32的屏蔽滤波功能对ID是有要求的,mpc2515你可以直接写ID,但在STM32这里ID必须进行移位处理.对照下表:ExtendedId滤波器设置(已验证…

stm32的屏蔽滤波功能对ID是有要求的,mpc2515你能够直接写ID,但在STM32 这儿ID有必要进行移位处理.

对照下表:

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);

Standard Id滤波器设置:

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中设置的节点的数据

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/moni/273019.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部