当前位置:网站首页>Can filter
Can filter
2022-04-23 18:22:00 【Things will turn when they reach the extreme 1024】
CAN filter
1、 Configure the filter so that the filter group works in initialization mode , Enter normal mode after configuration
CAN1->FMR|=1<<0; // Filter bank 0 Working in initialization mode
//CAN1->FMR|=1<<n; // Filter bank n Working in initialization mode
/*... To configure */
CAN1->FMR&=0<<0; // Filter bank 0 Enter normal mode
//CAN1->FMR&=0<<n; // Filter bank n Enter normal mode
2、 When configuring a filter, it is also necessary to turn off the activation of the filter
CAN1->FA1R&=~(1<<0); // filter 0 Do not activate
//CAN1->FA1R&=~(1<<n); // filter n Do not activate
CAN1->FA1R|=1<<0; // Activate the filter 0
//CAN1->FA1R|=1<<n; // Activate the filter n
3、 Set the filter bit width , Yes 32 Bit and 16 Two modes , This affects the later filtering and shielding ID length
CAN1->FS1R|=1<<0; // filter 0 The seat width is 32 position
CAN1->FS1R&=~(1<<0); // filter 0 The seat width is 16 position
CAN1->FS1R|=1<<n; // filter n The seat width is 32 position
CAN1->FS1R&=~(1<<n); // filter n The seat width is 16 position
STID standard ID
EXID Expand ID
IDE
RTR
32 Bit mode
CAN_FxR1[31:21] | CAN_FxR1[20:3] | CAN_FxR1[2] | CAN_FxR1[1] | CAN_FxR1[0] |
---|---|---|---|---|
CAN_FxR2[31:21] | CAN_FxR2[20:3] | CAN_FxR2[2] | CAN_FxR2[1] | CAN_FxR2[0] |
STID[10:0] | EXID[17:0] | IDE | RTR | 0 |
16 Bit mode
CAN_FxR1[15:5] | CAN_FxR1[4] | CAN_FxR1[3] | CAN_FxR1[2:0] |
---|---|---|---|
CAN_FxR1[31:21] | CAN_FxR1[20] | CAN_FxR1[19] | CAN_FxR1[18:16] |
CAN_FxR2[15:5] | CAN_FxR2[4] | CAN_FxR2[3] | CAN_FxR2[2:0] |
CAN_FxR2[31:21] | CAN_FxR2[20] | CAN_FxR2[19] | CAN_FxR2[18:16] |
STID[10:0] | IDE | RTR | EXID[17:15] |
4、 Set the filter operating mode , Identifier mask bit mode and identifier list mode
CAN1->FM1R&=~(1<<0); // filter 0 Working in identifier mask bit mode
CAN1->FM1R|=1<<0; // filter 0 Working in identifier list mode
CAN1->FM1R&=~(1<<n); // filter n Working in identifier mask bit mode
CAN1->FM1R|=1<<n; // filter n Working in identifier list mode
5、 Filter associated to FIFOn n=0,1
CAN1->FFA1R&=~(1<<0); // filter 0 Related to FIFO0
CAN1->FFA1R|=1<<0; // filter 0 Related to FIFO1
CAN1->FFA1R&=~(1<<n); // filter n Related to FIFO0
CAN1->FFA1R|=1<<n; // filter n Related to FIFO1
6、 Set filtering rules
CAN1->sFilterRegister[0].FR1=0x21<<21;//32 position ID
CAN1->sFilterRegister[0].FR2=(0x7F<<21);//32 position MASK
Identifier pattern
Each of the registers corresponds to the level of the corresponding bit of the desired identifier .
0: It is expected that the corresponding bit is dominant ;
1: The corresponding bit is expected to be recessive .
Mask bit mode
Each bit of the register indicating whether the corresponding identifier register bit must be consistent with the corresponding bit of the desired identifier .
0: No concern , This bit is not used for comparison ;
1: Must match , The incoming identifier bit must be consistent with the identifier register bit corresponding to the filter
The identifier pattern is FR2 by 1 The bit of identifies the bit to be verified ,FR1 Explain what the identified bit must be , That is, a filter, a rule , The logic here is similar to & operation
CAN1->sFilterRegister[0].FR1=0x21<<21;//32 position ID
CAN1->sFilterRegister[0].FR2=(0x7F<<21);//32 position MASK
// Means to check SDID Standard frame ID The lower seven of , The lower seven must be 0x21 To pass
Mask bit mode Is to specify a specific one ID,ID All bits of must conform to the set value
CAN1->sFilterRegister[0].FR1=0x21<<21;//32 position ID
CAN1->sFilterRegister[0].FR2=0xFF<<21)//32 position MASK
// Only 0x00 and 0xFF It can be filtered
Program routine
void CAN_Set_Filter(u8 Addr)
{
Addr=Addr&0x7F;
// Filter initialization
CAN1->FMR|=1<<0; // The filter group works in initialization mode
/* Filtering rules 1 CAN ID The lower seven digits of must be the same as Addr Agreement , Others don't care */
CAN1->FA1R&=~(1<<0); // filter 0 Do not activate
CAN1->FS1R|=1<<0; // The filter bit width is 32 position .
CAN1->FM1R|=0<<0; // filter 0 Working in identifier mask bit mode
//CAN1->FM1R|=1<<0; // filter 0 Working in identifier list mode
CAN1->FFA1R|=0<<0; // filter 0 Related to FIFO0
CAN1->sFilterRegister[0].FR1=Addr<<21;//32 position ID
CAN1->sFilterRegister[0].FR2=(0x7F<<21);//32 position MASK
CAN1->FA1R|=1<<0; // Activate the filter 0
/* Filtering rules 2 CAN ID Of the 7 Bit must be 1, That is, only 0x80 Can pass */
CAN1->FA1R&=~(1<<1); // filter 1 Do not activate
CAN1->FS1R|=1<<1; // filter 1 The seat width is 32 position .
//AN1->FM1R|=0<<1; // filter 1 Working in identifier mask bit mode
CAN1->FM1R|=1<<1; // filter 1 Working in identifier list mode
CAN1->FFA1R|=0<<1; // filter 1 Related to FIFO0
CAN1->sFilterRegister[1].FR1=0x80<<21;//32 position ID
CAN1->sFilterRegister[1].FR2=(0x80<<21);//32 position MASK
CAN1->FA1R|=1<<1; // Activate the filter 1
/* Filtering rules 3 CAN ID The lower eight digits of must be 0x00*/
CAN1->FA1R&=~(1<<2); // filter 2 Do not activate
CAN1->FS1R|=1<<2; // filter 2 The seat width is 32 position .
CAN1->FM1R|=0<<2; // filter 2 Working in identifier mask bit mode
//CAN1->FM1R|=1<<2; // filter 2 Working in identifier list mode
CAN1->FFA1R|=0<<2; // filter 2 Related to FIFO0
CAN1->sFilterRegister[2].FR1=0x00<<21;//32 position ID
CAN1->sFilterRegister[2].FR2=(0xFF<<21);//32 position MASK
CAN1->FA1R|=1<<2; // Activate the filter 2
CAN1->FMR&=0<<0; // The filter bank enters normal mode
}
版权声明
本文为[Things will turn when they reach the extreme 1024]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210610057105.html
边栏推荐
- Pointers in rust: box, RC, cell, refcell
- Realization of consumer gray scale
- Software test summary
- 【ACM】376. 摆动序列
- Mode of interprocess communication
- Stm32mp157 wm8960 audio driver debugging notes
- Daily CISSP certification common mistakes (April 15, 2022)
- 【ACM】70. climb stairs
- Feign requests the log to be printed uniformly
- QT add external font ttf
猜你喜欢
STM32学习记录0008——GPIO那些事1
C medium? This form of
Qt读写XML文件(含源码+注释)
Custom prompt box MessageBox in QT
解决报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
Stm32mp157 wm8960 audio driver debugging notes
Robocode tutorial 5 - enemy class
由tcl脚本生成板子对应的vivado工程
【ACM】376. Swing sequence
JD-FreeFuck 京东薅羊毛控制面板 后台命令执行漏洞
随机推荐
Solution to Chinese garbled code after reg file is imported into the registry
【ACM】70. 爬楼梯
C language to achieve 2048 small game direction merging logic
Gobang game based on pyGame Library
【ACM】455. Distribute Biscuits (1. Give priority to big biscuits to big appetite; 2. Traverse two arrays with only one for loop (use subscript index -- to traverse another array))
Daily CISSP certification common mistakes (April 18, 2022)
The vivado project corresponding to the board is generated by TCL script
ArcGIS license error -15 solution
CISSP certified daily knowledge points (April 18, 2022)
Imx6 debugging LVDS screen technical notes
Matlab tips (6) comparison of seven filtering methods
Pyppeter crawler
What are the relationships and differences between threads and processes
Crawling mobile game website game details and comments (MQ + multithreading)
7-21 wrong questions involve knowledge points.
SQL database syntax learning notes
QT notes on qmap container freeing memory
Daily CISSP certification common mistakes (April 13, 2022)
Closure type of rust (difference between FN, fnmut and fnone)
Function recursion and solving interesting problems