STM32 CAN bus identifier filter difficulty analysis

Publisher:HappyHeartedLatest update time:2017-09-22 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

CAN bus is a bus with many applications at present. It is widely used in automotive electronics and aerospace. The blogger uses the STM32 development board of the battleship. I won’t talk about the introduction and functional characteristics of CAN. They are all in books and on the Internet. Please understand the characteristics and functions of the CAN bus protocol before reading this article. Today, the blogger will learn with you how to use the CAN bus identifier filter (very important!)
      Please read this paragraph carefully (from the STM32 Chinese reference manual): In the CAN protocol, the identifier of the message does not represent the address of the node, but is related to the content of the message. Therefore, the sender sends the message to all receivers in the form of broadcast. When receiving the message, the node determines whether the software needs the message based on the value of the identifier; if it needs it, it will be copied to SRAM; if it does not need it, the message will be discarded without software intervention. In the STM32F103ZET6 chip, the bxCAN controller provides 14 variable-width, configurable filter groups (13~0) for the application to accept only those messages required by the software. Hardware filtering saves CPU overhead, otherwise it must be filtered by software, which will occupy a certain amount of CPU overhead. Each filter group x consists of two 32-bit registers, CAN_FxR0 and CAN_FxR1.

      Some readers may think, what are messages, identifiers, filters? What is the connection between them? These questions show that you will understand. Don't worry, listen to me slowly~~~
      Filter: The filter is used when receiving, and there is no need to configure the filter when sending! The filter will decide whether the node wants the message sent by the sender based on the identifier. In layman's terms: If it is what I want, I want it; if it is not what I want, I don't want it. Message

      : Message (MESSAGE) is the data unit exchanged and transmitted in the network, that is, the data block to be sent by the station at one time. The message contains the complete data information to be sent, the length is inconsistent, and the length is unlimited and variable. Note (here is the key point!): Message is also the unit of network transmission. During the transmission process, it will be continuously encapsulated into groups, packets, and frames for transmission. The encapsulation method is to add some information segments, which are the data organized in a certain format by the message header.

      Here is one more thing to add: the message transmission on the CAN bus is represented and controlled by 4 different frame types. 1. Data frame 2. Remote frame 3. Error frame 4. Overload frame. Read on:

  • When transmitting messages, different frames have different transmission structures (for example, a data frame consists of 7 segments: frame start, arbitration segment, control end, data segment, CRC segment, ACK segment, and frame end). Only when the frame is transmitted strictly according to the structure of the frame can it be correctly received and sent by the node.

  • In addition, there are two formats in the data frame and remote control frame: standard format and extended format. The standard format has an 11-bit identifier, and the extended format has a 29-bit identifier. As shown in the following figure:


      Identifiers: Identifiers mainly include the following, which can also be understood as only containing ID numbers, but here all of the following are to be included:

  •       1 32-bit filter, including: STDID[10:0], EXTID[17:0], IDE and RTR bits

  •       2 16-bit filters including: STDID[10:0], IDE, RTR, and EXTID[17:15] bits

      For example, in data frames and remote frames, identifiers are included, and data frames and remote frames are a type of message representation. Therefore, after the sender sends frame data to the receiver, the receiver will filter it based on the identifier and decide whether to accept it or not.

      After reading the above three definitions, there should be no problem looking back at the above paragraph~

      The following focuses on filters:

      STM32 provides two filter modes for users to choose, mask bit mode (identifier mask bit mode) and identifier list mode.


Mask bit pattern:

      In the mask bit mode, the identifier register and the mask register together specify whether any bit of the message identifier should be treated as "must match" or "don't care".

Identifier list mode:

      In the identifier list mode, the mask register is also used as the identifier register. Therefore, instead of using one identifier plus one mask bit, two identifier registers are used. Every bit of the received message must be the same as the filter identifier.

      The identifier list mode is easy to understand: it means that all bits of the filter register are used for filtering, that is, all bits of the identifier sent by the sender must be exactly the same as those defined in the filter register of the receiver. If there is one bit that is different, the message will be rejected!

      The mask bit pattern is a little more complicated, but it is also easy to understand: for a simple example, our filter group 0 works in: 1 32-bit filter-identifier mask mode, and then set CAN_F0R1=0XFFFF0000, CAN_F0R2=0XFF00FF00. Among them, the value stored in CAN_F0R1 is the ID expected to be received, that is, the image we hope to receive (STID+EXTID+IDE+RTR) is preferably: 0XFFFF0000. And 0XFF00FF00 is to set the ID that we must care about, indicating that the received image, its 16 bits [31:24] and [15:8] must be exactly the same as the corresponding bits in CAN_F0R1, and the other 16 bits do not need to be concerned about, they can be the same or different, and they are all considered to be the correct ID, that is, the received image must be 0XFFxx00xx to be correct (x means don't care). In other words, the value in the mask bit (CAN_F0R2):

      1: Must match, the incoming identifier bit must be consistent with the identifier register bit corresponding to the filter.

      0: Don’t care, can be the same or different, both are considered to be correct IDs

therefore:

      To filter out a group of identifiers, the filter group should be set to work in mask bit mode

      To filter out an identifier, you should set the filter group to work in identifier list mode.

Note: Filter groups not used by the application should be kept in disabled mode. (This is easy to understand)
Finally, regarding the CAN sending and receiving process, you can refer to the flowchart in the manual, which is very detailed.


Keywords:STM32 Reference address:STM32 CAN bus identifier filter difficulty analysis

Previous article:Touch screen learning notes based on STM32
Next article:Brief Analysis of the Principle of Dual-machine Communication Based on Serial Port RS485 in STM32

Recommended ReadingLatest update time:2024-11-16 12:55

STM32 GPIO related registers (Part 2)
STM32 microcontrollers can only communicate with the outside world if they have ports. Only by learning how to control ports can we make better use of peripherals, establish connections with the outside world, and give full play to our own advantages.          First, let's introduce the basic GPIO related registers:
[Microcontroller]
Key points of using STM32 IAP (online update program)
The so-called IAP is actually equivalent to a small bootloader used to update the program. Many products are basically programmed once on the production line, but BUGs are sometimes unavoidable. There are often painful experiences where the product has to be removed from the shell and the board and put back on the pro
[Microcontroller]
Key points of using STM32 IAP (online update program)
STM32 11 days to burn Chinese character library and display it on LCD
First use PCToLCD2002 to generate the Chinese font library, select all files, and select GBK.bin   #include "stm32f10x.h" //Contains STM32 registers and variable types   #include "stm32f10x_conf.h" //Includes the library function.h   #include "led.h"   #include "key.h"   #include "delay.h"   #include
[Microcontroller]
ucgui Chinese character library is stored in external flash (controls are available) and external FLASH software is written
Recently, I used several fonts in my project, and the internal flash of stm32 was running out of money. I had no choice but to look for help from Baidu and experts in the group. I would like to express my gratitude to Eric2013  , Yangyangkanworld and other experts. I learned some of their ideas. Here are the relevant
[Microcontroller]
ucgui Chinese character library is stored in external flash (controls are available) and external FLASH software is written
Introduction to three BOOT modes of STM32
1. Introduction to three BOOT modes The so-called boot, generally speaking, means that after we download the program and restart the chip, the value of the BOOT pin will be latched at the fourth rising edge of SYSCLK. Users can select the boot mode after reset by setting the state of the BOOT1 and BOOT0 pins. Main F
[Microcontroller]
Introduction to three BOOT modes of STM32
STM32 enter and exit sleep mode routine
    1. Design requirements     The system is required to enter and exit sleep mode as follows: 2 seconds after the system starts, configure the RTC to generate an alarm event after 3 seconds, and then use the WFI instruction to put the system into stop mode. If you want to wake up the system to normal mode, you can pr
[Microcontroller]
STM32: GPIO basics and corresponding pin operation library functions
USE_STDPERIPH_DRIVER, STM32F10X_HD The English abbreviations of the startup files in the STM32 firmware library Libraries\CMSIS\Core\CM3\startup\arm mean: cl: interconnected product, stm32f105/107 series vl: value product, stm32f100 series xl: ultra-high density (capacity) product, stm32f101/103 series ld: low-densit
[Microcontroller]
STM32 establishes a TCP connection with the server via GPRS
u16 USART3_CGREG_Cnt; u8 USART3_Task_Cnt; //task_GPRS is the GPRS processing task, which is called every 50ms~200ms void task_GPRS() {     switch(USART3_Task_Cnt)     {         case 0: //             SendUartStr("case0 ",1);             if(GprsState.bits.Timeout == true)             {                 GprsS
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号