A method for automatically matching CAN baud rate
By combining multi-baud rate test frame serialization transmission with clock synchronization detection, automatic CAN baud rate matching without manual intervention is achieved, solving the problems of cumbersome and error-prone baud rate matching and insufficient robustness in existing technologies, and improving the communication reliability of industrial control systems.
Patent Information
- Application Number
- CN202511087455.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-05
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2045-08-05
AI Technical Summary
In industrial control systems, precise matching of node baud rates relies on manual configuration, which is tedious, error-prone, and costly, and is difficult to scale to large-scale or dynamically changing network scenarios. Existing automation methods are not robust in complex electromagnetic environments and cannot effectively identify subtle clock drift or signal degradation problems.
The first target baud rate is dually locked by serialized transmission of multi-baud rate test frames and stable response feedback mechanism. Combined with clock synchronization detection, the second target baud rate between the communication node and the CAN bus is obtained. The consistency between the two is compared for matching. The complementarity of the physical layer and protocol layer is used to improve the detection accuracy and reliability.
It significantly improves the accuracy and reliability of baud rate detection, reduces the risk of misjudgment, ensures that the communication node and the CAN bus achieve precise matching under the same bit time base, and avoids communication failure and data packet loss.
Smart Images

Figure CN120582927B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial automation technology, and in particular to a method for automatic matching of CAN baud rates. Background Technology
[0002] In industrial control systems, the reliable establishment of controller area network (CAN) bus communication is a core component, and its key lies in the precise matching of node baud rates. However, due to the complexity and variability of bus physical topology and the significant differences in node clock characteristics, achieving automatic baud rate matching without manual intervention remains a major challenge. Current mainstream baud rate matching methods heavily rely on manual configuration by engineers, requiring precise calculation and synchronization of complex bit timing parameters for each node, including propagation and phase buffer sections. This process is not only tedious and error-prone but also incurs high costs and is difficult to scale to large-scale or dynamically changing network scenarios. Traditional automation attempts, such as limited auto-negotiation protocols, are less robust in complex electromagnetic environments or mixed-node applications, and cannot effectively identify and adapt to subtle clock drift or signal degradation issues. Summary of the Invention
[0003] To address the technical problems existing in the background art, this invention proposes a method for automatic CAN baud rate matching, comprising:
[0004] Obtain the first target baud rate; obtain the second target baud rate between the communication node and the CAN bus based on clock synchronization detection; when the error between the first target baud rate and the second target baud rate is less than a preset value, determine that the two are successfully matched; match the communication between the communication node and the CAN bus using the first target baud rate.
[0005] Further, obtaining the first target baud rate specifically involves: the communication node sequentially sending multiple test frames with different predefined baud rates to the CAN bus, each test frame containing a preset identifier field; the CAN bus responding to the test frames and generating a response signal; the bit timing parameter detection unit parsing the CAN bus response signal; and when a valid ACK response is detected, recording the baud rate corresponding to the test frame as the first target baud rate. Further, the sequential sending of multiple test frames with different predefined baud rates to the CAN bus by the communication node specifically includes: the communication node querying multiple different baud rates and arranging them from largest to smallest; and the communication node sequentially selecting different baud rates to send test frames to the CAN bus according to the arrangement order.
[0006] Furthermore, the second target baud rate between the communication node and the CAN bus is obtained based on clock synchronization detection as follows: the synchronization detection unit measures the time between the recessive and dominant level bits when the CAN bus is in an active state to obtain the bit time interval, and calculates the second target baud rate based on the bit time interval.
[0007] Furthermore, the step of calculating the second target baud rate based on the bit time interval specifically includes: acquiring multiple bit time intervals, applying an extreme value removal and mean filtering algorithm to the multiple bit time intervals to calculate the average bit time, and taking the reciprocal of the average bit time as the second target baud rate.
[0008] Furthermore, the step of applying the extreme value removal and mean filtering algorithm to multiple bit time intervals to calculate the average bit time specifically includes: removing the maximum and minimum values from the multiple bit time intervals; and averaging the remaining bit time intervals to obtain the average bit time.
[0009] Furthermore, the bit time interval is specifically the duration from the falling edge of the dominant bit to the rising edge of the dominant bit.
[0010] Furthermore, matching the communication between the communication node and the CAN bus with the first target baud rate specifically involves updating the baud rate configuration register of the communication node to the successfully matched baud rate value.
[0011] This invention proposes an automatic CAN baud rate matching method. It employs a dual-locking mechanism of serialized multi-baud rate test frame transmission and stable response feedback to determine a first target baud rate. A second target baud rate between the communication node and the CAN bus is obtained based on clock synchronization detection. Communication between the communication node and the CAN bus is matched by comparing the consistency of the first and second target baud rates. Combining the detection methods for the first and second target baud rates significantly improves the accuracy and reliability of baud rate detection. The complementarity of these two methods effectively reduces the risk of misjudgment that may arise from using a single method (such as hardware misdetection, signal interference, or deviations caused by protocol specificities). Attached Figure Description
[0012] Figure 1 This is a schematic diagram illustrating the workflow of a method for automatic CAN baud rate matching proposed in this invention. Detailed Implementation
[0013] Reference Figure 1 The present invention proposes a method for automatic CAN baud rate matching, which specifically includes the following steps:
[0014] S1. Obtain the first target baud rate. Specifically, this includes:
[0015] S11. The communication node sequentially sends multiple test frames with different predefined baud rates to the CAN (Controller Area Network) bus. Each test frame contains a preset identifier field (the value of which is a preset identifier).
[0016] Specifically, the pre-configured range of the acceptance filter on the receiving node matching the preset identifier must precisely match the value of the preset identifier. When a test frame is transmitted to the CAN bus, the receiving node matching the preset identifier identifies the identifier through the acceptance filter and triggers the protocol stack processing flow. If the frame verification sequence passes CRC (Cyclic Redundancy Check) verification, the receiving node matching the preset identifier will return the dominant bit in the ACK slot as a valid acknowledgment. This process ensures that the communication node can clearly distinguish between the physical layer response signal and the protocol layer valid ACK (acknowledgment character): if there is no preset identifier, the receiving node matching the preset identifier will discard the test frame, resulting in a missing ACK and the baud rate detection process failing. Essentially, this preset identifier, through the identifier matching rules pre-configured in the acceptance filter, enables the targeted wake-up of the receiving node matching the preset identifier, establishing a reliable response judgment basis for baud rate testing.
[0017] S12. The CAN bus response test frame is generated and a response signal is generated. The bit timing parameter detection unit parses the CAN bus response signal. When a valid ACK response is detected, the baud rate corresponding to the test frame is recorded as the first target baud rate.
[0018] The CAN bus response test frame has multiple response mechanisms, including: physical layer ACK hardware response mechanism, protocol layer feedback frame generation mechanism, and inter-node arbitration mechanism.
[0019] The physical layer ACK hardware response mechanism is as follows: the receiving node that matches the preset identifier parses the CAN bus signal through differential voltage detection; when the test frame passes the CRC check, the receiving node that matches the preset identifier overwrites the recessive bit of the communication node with the dominant bit in the acknowledgment slot and forms a differential voltage.
[0020] The protocol layer feedback frame generation mechanism is as follows: After the CAN controller detects the start bit of the CAN bus, it synchronizes the bit stream (a continuously transmitted binary sequence in a digital communication system) and completes CRC check and format verification. When the verification passes and the filter matches, all nodes matching the preset identifier are stored in the receive FIFO (first-in, first-out) and automatically reply with the ACK bit; then the CAN controller triggers the MCU (microcontroller unit) to receive interrupt. The CPU reads the frame data (identifier / downloadable content / data field) in the interrupt service routine and releases the hardware buffer; the protocol stack unpacks the data field (signal scaling / byte order conversion) according to the communication matrix and executes the business logic to generate response instructions; the CPU loads the send mailbox: sets the arbitration field (identifier priority), data field, and downloadable content. After the CAN controller detects that the CAN bus is idle, it starts carrier sense multiple access / collision detection arbitration: the higher priority identifier wins the arbitration; after successfully acquiring control of the CAN bus, the CAN controller serializes the transmission according to the frame structure, and all nodes that have passed the CRC check and format verification confirm receipt through the dominant bit of the ACK slot.
[0021] The inter-node arbitration mechanism includes: when multiple nodes initiate transmission simultaneously, non-destructive bit-by-bit arbitration is used to resolve multi-node conflicts. That is, each node synchronously sends the binary bit sequence of its own frame identifier and detects the CAN bus. If a recessive bit is sent but a dominant bit is detected, the node immediately stops sending. If the arbitration fails, the node automatically buffers the data and retryes when the CAN bus is idle, without the need for additional scheduling.
[0022] The process of a communication node sequentially sending multiple test frames with different predefined baud rates to the CAN bus includes: the communication node querying multiple different baud rates and arranging them from largest to smallest; and the communication node sequentially selecting different baud rates to send test frames to the CAN bus according to the arrangement order.
[0023] Among them, the communication node retrieves multiple different baud rates, including but not limited to:
[0024] Baud rates include 1Mbps, 500kbps, 250kbps, 125kbps, 100kbps, 50kbps, 20kbps, 10kbps, and 5kbps.
[0025] S2. The second target baud rate between the communication node and the CAN bus is obtained based on clock synchronization detection. Specifically:
[0026] S21. The synchronization detection unit measures the time between the recessive and dominant level bits when the CAN bus is in an active state to obtain the bit time interval, and calculates the second target baud rate based on the bit time interval.
[0027] The principle of detecting the active state of the CAN bus specifically includes a dual-layer determination mechanism of differential voltage detection and protocol rule parsing: The differential voltage detection mechanism works by the CAN transceiver detecting the difference between the CAN bus differential voltage, i.e., CAN_H (high-level data line) and CAN_L (low-level data line), identifying the dominant level (logic "0", bus occupied) and the recessive level (logic "1", bus idle), and converting them into logic signals for transmission to the CAN controller; The protocol rule parsing mechanism works by the CAN controller continuously sampling the level sequence and determining the state according to the CAN protocol: the continuous detection of ≥11 recessive bits indicates an idle state; the appearance of any dominant bit indicates that the CAN bus is occupied, which is an active state.
[0028] Specifically, the calculation of the second target baud rate based on the bit time interval includes:
[0029] Multiple bit time intervals are obtained, and an extreme value removal and mean filtering algorithm is applied to these multiple bit time intervals to calculate the average bit time. The reciprocal of the average bit time is taken as the second target baud rate.
[0030] Specifically, the step of applying an extreme value removal and mean filtering algorithm to multiple bit time intervals to calculate the average bit time includes: removing the maximum and minimum values from the multiple bit time intervals; and averaging the remaining bit time intervals to obtain the average bit time.
[0031] Specifically, the bit time interval is the duration from the falling edge of the dominant bit to the rising edge of the dominant bit.
[0032] In standard CAN, the duration from the falling edge to the rising edge of the dominant bit is fixed at one bit time. Since baud rate is defined as the number of bits transmitted per second, the corresponding baud rate can be calculated by taking the reciprocal of the average time, based on the following relationship: Average bit time = Therefore, we can conclude that: Baud rate = .
[0033] S3. When the error between the first target baud rate and the second target baud rate is less than the preset value, the two are determined to be successfully matched.
[0034] In a CAN bus system, the target baud rate of the same communication node and the same CAN bus should remain consistent within the allowable error range in both idle and active states. Specifically, the error between the first target baud rate in the idle state and the second target baud rate in the active state should be less than a preset value for the CAN bus and communication node to match correctly. The preset value is ±1%.
[0035] The dual locking of the first target baud rate through multi-baud rate test frame serialization and a stable response feedback mechanism is a behavior based on the CAN bus protocol layer. However, this behavior is susceptible to interference from CAN bus noise, erroneous frames, arbitration mechanisms, and high-priority regular communication, which can lead to communication nodes misjudging baud rate matching and generating false positives. For example, noise may coincidentally create a dominant bit at the ACK slot position, or a high-priority regular communication frame with the same baud rate on the CAN bus may win arbitration, and its ACK may be mistakenly interpreted as a response to the test frame. Using the first target baud rate acquisition method alone has the following drawbacks: if the bus uses a non-standard protocol or a custom frame structure, communication will fail; and it requires waiting for a device response, which may be misjudged as "no response" if the device is busy or the network latency is high.
[0036] The second target baud rate obtained based on clock synchronization detection between the communication node and the CAN bus is a physical layer behavior. However, under low load or specific interference conditions, it suffers from insufficient accuracy and difficulty in distinguishing between valid signals and noise, leading to unreliable matching results. Using the second target baud rate acquisition method alone also has the following drawbacks: if the bus is idle or the device does not send frames for a long time, it may fail to capture sufficient bit time characteristics, resulting in detection failure or misjudgment; when there is noise or erroneous frames on the bus, the bit time may be miscalculated (e.g., mistaking an interference pulse for a valid edge transition).
[0037] To address the aforementioned shortcomings, the two methods are mutually verified. The second target baud rate detection may be misjudged due to transient interference, but the software can correct the error through multiple samplings or protocol interactions, thus improving anti-interference capabilities. The first target baud rate list is limited; if the actual baud rate is a non-standard value (e.g., 333kbps), it can be confirmed through the second target baud rate detection method, covering non-standard baud rates. Dual verification can prevent baud rate configuration errors due to a single method error, preventing communication failures and data packet loss, and reducing the risk of misconfiguration.
[0038] S4. Match the communication between the communication node and the CAN bus using the first target baud rate. Specifically, update the baud rate configuration register of the communication node to the successfully matched baud rate value.
[0039] The process is as follows: By directly rewriting the baud rate configuration register in the communication node, the target baud rate parameter value (usually a prescaler or time constant) confirmed in the early detection is accurately written into its corresponding bit field. This causes the clock division circuit controlled by the baud rate configuration register to immediately generate a bit timing clock signal that strictly matches the baud rate. This forces the baud rate of the serial interface to be synchronously updated to the target value, ensuring that subsequent communication nodes and the CAN bus achieve bit-level synchronous sampling under the same bit time base, and finally achieves accurate baud rate matching.
[0040] After the first and second target baud rates are detected, the CAN controller is configured to the first target baud rate and attempts to communicate, for example, by sending the CANopen NMT reset command. If the device responds, but the second target baud rate is different from the first target baud rate, the result of the first target baud rate should be taken as the standard, and further communication verification should be performed.
[0041] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. A method for automatic CAN baud rate matching, characterized in that, include: S1. Obtain the first target baud rate; S2. Obtain the second target baud rate between the communication node and the CAN bus based on clock synchronization detection; S3. When the error between the first target baud rate and the second target baud rate is less than the preset value, the two are determined to be successfully matched. S4. Match the communication between the communication node and the CAN bus at the first target baud rate; Specifically, obtaining the first target baud rate involves: The communication node sequentially sends multiple test frames with different predefined baud rates to the CAN bus, and each test frame contains a preset identifier field; The CAN bus responds to the test frame and generates a response signal. The bit timing parameter detection unit parses the CAN bus response signal. When a valid ACK response is detected, the baud rate corresponding to the test frame is recorded as the first target baud rate. Specifically, the second target baud rate between the communication node and the CAN bus, obtained based on clock synchronization detection, is as follows: The synchronization detection unit measures the time between the recessive and dominant levels when the CAN bus is in an active state to obtain the bit time interval, and calculates the second target baud rate based on the bit time interval.
2. The method for automatic CAN baud rate matching according to claim 1, characterized in that, The communication node sequentially sends multiple test frames with different predefined baud rates to the CAN bus, specifically including: The communication node queries multiple different baud rates and sorts them from largest to smallest. The communication nodes sequentially select different baud rates to send test frames to the CAN bus in the order they are arranged.
3. The method for automatic CAN baud rate matching according to claim 1, characterized in that, The calculation of the second target baud rate based on the bit time interval specifically includes: Multiple bit time intervals are obtained, and an extreme value removal and mean filtering algorithm is applied to these multiple bit time intervals to calculate the average bit time. The reciprocal of the average bit time is taken as the second target baud rate.
4. The method for automatic CAN baud rate matching according to claim 3, characterized in that, The process of applying an extremum removal and mean filtering algorithm to multiple bit time intervals to calculate the average bit time specifically includes: Remove the maximum and minimum values from the above multiple bit time intervals; The average bit time is obtained by averaging the remaining bit time intervals.
5. The method for automatic CAN baud rate matching according to claim 1 or 3, characterized in that, The bit time interval is specifically the duration from the falling edge of the dominant bit to the rising edge of the dominant bit.
6. The method for automatic CAN baud rate matching according to claim 1, characterized in that, Matching the communication between the communication node and the CAN bus using the first target baud rate specifically involves: Update the baud rate configuration register of the communication node to the baud rate value that was successfully matched.
Citation Information
Patent Citations
Controller area network (CAN) bus Baud rate self-adapting method
CN104199298A
High-speed CAN transceiver baud rate matching detection system for local network
CN113688086A