您的位置 首页 模拟

STM32单片机的can总线的装备

STM32单片机的can总线的配置-CAN_InitStructure.CAN_TTCM=DISABLE;//禁止时间触发通信模式

CAN_InitStructure.CAN_ABOM=DISABLE;

CAN_InitStructure.CAN_AWUM=DISABLE;

CAN_InitStructure.CAN_NART=DISABLE;//CAN报文只被发送1次,不管发送的结果如何(成功、出错或仲裁丢失)

CAN_InitStructure.CAN_RFLM=DISABLE;

CAN_InitStructure.CAN_TXFP=DISABLE;

CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;

STM32can总线的装备如下:

CAN_InitStructure.CAN_TTCM=DISABLE;//制止时刻触发通讯形式

CAN_InitStructure.CAN_ABOM=DISABLE;

CAN_InitStructure.CAN_AWUM=DISABLE;

CAN_InitStructure.CAN_NART=DISABLE;//CAN报文只被发送1次,不论发送的成果怎么(成功、犯错或裁定丢掉)

CAN_InitStructure.CAN_RFLM=DISABLE;

CAN_InitStructure.CAN_TXFP=DISABLE;

CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;

STM32单片机的can总线的装备

//CAN_Mode_LoopBack

//CAN_Mode_Normal

CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;

CAN_InitStructure.CAN_BS1=CAN_BS1_5tq;//1–16

CAN_InitStructure.CAN_BS2=CAN_BS2_2tq;//1–8

CAN_InitStructure.CAN_Prescaler=2;

CAN_Init(&CAN_InitStructure);

/* CAN filter init */

CAN_FilterInitStructure.CAN_FilterNumber=0;//挑选过滤器0

CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;//指定过滤器被设置为标识符屏蔽形式

CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;//给出过滤器位宽为32位

下面依据设置的参数不同来决议can总线can总线的装备状况:

1、对扩展数据帧进行过滤:(只接纳扩展数据帧)

CAN_FilterInitStructure.CAN_FilterIdHigh = (((u32)slave_id《《3)&0xFFFF0000)》》16;

CAN_FilterInitStructure.CAN_FilterIdLow = (((u32)slave_id《《3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;

CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0xFFFF;

CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0xFFFF;

(注:规范帧数据帧、规范长途帧和扩展长途帧均被过滤)

2、对扩展长途帧过滤:(只接纳扩展长途帧)

CAN_FilterInitStructure.CAN_FilterIdHigh = (((u32)slave_id《《3)&0xFFFF0000)》》16;

CAN_FilterInitStructure.CAN_FilterIdLow = (((u32)slave_id《《3)|CAN_ID_EXT|CAN_RTR_REMOTE)&0xFFFF;

CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0xFFFF;

CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0xFFFF;

3、对规范长途帧过滤:(只接纳规范长途帧)

CAN_FilterInitStructure.CAN_FilterIdHigh = (((u32)slave_id《《21)&0xffff0000)》》16;

CAN_FilterInitStructure.CAN_FilterIdLow = (((u32)slave_id《《21)|CAN_ID_STD|CAN_RTR_REMOTE)&0xffff;

CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0xFFFF;

CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0xFFFF;

4、对规范数据帧过滤:(只接纳规范数据帧)

CAN_FilterInitStructure.CAN_FilterIdHigh = (((u32)slave_id《《21)&0xffff0000)》》16;

CAN_FilterInitStructure.CAN_FilterIdLow = (((u32)slave_id《《21)|CAN_ID_STD|CAN_RTR_DATA)&0xffff;

CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0xFFFF;

CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0xFFFF;

5、对扩展帧进行过滤:(扩展帧不会被过滤掉)

CAN_FilterInitStructure.CAN_FilterIdHigh = (((u32)slave_id《《3)&0xFFFF0000)》》16;

CAN_FilterInitStructure.CAN_FilterIdLow = (((u32)slave_id《《3)|CAN_ID_EXT)&0xFFFF;

CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0xFFFF;

CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0xFFFC;

6、对规范帧进行过滤:(规范帧不会被过滤掉)

CAN_FilterInitStructure.CAN_FilterIdHigh = (((u32)slave_id《《21)&0xffff0000)》》16;

CAN_FilterInitStructure.CAN_FilterIdLow = (((u32)slave_id《《21)|CAN_ID_STD)&0xffff;

CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0xFFFF;

CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0xFFFC;

注:slave_id为要过滤的id号。

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

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

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

微信扫一扫关注我们

返回顶部