打印
[STM32F1]

CAN如何设置标准帧

[复制链接]
582|13
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
juventus9554|  楼主 | 2021-11-21 15:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
CAN如何设置标准帧

使用特权

评论回复
沙发
heweibig| | 2021-11-21 15:15 | 只看该作者

楼主程序可以公开吗?贴程序看下吧,这么说看不出什么原因

使用特权

评论回复
板凳
juventus9554|  楼主 | 2021-11-21 15:15 | 只看该作者
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=0x0000;
          CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;
          CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000;//32位MASK
          CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;
          CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_Filter_FIFO0;//过滤器0关联到FIFO0
        CAN_FilterInitStructure.CAN_FilterActivation=ENABLE; //激活过滤器0

          CAN_FilterInit(&CAN_FilterInitStructure);//滤波器初始化

求教:假如我想设置标准帧的ID为0x56C,应该怎么设置CAN_FilterInitStructure.CAN_FilterIdHigh和dCAN_FilterInitStructure.CAN_FilterIdLow 的值 ?

使用特权

评论回复
地板
zhenykun| | 2021-11-21 15:17 | 只看该作者
这个得要自己配,对着手册来。

使用特权

评论回复
5
zwll| | 2021-11-21 15:20 | 只看该作者
https://mp.weixin.qq.com/s?__biz=MzA3OTIxMjQyNQ==&mid=2650948053&idx=1&sn=df92efcd987372bf480708074aed6d17&chksm=84401b33b3379225ecfb9c17e7c1f2051f5c09a78dc93ca2b959ab8e09eac423ed3bf8ad1f82&token=318093403&lang=zh_CN#rd

使用特权

评论回复
6
dingy| | 2021-11-21 15:23 | 只看该作者
手册上写的挺清楚的

使用特权

评论回复
7
lizye| | 2021-11-21 15:31 | 只看该作者

或者用代码生成工具

使用特权

评论回复
8
spark周| | 2021-11-21 15:34 | 只看该作者
对着寄存器说明自己设置是一样的

使用特权

评论回复
9
wangzsa| | 2021-11-21 15:36 | 只看该作者
默认的就是标准帧吧

使用特权

评论回复
10
zhenykun| | 2021-11-21 15:38 | 只看该作者
是的  无需设置 默认的就是

使用特权

评论回复
11
yszong| | 2021-11-21 15:42 | 只看该作者
这里的CAN_FilterId和CAN_FilterMaskId是配合使用的,意思是CAN_FilterId指出需要屏蔽ID的什么内容,什么格式;CAN_FilterMaskId是指CAN_FilterId的每一位是否需要过滤,若CAN_FilterMaskId在某位上是1的话,ID对应位上的数值就必须和CAN_FilterId该位上的一样,保持一致,反之则是“不关心”。

使用特权

评论回复
12
juventus9554|  楼主 | 2021-11-21 15:44 | 只看该作者

嗯,那我按大家的说法挨个排查一下,谢谢哈

使用特权

评论回复
13
_L_D_H_| | 2021-11-22 14:30 | 只看该作者
/********************************************************************************************************************************************************************************************
**函数名称:                CanSetRxFilter       
**函数功能:       
**入口参数:
**返回参数:
*********************************************************************************************************************************************************************************************/
void CanSetRxFilter(BYTE num,UINT32 FilterID1,UINT32 FilterID2)
{
        CAN_FilterInitTypeDef  CAN_FilterInitStructure;
        CAN_FilterInitStructure.CAN_FilterNumber = num;
        CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdList;
        CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
        printf("\r\n num: %d FilterID1: %08x FilterID2: %08x",num,FilterID1,FilterID2);
        if(FilterID1 > 0x800)
        {
               
                CAN_FilterInitStructure.CAN_FilterIdHigh=((FilterID1 << 3 )>> 16) & 0xffff;
                CAN_FilterInitStructure.CAN_FilterIdLow=((FilterID1 << 3)& 0xffff) | CAN_ID_EXT;
        }
        else
        {
                CAN_FilterInitStructure.CAN_FilterIdHigh = FilterID1 << 5;
                CAN_FilterInitStructure.CAN_FilterIdLow = 0|CAN_ID_STD;
        }


        if(FilterID2 > 0x800)
        {
               
                CAN_FilterInitStructure.CAN_FilterMaskIdHigh=((FilterID2 << 3 )>> 16) & 0xffff;
                CAN_FilterInitStructure.CAN_FilterMaskIdLow=((FilterID2 << 3)& 0xffff) | CAN_ID_EXT;
        }
        else
        {
                CAN_FilterInitStructure.CAN_FilterMaskIdHigh = FilterID2 << 5;
                CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0|CAN_ID_STD;
        }

       
        CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0;
        CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
       
        CAN_FilterInit(&CAN_FilterInitStructure);
}       

使用特权

评论回复
14
_L_D_H_| | 2021-11-22 14:32 | 只看该作者
兼容过滤标准帧和扩展帧

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

900

主题

12190

帖子

3

粉丝