Spi communication baud rate identification method and device
By using a timer to monitor transmission timeouts and calculate the baud rate in SPI communication, the communication error problem caused by baud rate deviation was solved, achieving efficient and accurate SPI communication.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-04
- Publication Date
- 2026-03-20
AI Technical Summary
In SPI communication, the baud rate deviation caused by different chips and crystal oscillators leads to communication errors and data inconsistencies, and requires a complex verification mechanism, which affects communication efficiency.
By using two timers in SPI communication to monitor whether the current and multiple transmissions time out, the baud rate is calculated to ensure communication success and data consistency. The first timer is used to monitor whether the current transmission times out, and the second timer is used to monitor whether multiple transmissions time out. The baud rate is calculated based on the timer period and the remaining duration.
It improves the success rate of SPI communication and the validity of data, reduces the reliance on data verification, and improves communication efficiency.
Smart Images

Figure CN116633486B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of circuit board, in particular to a SPI communication baud rate identification method and device. BACKGROUND
[0002] This section is intended to provide background information to facilitate an understanding of embodiments of the application as set forth in the claims. The description herein does not constitute admission of prior art.
[0003] After the circuit board is mass-produced, it needs to be electrically checked to ensure that the circuit board electrical conduction and disconnection are correct. The usual way is to add a certain signal at a certain position, and then read the signal at the corresponding check position to judge whether it is correctly connected. When the circuit board contains an intelligent chip, it is also necessary to verify whether the program of the circuit board intelligent chip is correctly run, and the components on the circuit board will affect the logic and action of the intelligent chip.
[0004] The above-mentioned action needs to be performed by SIP communication. In the traditional SPI communication, both parties agree on the communication baud rate, and each party ensures that its own baud rate is correct. The problem of the above-mentioned traditional scheme is:
[0005] Firstly, because the chips of the two communication parties are different, the crystal oscillators are different, and the timing periods are different, there will be a deviation in the baud rate. If the deviation is too large, greater than the width of 1 data bit, it will cause misalignment of communication, thereby causing communication data error and communication failure.
[0006] Secondly, when signal interference occurs during data communication, it will cause signal data misalignment, thereby causing complete data error, affecting the data validity and consistency of the two communication parties.
[0007] Thirdly, the two communication parties need to develop a complex verification mechanism to constantly verify and check whether their own data is correct, resulting in low communication efficiency. SUMMARY
[0008] The embodiment of the present application provides a SPI communication baud rate identification method applied to a circuit board for SPI communication, for SPI communication baud rate identification, ensuring successful communication, good data validity and consistency, and high communication efficiency. The method comprises the following steps:
[0009] After receiving the SPI data message data sent by other circuit boards, start the first timer and the second timer at the same time, wherein the first timer is used to monitor whether the current transmission is timed out; the second timer is used to monitor whether the multiple transmissions are timed out; the period of the first timer is shorter than the period of the first timer;
[0010] After receiving the data communication message again, check whether the first timer expires, if not, calculate the remaining time of the first timer;
[0011] When the second timer expires for the first time, record the remaining time of the second timer;
[0012] When it is determined that the header of the received data is correct, calculate the baud rate of the current SPI communication according to the period of the second timer, the remaining time of the first timer, and the remaining time of the second timer.
[0013] The embodiment of the application provides an SPI communication baud rate identification device applied to a circuit board in an SPI communication baud rate identification system, and used for identifying the SPI communication baud rate, ensuring successful communication, good data validity and consistency, and high communication efficiency.
[0014] The timer starting module is used for starting the first timer and the second timer simultaneously after receiving the data communication message of the SPI data message sent by other circuit boards, wherein the first timer is used for monitoring whether the current transmission expires; the second timer is used for monitoring whether multiple transmissions expire; and the period of the first timer is shorter than the period of the first timer.
[0015] The timeout judgment module is used for checking whether the first timer expires after receiving the data communication message again, calculating the remaining time of the first timer if the first timer does not expire, and recording the remaining time of the second timer when the second timer expires for the first time.
[0016] The baud rate calculation module is used for calculating the baud rate of the current SPI communication according to the period of the second timer, the remaining time of the first timer, and the remaining time of the second timer when it is determined that the header of the received data is correct.
[0017] The embodiment of the application further provides a computer device, which comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the above SPI communication baud rate identification method when executing the computer program.
[0018] The embodiment of the application further provides a computer readable storage medium, which stores a computer program, and the computer program is executed by the processor to implement the above SPI communication baud rate identification method.
[0019] The embodiment of the application further provides a computer program product, which comprises a computer program, and the computer program is executed by the processor to implement the above SPI communication baud rate identification method.
[0020] In the embodiment of the present application, after receiving the communication message of the SPI data message data sent by other circuit board, the first timer and the second timer are started simultaneously, wherein the first timer is used for monitoring whether the current transmission is timed out; the second timer is used for monitoring whether the multiple transmissions are timed out; the period of the first timer is shorter than the period of the first timer; after receiving the communication message of the data again, it is checked whether the first timer is timed out, if not, the remaining time of the first timer is calculated; when the second timer is not timed out for the first time, the remaining time of the second timer is recorded; when it is determined that the header identification of the received data is correct, the baud rate of the current SPI communication is calculated according to the period of the second timer, the remaining time of the first timer and the remaining time of the second timer. In the above process, the accurate baud rate is calculated through the two timers, which is used for communication to ensure the success rate of communication, data validity and consistency; the above process also does not need to repeatedly verify the correctness of the data, thereby improving the communication efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description only constitute some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained from these drawings without creative labor. In the drawings:
[0022] Figure 1 The flow chart of the SPI communication baud rate identification method in the embodiment of the present application;
[0023] Figure 2 The schematic diagram of the SPI data message communication between the two circuit boards in the embodiment of the present application;
[0024] Figure 3 The schematic diagram of the data received by the circuit board 2 for processing in the embodiment of the present application;
[0025] Figure 4 The specific flow chart of the SPI communication baud rate identification in the embodiment of the present application;
[0026] Figure 5 The schematic diagram of the SPI communication baud rate identification device in the embodiment of the present application;
[0027] Figure 6 The schematic diagram of the computer equipment structure in the embodiment of the present application. DETAILED DESCRIPTION
[0028] In order to make the purposes, technical solutions and advantages of the embodiments of the present application clearer, further detailed description will be made to the embodiments of the present application in combination with the drawings. Herein, the illustrative embodiments of the present application and the description thereof are used to explain the present application but not to limit the present application.
[0029] Figure 1 The flow chart of the SPI communication baud rate identification method in the embodiments of the present application comprises:
[0030] Step 101, after receiving the communication message of the SPI data message sent by the other circuit board, simultaneously starting a first timer and a second timer, wherein the first timer is used to monitor whether the current transmission is timed out; the second timer is used to monitor whether the multiple transmissions are timed out; the period of the first timer is shorter than the period of the first timer;
[0031] Step 102, after receiving the communication message of the data again, checking whether the first timer is timed out, if not, calculating the remaining time length of the first timer;
[0032] Step 103, when the second timer is not timed out for the first time, recording the remaining time length of the second timer;
[0033] Step 104, when it is determined that the header identification of the received data is correct, calculating the baud rate of the current SPI communication according to the period of the second timer, the remaining time length of the first timer and the remaining time length of the second timer.
[0034] In the embodiments of the present application, since SPI belongs to full-duplex synchronous serial communication method, the circuit boards involved in the embodiments of the present application all adopt 16-bit SPI communication. In the communication process, it can be ensured that the 16-bit data transmitted by the sending circuit board and the receiving circuit board is complete and will not be misaligned or modified accidentally. However, due to the characteristics of synchronous serial communication, the first 16-bit data (i.e. 2 bytes or 1 word) sent by the sending circuit board is fed back with a 16-bit data by the receiving circuit board at the same time. The receiving circuit board cannot wait for the first 16-bit data to be received, and then determine what kind of data to feed back after judgment and processing. Therefore, the first 16-bit data fed back by the receiving circuit board is invalid data and cannot be used for data communication, and can only be discarded. This results in that the valid data of the sending circuit board and the receiving circuit board are not aligned, and an extra 16-bit data needs to be sent after the valid data.
[0035] Due to the above reasons, if the circuit board needs to continue to send a 16-bit data after sending all the data, it requests other circuit boards to feedback the last valid data. For example, the valid data sent by the circuit board is 5 16-bit data, but due to the characteristics of SPI communication, actually 6 16-bit data are sent, and the last 16-bit data is meaningless. The feedback data actually received by the circuit board is also 6 16-bit data, but the first 16-bit data is invalid, and the circuit board needs to discard the first 16-bit data after receiving the data, and use the second to sixth 16-bit data as valid data.
[0036] Figure 2 The schematic diagram of SPI data message communication between two circuit boards in the embodiment of the application is shown in FIG. 1, and the method proposed in the embodiment of the application is applied to the circuit board 2 in FIG. 1, and the specific process includes the following steps. Figure 2
[0037] The first data of the first SPI data message sent by the circuit board 1 is H, indicating a header identifier, and the data is received by the circuit board 2, and the communication message is defined as R1. At the same time, the data dm sent by the circuit board 2 is invalid data, and the data is received by the circuit board 1, and the communication message is defined as T1.
[0038] The second data sent by the circuit board 1 is L, indicating the length of the message (the value is 9 in the above example), and the data is received by the circuit board 2, and the communication message is defined as R2. At the same time, the data h sent by the circuit board 2 is a feedback header identifier, and the data is received by the circuit board 1, and the communication message is defined as T2.
[0039] The third data sent by the circuit board 1 is D0, indicating valid data 0, and the data is received by the circuit board 2, and the communication message is defined as R3. At the same time, the data l sent by the circuit board 2 is a feedback valid data length (the value is 9 in the above example), and the data is received by the circuit board 1, and the communication message is defined as T3.
[0040] The fourth data sent by the circuit board 1 is D1, indicating valid data 1, and the data is received by the circuit board 2, and the communication message is defined as R4. At the same time, the data d0 sent by the circuit board 2 is a feedback valid data 0, and the data is received by the circuit board 1, and the communication message is defined as T4.
[0041] The fifth data sent by the circuit board 1 is D2, indicating valid data 2, and the data is received by the circuit board 2, and the communication message is defined as R5. At the same time, the data d1 sent by the circuit board 2 is a feedback valid data 1, and the data is received by the circuit board 1, and the communication message is defined as T5.
[0042] The 12th data sent by the circuit board 1 is C1, indicating a valid data check value, and the circuit board 2 receives the data, and the communication message is defined as R12. Meanwhile, the circuit board 2 sends data d8, which is a feedback valid data 8, and the circuit board 1 receives the data, and the communication message is defined as T12.
[0043] The 13th data sent by the circuit board 1 is C1, which is a placeholder data, used to trigger the circuit board 2 to send a valid data check value, and the circuit board 2 receives the data, and the communication message is defined as R13. Meanwhile, the circuit board 2 sends data c1, which is a feedback valid data check value, and the circuit board 1 receives the data, and the communication message is defined as T13.
[0044] Figure 3 The circuit board 2 receives data and processes the data in the embodiment of the application. The circuit board 2 starts a first timer Timer1 with a short period after receiving data each time, and the period is Timeout1, which is used as a watchdog for the data transmission of the current communication message T and R, for monitoring whether the current data communication is timed out; and a second timer Timer2 with a long period is started at the same time, and the period is Timeout2, which is used as a watchdog for the data transmission of multiple transmission messages T and R.
[0045] The circuit board 1 receives data at the same time of sending data each time, and then delays for a sleep time, and then starts the next data sending. Because the task timing and the program running branches are different, each sleep time is different, thus affecting the correct identification of the SPI communication baud rate. The interval time of the communication messages R of the adjacent two data communications has a timing deviation, and the time change of the program task processing and the like occurs, thus the circuit board 2 cannot accurately predict the data arrival time, so that the data cannot be prepared, the data communication is slow, and the like occur.
[0046] In step 101, after receiving the communication message of the SPI data message sent by the other circuit board, a first timer (with a period of Timeout1_def) and a second timer are started at the same time, wherein the first timer is used to monitor whether the current transmission is timed out; the second timer is used to monitor whether multiple transmissions are timed out; the period of the first timer is shorter than the period of the first timer;
[0047] The period Timeout2_def is calculated according to a preset rule, for example, the rule is Timeout2_def=100×Timeout1_def, which represents that the period of the second timer is 100 times of the period of the first timer, and is used to capture 100 times of data exchange processes.
[0048] In step 102, after receiving the communication message of the data again, it is checked whether the first timer is timed out, and if not, the remaining time of the first timer is calculated;
[0049] If the first timer expires, it means that the period of the first timer is too short, and the period of the first timer is extended, and the period of the second timer is extended according to a preset rule, so as to improve the data transmission success rate, effectiveness and consistency.
[0050] Generally, the period of the first timer is usually selected to be increased by 1 time, and the period of the second timer is calculated according to the formula Timeout2 = 100 x Timeout1.
[0051] If the first timer does not expire, it means that the actual time spent in transmitting 1 16-bit data is less than the current period Timeout1_c of the first timer, and the remaining time T_left1 of the current first timer is recorded. At this time, the time spent in transmitting 1 16-bit data is Timeout1_c-T_left1.
[0052] In an embodiment, the method further comprises:
[0053] If the first timer does not expire, it is checked whether the second timer expires;
[0054] If the second timer expires, it means that the actual time spent in SPI communication of 100 16-bit data is greater than the current period of the second timer, and the period of the second timer is extended, for example, 1 period of the current first timer is added to the current period of the second timer, so as to preliminarily meet the time spent in SPI communication of 100 16-bit data. In this way, the data transmission success rate, effectiveness and consistency can be further improved.
[0055] In step 103, when the second timer first does not expire, the remaining time T_left2 of the second timer is recorded, and at this time the time spent in transmitting 1 16-bit data is Timeout1_c-T_left2. If neither the first timer nor the second timer expires again, it means that the actual time spent in transmitting 1 16-bit data is less than Timeout1_c, and the actual time spent in transmitting 100 16-bit data is less than Timeout2_c.
[0056] In step 104, when it is determined that the header identification of the received data is correct, the baud rate of the current SPI communication is calculated according to the period of the second timer, the remaining time of the first timer and the remaining time of the second timer.
[0057] In an embodiment, the method further comprises:
[0058] It is checked whether the header identification of the data is a preset header identification 0xA5A5;
[0059] If yes, it is determined that the header identification of the data is correct.
[0060] In an embodiment, the method further comprises:
[0061] If the header identification of the data is not the preset header identification 0xA5A5, the period of the first timer is shortened, and the data is received. In this way, the success rate, effectiveness and consistency of data transmission can be improved.
[0062] In an embodiment, the method further comprises:
[0063] The baud rate of the current SPI communication is set to the baud rate of the current circuit board.
[0064] In the foregoing embodiment, there are three key data Timeout2_c / 100, Timeout1_c-T_left1 and Timeout1_c-T_left2, which represent the time for transmitting one 16-bit data. Timeout2_c / 100 is the actual average time, which can eliminate the time jitter measured by the timer; Timeout1_c-T_left1 is the instantaneous time for single transmission, which can eliminate the time jitter caused by transmission sleep; and Timeout1_c-T_left2 is the instantaneous time after 100 transmissions, which can evaluate the average value of 99 transmission sleeps. The value is (T_left1-T_left2) / 99.
[0065] In an embodiment, the baud rate of the current SPI communication is calculated according to the period of the second timer, the remaining time length of the first timer and the remaining time length of the second timer, comprising:
[0066] The period ratio is calculated according to the period of the second timer and the period of the first timer.
[0067] The baud rate of the current SPI communication is calculated according to the period ratio, the remaining time length of the first timer and the remaining time length of the second timer.
[0068] In an embodiment, the period ratio is calculated by using the following formula:
[0069] C=Timeout2_c / Timeout1_c
[0070] Wherein, C is the period ratio, and Timeout1_c and Timeout2_c are the periods of the first timer and the second timer respectively.
[0071] The baud rate of the current SPI communication is calculated by using the following formula:
[0072] B = (Timeout2_c / C-(T_left1-T_left2) / (C-1)) / 16
[0073] Wherein, B is baud rate; T_left1, T_left2 are the remaining time length of the first timer and the second timer respectively.
[0074] The above embodiments are combined to give a specific embodiment, Figure 4 The specific flow chart of the SPI communication baud rate identification in the embodiment of the application is shown in Fig. 1. Figure 4 Wherein, timer 1 is the first timer, and timer 2 is the second timer.
[0075] The minimum time interval of the timer of the current circuit board 2 is 0.01 microsecond, the initial setting value of the timer 1 cycle is 10000000, and the equivalent 10M baud rate SPI communication can be detected. The timer 1 starts to count down from 10000000, and automatically decreases by 1 in each machine cycle. If the count value is 0, the timer 1 is timed out. The initial setting value of the timer 2 cycle is 1000000, and automatically decreases by 1 in each machine cycle. If the count value is 0, the timer 2 is timed out.
[0076] After receiving the data, the timers 1 and 2 are started, and then the timers 1 and 2 start to count down. If the timer 1 is timed out, it indicates that no next data is received within 1 second. If this happens, it indicates that the interval time between two data is greater than 1 second, and the cycle of the timer 1 needs to be further increased, and the setting value is set to 20000000, and the setting value of the timer 2 is set to 200000000.
[0077] If the timer 2 is timed out, it indicates that the complete SPI data is not received within the timing cycle of the timer 2, and the situation of receiving half of the SPI data occurs, and the cycle of the timer 2 needs to be prolonged, and the cycle of the timer 2 is increased, and the setting value is set to 220000000.
[0078] The average value of sleep (T_left1-T_left2) / 99 is calculated, according to the data, the average time of a data transmission can be evaluated as Timeout1_c-(T_left1-T_left2) / 99, and then the baud rate of the SPI communication is calculated, and the baud rate of the current SPI communication is set as the baud rate of the current circuit board.
[0079] The SPI data is continuously received subsequently, and if the header of the first data currently received is identified as 0xA5A5, it indicates that the received data is correct, and the correctness of the SPI baud rate is verified.
[0080] If the header identifier of the received data is not 0xA5A5, the period of the first timer is reduced by 0.01 times of the sleep average, at this time, Timeout1_c-(T_left1-T_left2) / 99-(T_left1-T_left2) / 9900 is set, and the data is continuously read until the header identifier of the data is 0xA5A5.
[0081] In summary, in the method provided in the embodiment of the application, after receiving the communication message of the data of the SPI data message sent by other circuit boards, the first timer and the second timer are started at the same time, wherein the first timer is used to monitor whether the current transmission is timed out; the second timer is used to monitor whether multiple transmissions are timed out; the period of the first timer is shorter than the period of the first timer; after receiving the communication message of the data again, it is checked whether the first timer is timed out, if not, the remaining time length of the first timer is calculated; when the second timer is not timed out for the first time, the remaining time length of the second timer is recorded; when it is determined that the header identifier of the received data is correct, the baud rate of the current SPI communication is calculated according to the period of the second timer, the remaining time length of the first timer and the remaining time length of the second timer. In the above process, the accurate baud rate is calculated through the two timers, which is used for communication to ensure the success rate of communication, data validity and consistency; the above process also does not need to repeatedly verify the correctness of the data, thereby improving the communication efficiency. In addition, if the first timer is timed out, the periods of the two timers are prolonged, if the second timer is timed out, the period of the second timer is prolonged, and if the header identifier of the data is not the preset header identifier, the period of the first timer is shortened, which can further improve the data transmission success rate, validity and consistency.
[0082] The embodiment of the application also provides an SPI communication baud rate identification device applied to the circuit board in the SPI communication baud rate identification system, and the principle of the device is similar to that of the SPI communication baud rate identification method, which will not be described herein.
[0083] Figure 5 The schematic diagram of the SPI communication baud rate identification device in the embodiment of the application comprises:
[0084] The timer starting module 501 is used to start the first timer and the second timer at the same time after receiving the communication message of the data of the SPI data message sent by other circuit boards, wherein the first timer is used to monitor whether the current transmission is timed out; the second timer is used to monitor whether multiple transmissions are timed out; the period of the first timer is shorter than the period of the first timer;
[0085] The timeout judging module 502 is configured to, after receiving the communication packet with data again, check whether the first timer is timed out, and if not, calculate the remaining time length of the first timer; and when the second timer is not timed out for the first time, record the remaining time length of the second timer.
[0086] The baud rate calculating module 503 is configured to, when it is determined that the header of the received data is correct, calculate the baud rate of the current SPI communication according to the period of the second timer, the remaining time length of the first timer and the remaining time length of the second timer.
[0087] In an embodiment, the timeout judging module 502 is further configured to:
[0088] If the first timer is timed out, the period of the first timer is extended, and the period of the second timer is extended according to a preset rule.
[0089] In an embodiment, the timeout judging module 502 is further configured to:
[0090] If the first timer is not timed out, check whether the second timer is timed out.
[0091] If the second timer is timed out, the period of the second timer is extended.
[0092] In an embodiment, the baud rate calculating module 503 is specifically configured to:
[0093] The baud rate calculating module 503 is configured to, when it is determined that the header of the received data is correct, calculate the baud rate of the current SPI communication according to the period of the second timer, the remaining time length of the first timer and the remaining time length of the second timer.
[0094] Calculate the period ratio according to the period of the second timer and the period of the first timer.
[0095] Calculate the baud rate of the current SPI communication according to the period ratio, the remaining time length of the first timer and the remaining time length of the second timer.
[0096] In an embodiment, the baud rate calculating module 503 is specifically configured to:
[0097] The period ratio is calculated by using the following formula:
[0098] C = Timeout2_c / Timeout1_c
[0099] Wherein, C is the period ratio, and Timeout1_c and Timeout2_c are the periods of the first timer and the second timer respectively.
[0100] The baud rate of the current SPI communication is calculated by using the following formula:
[0101] B = (Timeout2_c / C-(T_left1-T_left2) / (C-1)) / 16
[0102] Wherein, B is baud rate; T_left1 and T_left2 are the remaining time of the first timer and the second timer respectively.
[0103] In an embodiment, the baud rate calculation module 503 is further configured to:
[0104] checking whether the header identification of the data is the preset header identification;
[0105] If yes, determining that the header identification of the data is correct.
[0106] In an embodiment, the baud rate calculation module 503 is further configured to:
[0107] If the header identification of the data is not the preset header identification, shortening the period of the first timer and waiting for receiving the data.
[0108] In an embodiment, the baud rate calculation module 503 is further configured to:
[0109] setting the baud rate of the current SPI communication as the baud rate of the current circuit board.
[0110] In summary, in the device provided in the embodiment of the application, after receiving the communication message of the SPI data message of the data sent by other circuit boards, the first timer and the second timer are started simultaneously, wherein the first timer is used to monitor whether the current transmission is timed out; the second timer is used to monitor whether the multiple transmissions are timed out; the period of the first timer is shorter than the period of the first timer; after receiving the communication message of the data again, it is checked whether the first timer is timed out, if not, the remaining time of the first timer is calculated; when the second timer is not timed out for the first time, the remaining time of the second timer is recorded; when it is determined that the header identification of the received data is correct, the baud rate of the current SPI communication is calculated according to the period of the second timer, the remaining time of the first timer and the remaining time of the second timer. In the above process, the accurate baud rate is calculated through the two timers, which is used for communication to ensure the success rate of communication, data validity and consistency; the above process also does not need to repeatedly verify the correctness of the data, thereby improving the communication efficiency. In addition, if the first timer is timed out, the periods of the two timers are prolonged, if the second timer is timed out, the period of the second timer is prolonged, and if the header identification of the data is not the preset header identification, the period of the first timer is shortened, which can further improve the data transmission success rate, validity and consistency.
[0111] Based on the foregoing inventive concept, as Figure 6As shown, the embodiment of the present application further provides a computer device 600, comprising a memory 610, a processor 620, and a computer program 630 stored in the memory 610 and capable of running on the processor 620, wherein the processor 620 implements the SPI communication baud rate recognition method when executing the computer program 630.
[0112] Based on the foregoing inventive concept, the embodiment of the present application further provides a computer readable storage medium, which stores a computer program, wherein the computer program is executed by a processor to implement the SPI communication baud rate recognition method.
[0113] The embodiment of the present application further provides a computer program product, which comprises a computer program, wherein the computer program is executed by a processor to implement the SPI communication baud rate recognition method.
[0114] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, etc.) containing computer-usable program code.
[0115] The present application is described with reference to the flowcharts and / or block diagrams of the method, device (system), and computer program product according to the embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing apparatus to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing apparatus produce a device implemented in the flowcharts and / or block diagrams. Figure 1 The function specified in one or more flows and / or blocks. Figure 1 The function specified in one or more flows and / or blocks.
[0116] These computer program instructions can also be stored in a computer readable memory capable of directing the computer or other programmable data processing apparatus to work in a specific manner, so that the instructions stored in the computer readable memory produce a manufactured product comprising instruction means, which implement the flowcharts and / or block diagrams. Figure 1 The function specified in one or more flows and / or blocks. Figure 1 The function specified in one or more flows and / or blocks.
[0117] These computer program instructions can also be loaded into a computer or other programmable data processing devices, so that a series of operational steps are performed on the computer or other programmable data processing devices to generate a computer implemented process, so that the instructions executed on the computer or other programmable data processing devices provide a process for implementing the flowchart Figure 1 one flow or multiple flows and / or the functions specified in the block Figure 1 one flow or multiple flows and / or the functions specified in the block
[0118] The above-described specific embodiments, the purpose, technical solutions and beneficial effects of the present application are further described in detail, it should be understood that the above-described is only a specific embodiment of the present application, and is not used to limit the protection scope of the present application, any modification, equivalent replacement, improvement, etc. within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. A method for identifying the baud rate of SPI communication, characterized in that, The circuit board used for SPI communication includes: After receiving a communication message containing SPI data packets from other circuit boards, a first timer and a second timer are started simultaneously. The first timer is used to monitor whether the current transmission times out; the second timer is used to monitor whether multiple transmissions time out; the period of the first timer is shorter than the period of the second timer. After receiving the data communication message again, check if the first timer has timed out. If not, calculate the remaining duration of the first timer. When the second timer does not time out for the first time, record the remaining duration of the second timer; Once it is confirmed that the header identifier of the received data is correct, the baud rate of the current SPI communication is calculated based on the period of the second timer, the remaining duration of the first timer, and the remaining duration of the second timer. Calculate the current SPI communication baud rate based on the period of the second timer, the remaining duration of the first timer, and the remaining duration of the second timer, including: calculating the period ratio based on the period of the second timer and the period of the first timer; and calculating the current SPI communication baud rate based on the period ratio, the remaining duration of the first timer, and the remaining duration of the second timer. The cycle ratio is calculated using the following formula: C = Timeout2_c / Timeout1_c Where C is the period ratio, and Timeout1_c and Timeout2_c are the periods of the first timer and the second timer, respectively; The baud rate of the current SPI communication is calculated using the following formula: B=( Timeout2_c / C - (T_left1- T_left2) / (C-1)) / 16 Where B is the baud rate; T_left1 and T_left2 are the remaining durations of the first and second timers, respectively; If the first timer times out, extend the period of the first timer and extend the period of the second timer according to the preset rules. Check if the data header identifier is the preset header identifier; If so, confirm that the data header identifier is correct.
2. The method as described in claim 1, characterized in that, Also includes: If the first timer does not time out, check if the second timer has timed out. If the second timer times out, extend the period of the second timer.
3. The method as described in claim 1, characterized in that, Also includes: If the data header identifier is not the preset header identifier, shorten the period of the first timer and wait to receive data.
4. The method as described in claim 1, characterized in that, Also includes: Set the current SPI communication baud rate to the current board baud rate.
5. An SPI communication baud rate identification device, characterized in that, The circuit board used for SPI communication includes: The timer startup module is used to simultaneously start a first timer and a second timer after receiving a communication message of SPI data packets sent by other circuit boards. The first timer is used to monitor whether the current transmission has timed out; the second timer is used to monitor whether multiple transmissions have timed out; the period of the first timer is shorter than the period of the second timer. The timeout detection module is used to check whether the first timer has timed out after receiving a data communication packet again. If not, it calculates the remaining duration of the first timer. When the second timer does not time out for the first time, it records the remaining duration of the second timer. The baud rate calculation module is used to calculate the baud rate of the current SPI communication based on the period of the second timer, the remaining duration of the first timer, and the remaining duration of the second timer when it is determined that the header identifier of the received data is correct. Calculate the current SPI communication baud rate based on the period of the second timer, the remaining duration of the first timer, and the remaining duration of the second timer, including: calculating the period ratio based on the period of the second timer and the period of the first timer; and calculating the current SPI communication baud rate based on the period ratio, the remaining duration of the first timer, and the remaining duration of the second timer. The cycle ratio is calculated using the following formula: C = Timeout2_c / Timeout1_c Where C is the period ratio, and Timeout1_c and Timeout2_c are the periods of the first timer and the second timer, respectively; The baud rate of the current SPI communication is calculated using the following formula: B=( Timeout2_c / C - (T_left1- T_left2) / (C-1)) / 16 Where B is the baud rate; T_left1 and T_left2 are the remaining durations of the first and second timers, respectively; If the first timer times out, extend the period of the first timer and extend the period of the second timer according to the preset rules. Check if the data header identifier is the preset header identifier; If so, confirm that the data header identifier is correct.
6. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method of any one of claims 1 to 4.
8. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the method of any one of claims 1 to 4.
Citation Information
Patent Citations
Method for identifying serial port communication baud rate and readable storage medium
CN111427818A
Quantum circuit task timeout reason determination method and device, equipment and storage medium
CN115879561A