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.
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
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Intelligence at the Edge Powers Autonomous Factories
- 8. [Learning LPC1768 library functions] Timer experiment
- One minute to understand: World Industrial History (video explanation)
- EEWorld's "Search Device" applet is now online, allowing you to easily check device data and make chip selection easier
- Wireless transmission distance calculation
- How to amplify small signals with the ATA-5000 series preamplifier?
- LOTO Lesson 4: Practice of the common emitter amplifier circuit of transistor 2N3904
- Ahhhh urgent help, please help me analyze the simple circuit diagram
- Inventory of several commonly used protection circuits
- 4G Small Base Station