A can bus baud rate self-adapting method, terminal and storage medium

Through the pin multiplexing and input capture module of the main control chip MCU, combined with the preset baud rate matching table, the CAN bus pulse signal width is directly measured and the baud rate weight is calculated, which solves the problems of slow baud rate adaptation and high hardware cost of the CAN network, realizes fast and accurate baud rate matching, and improves system compatibility and reliability.

CN119052020BActive Publication Date: 2025-10-21SINO TRUK JINAN POWER CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411271795.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-11
Publication Date
2025-10-21
Estimated Expiration
2044-09-11

AI Technical Summary

Technical Problem

Existing CAN network baud rate adaptation methods are difficult to achieve fast and accurate baud rate matching without increasing the hardware burden, resulting in unstable communication and increased hardware costs.

Method used

Through the pin multiplexing and input capture module of the main control chip MCU, combined with the preset baud rate matching table, the CAN bus pulse signal width is directly measured, the baud rate weight is calculated, and the baud rate is automatically adjusted to match the bus communication rate.

Benefits of technology

It achieves fast and accurate baud rate adaptation, reduces hardware costs, improves system compatibility and reliability, simplifies operation processes, and is suitable for cost-sensitive application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119052020B_ABST
    Figure CN119052020B_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of vehicle communication, and specifically provides a CAN bus baud rate self-adaptive method, a terminal and a storage medium, which comprise updating a pin multiplexing module configuration, connecting a message receiving pin of a master control chip MCU with an input capture module in the master control chip MCU, initializing the input capture module, and setting a clock frequency to measure the pulse width of a current CAN pulse signal; according to a preset baud rate matching table, the upper and lower limits of the pulse width corresponding to each baud rate and the overall upper and lower limits are calculated; by directly measuring the pulse signal width on the CAN bus and combining the preset baud rate matching table, the application can quickly narrow the baud rate search range, reduce the number of unnecessary attempts, thereby significantly shorten the time required for the self-adaptive process, and improve the system startup speed and response capability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of vehicle communications, and in particular relates to a CAN bus baud rate self-adaptation method, a terminal and a storage medium. Background Art

[0002] With the rapid development of automotive electronics, the Controller Area Network (CAN) has become an indispensable component of modern vehicles, providing efficient and reliable communication between various control units within the vehicle. With its high reliability, strong anti-interference capabilities, and flexible communication mechanisms, the CAN network demonstrates excellent performance in complex and changing vehicle environments and is widely used in various fields, including powertrain control, body control, and safety systems. However, to ensure stable and effective communication between nodes within the CAN network, each node must strictly adhere to the same communication rate, or baud rate.

[0003] While CAN networks play a vital role in automotive communications, in practice, baud rate settings can vary, especially between different vehicle models or years, due to manufacturer differences or upgrade requirements. This requires CAN nodes to have baud rate adaptation capabilities to automatically match the communication rate on the bus. Current methods for implementing baud rate adaptation have two major challenges: First, software polling, which continuously attempts to send messages at different baud rates and detects responses, is flexible but time-consuming, impacting system startup speed and responsiveness. Second, hardware acquisition, which directly measures the pulse width of CAN messages by adding additional pins, improves speed but undoubtedly increases hardware cost and design complexity, making it unsuitable for cost-sensitive applications. Therefore, achieving fast and accurate baud rate adaptation without excessive hardware overhead remains a pressing challenge. Summary of the Invention

[0004] In view of the above-mentioned deficiencies in the prior art, the present invention provides a CAN bus baud rate adaptation method, a terminal and a storage medium to solve the above-mentioned technical problems.

[0005] In a first aspect, the present invention provides a CAN bus baud rate adaptation method, wherein the CAN bus is connected to a main control chip MCU via a CAN transceiver, comprising:

[0006] Step 110: In the initial state, the pin multiplexing module in the main control chip MCU is configured to connect the message sending pin of the main control chip MCU to the message sending pin of the CAN function module in the main control chip MCU, and to connect the message receiving pin of the main control chip MCU to the message receiving pin of the CAN function module for sending and receiving messages;

[0007] Step 120, read the preset baud rate value and send a message to the CAN bus at the preset baud rate, and check the error flag bit of the internal status register of the CAN functional module; if the error flag bit is 0, it indicates that the preset baud rate matches the baud rate of the CAN bus, and the adaptive process ends; if the error flag bit is 1, go to step 130;

[0008] Step 130: Update the pin multiplexing module configuration, connect the message receiving pin of the main control chip MCU to the input capture module in the main control chip MCU, initialize the input capture module, and set the clock frequency to measure the pulse width of the current CAN pulse signal;

[0009] Step 140, calculating the pulse width upper and lower limits and the overall upper and lower limits corresponding to each baud rate according to a preset baud rate matching table;

[0010] Step 150, reading the pulse signal on the CAN bus, and calculating the weights of all baud rates according to the pulse width of the read pulse signal;

[0011] Step 160: sort all baud rate weights, select the baud rate with the largest weight as a candidate value, update the pin multiplexing module configuration, initialize the CAN function module according to the candidate baud rate, and send a message to the CAN bus through the CAN transceiver;

[0012] Step 170, determine whether the match is successful based on the error flag bit of the internal status register of the CAN functional module; if successful, update the initial baud rate value and end the adaptive process; if unsuccessful, exclude the candidate values ​​in this adaptive process and repeat steps 160 and 170 until the match is successful.

[0013] A further improvement of this technical solution is that the clock frequency is 10MHZ.

[0014] A further improvement of this technical solution is that the specific method for calculating the upper and lower limits of the pulse width corresponding to each baud rate includes:

[0015] After the CAN pulse signal enters the input capture module, the status of the captured CAN pulse signal is determined;

[0016] When the rising edge of the CAN pulse signal is captured, the cnt register in the input capture module is reset and automatically accumulates from 0;

[0017] When the falling edge of the CAN pulse signal is captured, the value of the cnt register is automatically stored in the data register;

[0018] Calculate the pulse width of the captured CAN pulse signal based on the value of the data register and the current clock frequency of the input capture module;

[0019] According to the calculated pulse width, the upper and lower limits of the pulse width corresponding to the baud rate are obtained from the preset baud rate matching table. A further improvement of this technical solution is that the formula for calculating the pulse width of the captured CAN pulse signal is:

[0020] Width = Tick / freq;

[0021] Where Width is the pulse width, Tick is the read data register value, and freq is the current clock frequency of the input capture module.

[0022] A further improvement of the technical solution is to calculate the overall upper and lower limits based on the upper and lower limits of the pulse width corresponding to each baud rate and in combination with the bit stuffing rule.

[0023] A further improvement of the technical solution is to read the pulse signal on the CAN bus and calculate the weights of all baud rates according to the pulse width of the read pulse signal. The specific method includes:

[0024] Determine whether the read pulse width falls within the upper and lower limits of the pulse width corresponding to the preset baud rate;

[0025] When the read pulse width falls within the upper and lower limits of the preset baud rate, the hit count of the preset baud rate is increased by 1; when the read pulse width exceeds the overall upper and lower limits, it is regarded as an abnormal signal and discarded; when the read pulse width exceeds the upper and lower limits of the preset baud rate but does not exceed the overall upper and lower limits, the miss count of the preset baud rate is increased by 1;

[0026] The weight corresponding to the preset baud rate is calculated based on the judgment result and the baud rate weight calculation formula.

[0027] A further improvement of this technical solution is that the baud rate weight calculation formula is:

[0028] W = k1·n1-k2·n2;

[0029] Wherein, W is the weight of the preset baud rate, n1 is the number of hits of the preset baud rate, n2 is the number of misses of the preset baud rate, k1 is the weight coefficient of hits, and k2 is the weight coefficient of misses.

[0030] A further improvement of the technical solution is that all baud rates in the preset baud rate matching table share the same k1 and k2.

[0031] In a second aspect, a terminal is provided, including:

[0032] processor, memory, wherein

[0033] The memory is used to store computer programs,

[0034] The processor is used to call and run the computer program from the memory, so that the terminal executes the above-mentioned terminal method.

[0035] According to a third aspect, a computer storage medium is provided, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the methods described in the above aspects.

[0036] The beneficial effects of the present invention are that the CAN bus baud rate adaptation method provided by the present invention achieves rapid and accurate adaptation of the CAN bus baud rate without adding additional hardware resources by cleverly utilizing the pin multiplexing function of the main control chip MCU and the input capture module. Compared with traditional methods, this technical solution has the following significant benefits:

[0037] Improved adaptive efficiency: By directly measuring the pulse signal width on the CAN bus and combining it with a preset baud rate matching table, the present invention can quickly narrow the baud rate search range and reduce the number of unnecessary attempts, thereby significantly shortening the time required for the adaptive process and improving the system startup speed and responsiveness.

[0038] Reduce hardware costs: No additional acquisition pins or complex peripheral circuits are required. Adaptive baud rate detection can be achieved by simply utilizing the existing pin multiplexing and input capture functions within the main control chip MCU, effectively reducing hardware costs and making this technical solution more suitable for cost-sensitive application scenarios.

[0039] Enhanced system compatibility: Since the baud rates of the CAN network may vary between vehicles of different models or years, the adaptive method provided by the present invention can automatically match the communication rate on the bus, thereby enhancing the compatibility and flexibility of the system and facilitating communication and data exchange between different vehicles.

[0040] Improve system reliability: By real-time detection of the error flag bit of the internal status register of the CAN functional module, the present invention can accurately determine whether the preset baud rate matches the baud rate of the CAN bus, and automatically adjust it if it does not match, avoiding communication failure and data loss caused by baud rate mismatch, and improving the stability and reliability of the system.

[0041] Simplified Operational Process: The entire adaptive process is automatically controlled by the main control chip MCU, eliminating the need for manual intervention. This simplifies the operational process and reduces maintenance difficulty and costs. Furthermore, the preset baud rate matching table and weighted sorting algorithm make the adaptive process more intelligent and efficient. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0043] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention.

[0044] Figure 2 It is a schematic block diagram of a CAN communication system corresponding to the method of the present invention.

[0045] Figure 3 A schematic diagram of the structure of a terminal provided by an embodiment of the present invention.

[0046] 211 is a pin multiplexing module, 212 is a CAN function module, 213 is an input capture module, 220 is a CAN bus, and 230 is a CAN transceiver. DETAILED DESCRIPTION

[0047] In order to enable those skilled in the art to better understand the technical solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.

[0048] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention.

[0049] The key terms appearing in the present invention are explained below.

[0050] CAN (Controller Area Network) is a serial communication protocol bus designed for real-time applications. It uses twisted-pair wiring for signal transmission and is one of the world's most widely used fieldbuses. The CAN protocol is used for communication between various components in automobiles, replacing expensive and bulky distribution wiring harnesses. The protocol's robustness has extended its use to other automation and industrial applications. Features of the CAN protocol include complete serial data communication, real-time support, transmission rates up to 1 Mb / s, 11-bit addressing, and error detection.

[0051] An MCU (Microcontroller Unit), also known as a single-chip microcomputer or single-chip microcomputer, reduces the frequency and specifications of a central processing unit (CPU) and integrates memory, timers, A / D converters, and other peripherals onto a single chip, creating a chip-level computer capable of providing diverse control combinations for various applications. MCUs can be found in mobile phones, PC peripherals, remote controls, automotive electronics, industrial stepper motors, and robotic arm control.

[0052] Figure 1 The following is a schematic flow chart of a CAN bus baud rate adaptation method. Figure 1 The execution entity can be Figure 2 The CAN communication system shown in the figure is specifically a CAN bus connected to the main control chip MCU via a CAN transceiver. The main control chip MCU includes a pin multiplexing module, a CAN function module, and an input capture module. Depending on different needs, the order of the steps in the flowchart can be changed, and some steps can be omitted.

[0053] like Figure 1 As shown, the method includes:

[0054] Step 110: In the initial state, the pin multiplexing module in the main control chip MCU is configured to connect the message sending pin (P01) of the main control chip MCU to the message sending pin of the CAN function module in the main control chip MCU, and to connect the message receiving pin (P02) of the main control chip MCU to the message receiving pin of the CAN function module for sending and receiving messages;

[0055] Step 120, read the preset baud rate value and send a message to the CAN bus at the preset baud rate, and check the error flag bit of the internal status register of the CAN functional module; if the error flag bit is 0, it indicates that the preset baud rate matches the baud rate of the CAN bus, and the adaptive process ends; if the error flag bit is 1, go to step 130;

[0056] Step 130: Update the pin multiplexing module configuration, connect the message receiving pin of the main control chip MCU to the input capture module in the main control chip MCU, initialize the input capture module, and set the clock frequency to measure the pulse width of the current CAN pulse signal;

[0057] Step 140, calculating the pulse width upper and lower limits and the overall upper and lower limits corresponding to each baud rate according to a preset baud rate matching table;

[0058] Step 150, reading the pulse signal on the CAN bus, and calculating the weights of all baud rates according to the pulse width of the read pulse signal;

[0059] Step 160: sort all baud rate weights, select the baud rate with the largest weight as a candidate value, update the pin multiplexing module configuration, initialize the CAN function module according to the candidate baud rate, and send a message to the CAN bus through the CAN transceiver;

[0060] Step 170, determine whether the match is successful based on the error flag bit of the internal status register of the CAN functional module; if successful, update the initial baud rate value and end the adaptive process; if unsuccessful, exclude the candidate values ​​in this adaptive process and repeat steps 160 and 170 until the match is successful.

[0061] Specifically, the message receiving pin of the main control chip MCU also has a pin reset function, which can be used to receive CAN messages or to collect pulse signals according to different configurations of the pin multiplexing module.

[0062] In addition, the specific methods for calculating the upper and lower limits of the pulse width corresponding to each baud rate include:

[0063] Step 141, after the CAN pulse signal enters the input capture module, determine the state of the captured CAN pulse signal;

[0064] Step 142, when the rising edge of the CAN pulse signal is captured, the cnt register in the input capture module is reset and automatically accumulated from 0;

[0065] Step 143, when the falling edge of the CAN pulse signal is captured, the value of the cnt register is automatically stored in the data register;

[0066] Step 144 , calculating the pulse width of the captured CAN pulse signal based on the value of the data register and the current clock frequency of the input capture module;

[0067] Step 145 : Obtain the upper and lower limits of the pulse width corresponding to the baud rate from a preset baud rate matching table according to the calculated pulse width.

[0068] Specifically, the formula for calculating the pulse width of the captured CAN pulse signal is:

[0069] Width = Tick / freq;

[0070] Among them, Width is the pulse width, Tick is the data register value read, and freq is the current clock frequency of the input capture module. For example, when the clock frequency is 1MHZ and the Tick value is 100, the calculated pulse width is 100 microseconds. According to the bit filling rule of the CAN message, after sending 5 identical bits continuously (whether 5 1s or 5 0s), a bit opposite to it will be inserted at the 6th position. Therefore, under normal circumstances, the pulse width of the CAN pulse signal ranges from 1 to 5 bits. The clock frequency here refers to the clock frequency of the input capture module involved in calculating the pulse width. The clock frequency of the input capture module is not fixed. A frequency that is too high may cause data overflow in the internal register of the input capture module when collecting signals. A frequency that is too low may cause the collected data to be less accurate. In order to ensure the adaptation effect of each baud rate in the baud rate matching table, the preferred clock frequency is 10MHZ.

[0071] Table 1: Preset baud rate matching table

[0072] Baud rate (kbit / s) Pulse width upper limit (μs) Pulse width lower limit (μs) 5 1000 200 10 500 100 20 250 50 50 100 20 100 50 10 125 40 8 250 20 4 500 10 2 1000 5 1 .

[0073] For example, when the baud rate is 1000 kbit / s, the actual pulse width should be in the range of 1 microsecond to 5 microseconds.

[0074] Furthermore, the overall upper and lower limits are calculated based on the obtained pulse width upper and lower limits corresponding to each baud rate and in combination with the bit stuffing rule.

[0075] Afterwards, the pulse signal on the CAN bus is read, and the weights of all baud rates are calculated based on the pulse width of the read pulse signal. The specific method includes:

[0076] Step 151, determining whether the read pulse width falls within the upper and lower limits of the pulse width corresponding to the preset baud rate;

[0077] Step 152: When the read pulse width falls within the upper and lower limits of the preset baud rate, the hit count of the preset baud rate is increased by 1; when the read pulse width exceeds the overall upper and lower limits, it is considered an abnormal signal and discarded; when the read pulse width exceeds the upper and lower limits of the preset baud rate but does not exceed the overall upper and lower limits, the miss count of the preset baud rate is increased by 1;

[0078] Step 153, calculate the weight corresponding to the preset baud rate according to the judgment result and the baud rate weight calculation formula. Specifically, the baud rate weight calculation formula is:

[0079] W = k1·n1-k2·n2;

[0080] Wherein, W is the weight of the preset baud rate, n1 is the number of hits of the preset baud rate, n2 is the number of misses of the preset baud rate, k1 is the weight coefficient of hits, and k2 is the weight coefficient of misses.

[0081] Specifically, all baud rates in the preset baud rate matching table share the same k1 and k2. According to the above rules, after multiple iterations, the weights of all baud rates are obtained, and all baud rates are sorted according to the weights. The larger the weight, the more likely the baud rate is to be the current bus baud rate. For example, k1 = 1, k2 = 2, and the current baud rate matching table contains 250K, 500K, and 1000K. The corresponding pulse width upper and lower limits are 4 to 20, 2 to 10, and 1 to 5, respectively, and the overall upper and lower limits are 1 to 20. Assuming that the measured pulse widths are 2, 4, 6, 8, and 21, respectively, the weight of 250K is calculated to be 1, the weight of 500K is 4, and the weight of 1000K is -2. The most likely baud rate of the bus is 500K.

[0082] Figure 3 This is a structural diagram of a terminal 300 provided in an embodiment of the present invention. The terminal 300 can be used to execute the CAN bus baud rate adaptation method provided in an embodiment of the present invention.

[0083] The terminal 300 may include a processor 310, a memory 320, and a communication module 330. These components communicate via one or more buses. Those skilled in the art will appreciate that the server structure shown in the figure does not limit the present invention. The server structure may be a bus structure or a star structure, and may include more or fewer components than shown, or may combine certain components or arrange the components differently.

[0084] The memory 320 can be used to store execution instructions of the processor 310. The memory 320 can be implemented by any type of volatile or non-volatile storage terminal or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk, or optical disk. When the execution instructions in the memory 320 are executed by the processor 310, the terminal 300 can perform some or all of the steps in the following method embodiments.

[0085] The processor 310 is the control center of the storage terminal. It uses various interfaces and lines to connect various parts of the entire electronic terminal. It runs or executes software programs and / or modules stored in the memory 320, and calls data stored in the memory to perform various functions of the electronic terminal and / or process data. The processor can be composed of an integrated circuit (IC), for example, it can be composed of a single packaged IC, or it can be composed of multiple packaged ICs with the same or different functions. For example, the processor 310 can only include a central processing unit (CPU). In an embodiment of the present invention, the CPU can be a single computing core or multiple computing cores.

[0086] The communication module 330 is used to establish a communication channel so that the storage terminal can communicate with other terminals, receive user data sent by other terminals, or send user data to other terminals.

[0087] The present invention also provides a computer storage medium, wherein the computer storage medium may store a program that, when executed, may include some or all of the steps of each embodiment provided by the present invention. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).

[0088] Those skilled in the art will clearly understand that the technology in the embodiments of the present invention can be implemented by means of software plus a necessary general-purpose hardware platform. Based on this understanding, the technical solutions in the embodiments of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product is stored in a storage medium such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, or other medium that can store program code, and includes a number of instructions for enabling a computer terminal (which can be a personal computer, a server, or a second terminal, a network terminal, etc.) to execute all or part of the steps of the method described in each embodiment of the present invention.

[0089] In this specification, the same or similar parts between the various embodiments can be referred to each other. In particular, for the terminal embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description in the method embodiment.

[0090] In the several embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative. For example, the division of the modules is merely a logical function division. In actual implementation, there may be other division methods, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of systems or modules, and can be electrical, mechanical or other forms.

[0091] The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules may be selected to achieve the purpose of this embodiment according to actual needs.

[0092] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.

[0093] Although the present invention has been described in detail with reference to the accompanying drawings and in conjunction with preferred embodiments, the present invention is not limited thereto. Without departing from the spirit and essence of the present invention, persons of ordinary skill in the art may make various equivalent modifications or substitutions to the embodiments of the present invention, and such modifications or substitutions shall be within the scope of the present invention. Any changes or substitutions that can be easily conceived by persons skilled in the art within the technical scope disclosed in the present invention shall be within the scope of protection of the present invention.

Claims

1. A CAN bus baud rate adaptation method, wherein the CAN bus is connected to the main control chip MCU via a CAN transceiver, characterized in that: include: Step 110: In the initial state, the pin multiplexing module in the main control chip MCU is configured to connect the message sending pin of the main control chip MCU to the message sending pin of the CAN function module in the main control chip MCU, and to connect the message receiving pin of the main control chip MCU to the message receiving pin of the CAN function module for sending and receiving messages; Step 120, read the preset baud rate value and send a message to the CAN bus at the preset baud rate, and check the error flag bit of the internal status register of the CAN functional module; If the error flag is 0, it indicates that the preset baud rate matches the baud rate of the CAN bus, and the adaptive process ends; If the error flag is 1, go to step 130; Step 130: Update the pin multiplexing module configuration, connect the message receiving pin of the main control chip MCU to the input capture module in the main control chip MCU, initialize the input capture module, and set the clock frequency to measure the pulse width of the current CAN pulse signal; Step 140, calculating the pulse width upper and lower limits and the overall upper and lower limits corresponding to each baud rate according to a preset baud rate matching table; Step 150, reading the pulse signal on the CAN bus, and calculating the weights of all baud rates according to the pulse width of the read pulse signal; Step 160: sort all baud rate weights, select the baud rate with the largest weight as a candidate value, update the pin multiplexing module configuration, initialize the CAN function module according to the candidate baud rate, and send a message to the CAN bus through the CAN transceiver; Step 170, determine whether the match is successful based on the error flag bit of the internal status register of the CAN functional module; if successful, update the initial baud rate value and end the adaptive process; if unsuccessful, exclude the candidate values ​​in this adaptive process and repeat steps 160 and 170 until the match is successful.

2. The CAN bus baud rate adaptive method according to claim 1, wherein: The clock frequency is 10MHZ.

3. The CAN bus baud rate self-adaptation method according to claim 1, wherein: The specific methods for calculating the upper and lower limits of the pulse width corresponding to each baud rate include: After the CAN pulse signal enters the input capture module, the status of the captured CAN pulse signal is determined; When the rising edge of the CAN pulse signal is captured, the cnt register in the input capture module is reset and automatically accumulates from 0; When the falling edge of the CAN pulse signal is captured, the value of the cnt register is automatically stored in the data register; Calculate the pulse width of the captured CAN pulse signal based on the value of the data register and the current clock frequency of the input capture module; The upper and lower limits of the pulse width corresponding to the baud rate are obtained from the preset baud rate matching table according to the calculated pulse width.

4. The CAN bus baud rate self-adaptation method according to claim 3, wherein: The formula for calculating the pulse width of the captured CAN pulse signal is: Width = Tick / freq; Where Width is the pulse width, Tick is the read data register value, and freq is the current clock frequency of the input capture module.

5. The CAN bus baud rate self-adaptation method according to claim 3, wherein: The overall upper and lower limits are calculated based on the obtained pulse width upper and lower limits corresponding to each baud rate and the bit stuffing rule.

6. The CAN bus baud rate self-adaptation method according to claim 1, wherein: Read the pulse signal on the CAN bus and calculate the weights of all baud rates based on the pulse width of the read pulse signal. The specific method includes: Determine whether the read pulse width falls within the upper and lower limits of the pulse width corresponding to the preset baud rate; When the read pulse width falls within the upper and lower limits of the preset baud rate, the hit count of the preset baud rate is increased by 1; when the read pulse width exceeds the overall upper and lower limits, it is regarded as an abnormal signal and discarded; when the read pulse width exceeds the upper and lower limits of the preset baud rate but does not exceed the overall upper and lower limits, the miss count of the preset baud rate is increased by 1; The weight corresponding to the preset baud rate is calculated based on the judgment result and the baud rate weight calculation formula.

7. The CAN bus baud rate self-adaptation method according to claim 6, wherein: The baud rate weight calculation formula is: W = k1·n1-k2·n2; Wherein, W is the weight of the preset baud rate, n1 is the number of hits of the preset baud rate, n2 is the number of misses of the preset baud rate, k1 is the weight coefficient of hits, and k2 is the weight coefficient of misses.

8. The CAN bus baud rate self-adaptation method according to claim 6, wherein: All baud rates in the preset baud rate matching table share the same k1 and k2.

9. A terminal, characterized in that: include: processor; a memory for storing execution instructions of the processor; The processor is configured to execute the method according to any one of claims 1 to 8.

10. A computer-readable storage medium storing a computer program, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.

Citation Information

Patent Citations

  • CAN bus baud rate self-adaption method and device

    CN112118075A

  • Baud rate adaptive system, method and device

    CN114095296A