当前位置:网站首页>Filter setting of can
Filter setting of can
2022-07-20 12:29:00 【Xiao AI Kun who likes code】
CAN Node passing ID Filtering can selectively receive messages ,stm32 Of CAN The filter has two modes : List mode and mask mode .
(1) List mode
List mode only receives those that meet the specified ID Frame of , Save the specified ID Use 2 individual 32 Bit register , It is divided into 16 Bit mode and 32 Bit mode .
16 Bit list mode one ID Occupy 16 position , A coexistence 4 individual 16 position ID, Usually used for standard frames , Standard frame ID Deposit in 16 The height of a bit 11 position , Extended frames can only be saved 15~17 Yu low 3 position , The other two save RTR and IDE position , Respectively represent standard frames (0)/ Extended frames (1), Data frame (0)/ Remote control frame (1)
32 Bit list mode one ID Occupy 32 position , A coexistence 2 individual 32 position ID, Usually used to extend frames , Extended frame ID Deposit in 32 High bit register 29 position , in addition 3 Bits are stored separately IDE,RTR and 0.
// Initialize filter ------16 Bit list mode
CAN_FilterInitStruct.CAN_FilterActivation = ENABLE;// Enable filter
CAN_FilterInitStruct.CAN_FilterFIFOAssignment = CAN_Filter_FIFO0;// Install the filter to FIFO0
CAN_FilterInitStruct.CAN_FilterMode = CAN_FilterMode_IdList;// Filter mode --- list
CAN_FilterInitStruct.CAN_FilterNumber = 0;// filter 0
CAN_FilterInitStruct.CAN_FilterScale = CAN_FilterScale_16bit;// Filter length
// Provide two standard frames ID 0x123 , 0x321; Provide two masks 0x7af,0x000
CAN_FilterInitStruct.CAN_FilterIdHigh = 0x123<<5;
CAN_FilterInitStruct.CAN_FilterIdLow = 0x321<<5;
CAN_FilterInitStruct.CAN_FilterMaskIdHigh = 0x7af<<5;
CAN_FilterInitStruct.CAN_FilterMaskIdLow = 0x000;
CAN_FilterInit(&CAN_FilterInitStruct);
// Initialize filter ------16 Bit mask mode
CAN_FilterInitStruct.CAN_FilterActivation = ENABLE;// Enable filter
CAN_FilterInitStruct.CAN_FilterFIFOAssignment = CAN_Filter_FIFO0;// Install the filter to FIFO0
CAN_FilterInitStruct.CAN_FilterMode = CAN_FilterMode_IdList;// Filter mode --- list
CAN_FilterInitStruct.CAN_FilterNumber = 0;// filter 0
CAN_FilterInitStruct.CAN_FilterScale = CAN_FilterScale_16bit;// Filter length
// Provide a standard frame ID 0x6789abc,0xcba9876
//ID high 16 position
CAN_FilterInitStruct.CAN_FilterIdHigh = 0x6789abc>>13;
//ID low 13 Put high position ,IDE-1
CAN_FilterInitStruct.CAN_FilterIdLow = (0x6789abc<<5)& 0xffff | (0x1)<<2;
//ID high 16 position
CAN_FilterInitStruct.CAN_FilterMaskIdHigh = 0xcba9876>>13;
//ID low 13 Put high position ,IDE-1
CAN_FilterInitStruct.CAN_FilterMaskIdLow = (0xcba9876<<3)& 0xffff | (0x1)<<2;
CAN_FilterInit(&CAN_FilterInitStruct);
(2) Mask mode
Mask mode only receives frames that meet the mask requirements , One 32 Bit register storage ID, One 32 Bit register storage mask , Also divided into 16 Bit mode and 32 Bit mode .
Only the first register corresponds to 1 You need to match for .
// Initialize filter ------16 Bit mask mode
CAN_FilterInitStruct.CAN_FilterActivation = ENABLE;// Enable filter
CAN_FilterInitStruct.CAN_FilterFIFOAssignment = CAN_Filter_FIFO0;// Install the filter to FIFO0
CAN_FilterInitStruct.CAN_FilterMode = CAN_FilterMode_IdMask;// Filter mode --- list
CAN_FilterInitStruct.CAN_FilterNumber = 0;// filter 0
CAN_FilterInitStruct.CAN_FilterScale = CAN_FilterScale_16bit;// Filter length
// Provide two standard frames ID 0x123 , 0x321; Provide two masks 0x0f0,0xf0f0
CAN_FilterInitStruct.CAN_FilterIdHigh = 0x123<<5;
CAN_FilterInitStruct.CAN_FilterIdLow = 0x321<<5;
CAN_FilterInitStruct.CAN_FilterMaskIdHigh = 0x0f0<<5;
CAN_FilterInitStruct.CAN_FilterMaskIdLow = ((0xcba9876<<3) & 0xffff)|(0x1<<2);
CAN_FilterInit(&CAN_FilterInitStruct);
Please try setting CN Bus filter 32 Bit mode
边栏推荐
- Gauss mathematics -- watching animation and Learning Mathematical Olympiad
- Win7 process command
- Vs2017 opencv3.4.2 is compiled into x86 through the release version source code
- 【微信小程序】checkbox复选框(89/100)
- 广州证券开户安不安全?
- 【sklearn报错解决方案】UndefinedMetricWarning: Precision is ill-defined and being set to 0.0
- SylixOS TCP 数据段发送流程简述
- 【微信小程序】Button(90/100)
- Fault 006: connection sorting and de duplication results are not as good as people want
- 为什么 PSP22 对 Polkadot 生态系统很重要
猜你喜欢
What is the gold content of PMP certificate? Is it worth taking the exam?
Comparison of gold content between PRINCE2 and PMP
Yunna FSU dynamic loop monitoring unit, what is FSU dynamic loop monitoring unit
ES6练习
[nightsafe AI] create the NFT digital art collection you want in one minute
Read the paper: (yolov1) you only look once:unified, real time object detection
Hcia-r & s self use notes (11) VRP file system, system management
[solution] the Monaco editor in leetcode cannot be loaded
【无标题】
What network models does neural network include? Basic principles of neural network model
随机推荐
DOM introduction and acquisition of DOM series
新蓝海“硬防晒”,千亿市场“遮不住”了
【延期至12月】2022年网络安全国际研讨会(CSW2022)
数据库优化方式和问题汇总篇
一台好的产品需要「情绪价值」
为什么 PSP22 对 Polkadot 生态系统很重要
[wechat applet] button (90/100)
Spec206 detailed parameters and summary of common problems in the test process (with example operation)
【微信小程序】input输入框(87/100)
[exception] exception resolution article format
DOM events of DOM series
ES6 adds (I) let and constant
出于对员工人身安全的担忧 星巴克未来可能关闭更多美国门店
CorelDRAWX8试用到期了怎么免费使用?cdrX8
Pyqt5 learning resource preparation and environment configuration
【微信小程序】Button(90/100)
Dynamic ring monitoring module, dynamic ring monitoring module classification
Weekly recommended short videos: put forward higher requirements for the elastic computing power of cloud computing
[applet] what is a small game?
Reasons why crontab cannot execute scripts and Solutions