SPI-based data communication method and device, vehicle and storage medium
By improving the SPI communication mechanism, the sending end and the receiving end receive response messages while sending data and adjusting the state machine status, the problem of low SPI communication performance is solved, and the full utilization of bandwidth resources and the reliability of data transmission is achieved.
Patent Information
- Application Number
- CN202510766450.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-10
- Publication Date
- 2025-08-12
AI Technical Summary
In the existing SPI communication protocol, the communication performance is low, resulting in the underutilization of the SPI bus bandwidth resources.
By improving the communication mechanism, the sending end and the receiving end receive the other party's response message while sending data, and determine whether the request message needs to be retransmitted based on the response message, ensuring dynamic adjustment of the state machine state to utilize the bidirectional communication bandwidth.
It improves the performance of SPI communication, realizes the full utilization of bandwidth resources, and ensures the reliability and efficiency of data transmission.
Smart Images

Figure CN120474671A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of vehicle communication technology, and in particular to a data communication method, device, vehicle, and storage medium based on SPI. Background Art
[0002] In vehicle cockpit systems, the Serial Peripheral Interface (SPI) communication protocol is often used for data exchange between the System on Chip (SOC) and the Microcontroller Unit (MCU). The traditional SPI communication protocol uses a bidirectional communication process: the SOC sends a message, waits for a response from the MCU, and only sends the next message after receiving the response. This communication method has obvious drawbacks. Because the reverse channel of the SPI bus is idle when the SOC sends a message, and the forward channel is idle when waiting for a response, it actually only utilizes half of the bandwidth resources, resulting in poor communication performance. Summary of the Invention
[0003] The present invention provides a data communication method, device, vehicle and storage medium based on SPI, so as to solve the problem of low communication performance in the prior art when communicating based on the SPI communication protocol.
[0004] According to one aspect of the present invention, there is provided a data communication method based on SPI, the method comprising:
[0005] When the state machine of the sending end is in an idle state, sending a first request message to the receiving end to modify the state machine to a first sending state;
[0006] While sending the second request message to the receiving end, receiving a third message sent by the receiving end, and modifying the state machine to a second sending state;
[0007] determining whether the first request message needs to be retransmitted based on the third message;
[0008] If not necessary, the state machine of the sending end is modified to the first sending state, the second request message is used as the first request message, and the new second request message is continued to be sent and the new third message is received; if necessary, the state machine of the sending end is modified to the retransmission state, and the first request message is retransmitted.
[0009] According to another aspect of the present invention, there is provided a data communication method based on SPI, the method comprising:
[0010] When the state machine of the receiving end is in an idle state, receiving a first request message sent by the sending end, and changing the state of the state machine to a third response state;
[0011] while sending the third message to the sending end, receiving a second request message sent by the sending end;
[0012] While continuing to send the new third message to the sending end, a request message sent by the sending end is received, where the request message is the first request message or the second request message.
[0013] According to another aspect of the present invention, there is provided a data communication device based on SPI, the device comprising:
[0014] A first sending module, configured to send a first request message to a receiving end to modify the state machine to a first sending state when the state machine of the sending end is in an idle state;
[0015] A second sending module is configured to receive a third message sent by the receiving end while sending a second request message to the receiving end, and modify the state machine to a second sending state;
[0016] a determining module, configured to determine whether the first request message needs to be retransmitted based on the third message;
[0017] The third sending module is used to modify the state machine of the sending end to the first sending state if not needed, use the second request message as the first request message, and continue to send new second request messages and receive new third messages; if necessary, modify the state machine of the sending end to the retransmission state and retransmit the first request message.
[0018] According to another aspect of the present invention, there is provided a data communication device based on SPI, the device comprising:
[0019] a receiving module, configured to receive a first request message sent by the transmitting end when the state machine of the receiving end is in an idle state, and modify the state of the state machine to a third response state;
[0020] a fourth sending module, configured to receive a second request message sent by the sending end while sending the third message to the sending end;
[0021] The fifth sending module receives a request message sent by the sending end while continuing to send a new third message to the sending end, where the request message is the first request message or the second request message.
[0022] According to another aspect of the present invention, there is provided a vehicle comprising: at least one processor; and
[0023] a memory communicatively connected to the at least one processor; wherein,
[0024] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the SPI-based data communication method described in any embodiment of the present invention.
[0025] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the SPI-based data communication method according to any embodiment of the present invention when executed.
[0026] An embodiment of the present invention provides an SPI-based data communication method, device, vehicle, and storage medium. The method includes: when a state machine of a transmitting end is in an idle state, sending a first request message to a receiving end, and modifying the state machine to a first transmitting state; while sending a second request message to the receiving end, receiving a third message sent by the receiving end, and modifying the state machine to a second transmitting state; determining whether the first request message needs to be retransmitted based on the third message; if not, modifying the state machine of the transmitting end to the first transmitting state, using the second request message as the first request message, and continuing to send a new second request message and receive a new third message; if necessary, modifying the state machine of the transmitting end to a retransmission state, and retransmitting the first request message. By sending data to the receiving end and receiving data sent by the receiving end at the same time, all bandwidth resources can be utilized, communication performance can be improved, and the problem of low communication performance in the prior art when communicating based on the SPI communication protocol is solved.
[0027] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0029] Figure 1 A schematic diagram of a flow chart of a data communication method based on SPI provided in the first embodiment of the present invention;
[0030] Figure 2A schematic diagram of a flow chart of a data communication method based on SPI provided in an embodiment of the present invention;
[0031] Figure 3 A schematic diagram of modifying the state of a state machine provided in an embodiment of the present invention;
[0032] Figure 4 A schematic diagram of a second state machine modification state provided by an embodiment of the present invention;
[0033] Figure 5 A schematic diagram of a third state modification state machine provided in an embodiment of the present invention;
[0034] Figure 6 A schematic diagram of a fourth state modification state machine provided by an embodiment of the present invention;
[0035] Figure 7 A schematic diagram of a fifth state modification state machine provided by an embodiment of the present invention;
[0036] Figure 8 A schematic diagram of normal communication provided by an embodiment of the present invention;
[0037] Figure 9 A schematic diagram of abnormal communication provided by an embodiment of the present invention;
[0038] Figure 10 A schematic diagram of another abnormal communication provided by an embodiment of the present invention;
[0039] Figure 11 A schematic diagram of normal communication provided by an embodiment of the present invention;
[0040] Figure 12 A schematic diagram of another abnormal communication provided by an embodiment of the present invention;
[0041] Figure 13 A flow chart of a data communication method based on SPI provided in the second embodiment of the present invention;
[0042] Figure 14 A schematic structural diagram of an SPI-based data communication device provided in Embodiment 3 of the present invention;
[0043] Figure 15 A schematic structural diagram of an SPI-based data communication device provided in a fourth embodiment of the present invention;
[0044] Figure 16 Schematic diagram of the structure of a vehicle according to an embodiment of the present invention. DETAILED DESCRIPTION
[0045] In order to enable those skilled in the art to better understand the 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 drawings in the embodiments of the present invention. Obviously, the described embodiments are only embodiments of a part of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work should fall within the scope of protection of the present invention. It should be understood that the various steps described in the method implementation mode of the present invention can be performed in different orders and / or in parallel. In addition, the method implementation mode may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.
[0046] As used herein, the term "including" and its variations are open-ended, i.e., "including but not limited to." The term "based on" means "based, at least in part, on." The term "one embodiment" means "at least one embodiment," the term "another embodiment" means "at least one additional embodiment," and the term "some embodiments" means "at least some embodiments." Other terms are defined in the following description.
[0047] It should be noted that the terms "first," "second," and the like in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or precedence. It should be understood that the numbers used in this manner are interchangeable where appropriate so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, any variations of the terms "including" and "having" are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units that are explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to these processes, methods, products, or apparatus.
[0048] It should be noted that the modifications of "one" and "multiple" mentioned in the present invention are illustrative rather than restrictive. Those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0049] The names of the messages or information exchanged between multiple devices in the embodiments of the present invention are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0050] The SPI communication scheme currently used in automotive cockpit systems generally uses a method that sends the nth data item, data(n), waits for the nth acknowledgment, ack(n), sends the n+1th data item, data(n+1), and waits for the n+1th acknowledgment, ack(n+1). This method is simple to implement logically, but also has poor performance. In particular, when only one end has data to send, only half of the SPI bus bandwidth is utilized. Since only one end has data, which is the majority of system operations, only half of the SPI bus bandwidth is actually utilized.
[0051] The technical solution of this embodiment improves the communication mechanism and fully utilizes the bandwidth of SPI two-way communication to improve the communication efficiency between the SOC and MCU in the vehicle cockpit system. At the same time, it has a retransmission processing function in the event of transmission errors, which can ensure the reliability of data transmission.
[0052] Example 1
[0053] Figure 1 This is a flow chart of an SPI-based data communication method provided in Example 1 of the present invention. This method is applicable to data transmission. The method can be performed by an SPI-based data communication device, wherein the device can be implemented by software and / or hardware and is generally integrated on a vehicle. In this embodiment, the vehicle includes but is not limited to: smart vehicles, etc.
[0054] like Figure 1 As shown, the first embodiment of the present invention provides a data communication method based on SPI, including the following steps:
[0055] S110 : When the state machine of the sending end is in an idle state, send a first request message to the receiving end to modify the state machine to a first sending state.
[0056] The first request message may refer to data to which a response is required.
[0057] In this embodiment, when the state machine of the transmitting end is in an idle state, a first request message can be sent to the receiving end, and the state of the state machine can be modified to a first sending state. The transmitting end and the receiving end can be a SOC and an MCU, respectively. That is, when the transmitting end is an SOC, the receiving end is an MCU, and when the transmitting end is an MCU, the receiving end is an SOC. The state machine can be used to manage the communication status of the transmitting end and the receiving end, and each end is provided with a corresponding state machine. The state of the state machine may include an idle state, a response state, a sending state, and a retransmission state. The sending state may include a first sending state and a second sending state. When the state machine is in the first sending state, it indicates that the transmitting end has a data for which a corresponding response message has not been received.
[0058] S120. While sending the second request message to the receiving end, receive a third message sent by the receiving end, and modify the state machine to a second sending state.
[0059] In this embodiment, the first request message and the second request message may be messages that the sender needs to send. The specific method for obtaining them is not limited in this embodiment. For example, the first request message and the second request message may be obtained from a message queue. The message queue may be a message queue maintained by the sender and used to store messages to be sent. Each message may include information such as message content, message sequence number, number of transmissions, and response status. The message sequence number can be used to uniquely identify each message, facilitating tracking and processing.
[0060] In this embodiment, while the sending end sends the second request message to the receiving end, it can receive the third message sent by the receiving end and change the state machine to the second sending state. When the state is the second sending state, it means that the sending end has two data for which the corresponding response message has not been received.
[0061] S130. Determine whether the first request message needs to be retransmitted based on the third message.
[0062] In this embodiment, whether the first request message needs to be retransmitted can be determined by the third message. For example, if it is determined by the third message that the first request message is sent and the response is successful, the first request message does not need to be retransmitted.
[0063] In one embodiment, the determination of whether the first request message needs to be retransmitted based on the third message includes: when the third message is a response message corresponding to the first request message and the response message is verified to be correct, determining that the first request message does not need to be retransmitted; when the third message is a response message corresponding to the first request message and the response message includes an error flag, or the third message is a blank frame, determining that the first request message needs to be retransmitted.
[0064] In this embodiment, the third message can be a response message corresponding to the first request message, or it can be a blank frame. When the third message is a response message corresponding to the first request message and the response message is verified to be correct, it means that the first request message was sent successfully and the corresponding response was successfully received, and the first request message does not need to be retransmitted. When the third message is a response message corresponding to the first request message and the response message includes an error flag, it means that the first request message was not sent successfully. If the third message is a blank frame, it means that the corresponding response was not received, and the first request message needs to be retransmitted. By determining whether the third message is a correct response message, the success of data transmission can be further guaranteed.
[0065] When data is transmitted at both ends of the transmitting and receiving ends of this embodiment, the received data can be verified separately. Common verification methods can be used, such as Cyclic Redundancy Check (CRC). When sending data, the CRC check value of the data is calculated and sent together. After receiving the data, the receiver recalculates the CRC check value and compares it with the received check value. If the two are inconsistent, it is determined that the data transmission is erroneous. Exemplarily, the response message may include a check value. After receiving the response message, the transmitting end may also verify the response message. When the check value is correct, it is determined that the first request message does not need to be retransmitted. When the message sent by the other end is unanswered (for example, a blank frame for ack(n)), the SOC / MCU at one end has already sent the next request message data(n+1), so what is detected is the failure of the previous round of message sending.
[0066] The sending end of this embodiment may further set up a response cache for storing responses received from the other end. The response cache may be indexed according to message sequence numbers for quick search and comparison.
[0067] S140. If not required, the state machine of the sending end is modified to the first sending state, the second request message is used as the first request message, and new second request messages are continued to be sent and new third messages are received; if necessary, the state machine of the sending end is modified to the retransmission state, and the first request message is retransmitted.
[0068] When the state machine is in the retransmission state, the sending end expects to receive a response message corresponding to the sent request message.
[0069] In this embodiment, if the first request message does not need to be retransmitted, then the sender only has one request message for which no response message has been received. In this case, the sender's state machine can be modified to the first sending state, where treating the second request message as the first request message means treating the second request message as the next message to determine whether it needs to be retransmitted, and continuing to send a new second request message and receive a new third message. If the first request message needs to be retransmitted, the sender's state machine can be modified to the retransmission state, and the first request message can be retransmitted. For example, if there is a first request message data(n) and a second request message data(n+1), and a third message ack(n) is received when data(n+1) is sent, if ack(n) is the response message corresponding to data(n) and is verified to be correct, then data(n+1) is treated as the new first request message, and a new third message ack(n+1) is received while sending a new second request message data(n+2). Based on the new third message ack(n+1), it is determined whether the new first request message data(n+1) needs to be retransmitted.
[0070] In this embodiment, when one end detects that the previous request message failed to be sent (response missing or response error), it increments the request message's transmission count by 1 and marks its status in the message queue as retransmission. It also pauses the sending of new messages, prioritizing retransmissions. When the retransmitted request message successfully receives a valid response from the other end, it marks the message as successfully sent and removes it from the message queue. At the same time, the local end resumes the normal message sending process and selects the next pending message from the message queue for transmission.
[0071] In this embodiment, when retransmitting a request message, a priority can be set for the retransmission request message. This gives the retransmission request message a higher priority, and the sending end will preferentially select request messages in the retransmission state from the message queue for transmission. During the retransmission process, the parallel transmission and reception mode is maintained. That is, the retransmission request message is sent while the other end receives a response to the previous retransmission request message or normal request message.
[0072] Furthermore, a maximum number of retransmissions can be set for the retransmission request message to avoid infinite retransmissions. If the retransmission fails after reaching the maximum number of retransmissions, the communication task is considered failed and the error information is reported to the upper system for further processing.
[0073] Furthermore, you can set a retransmission interval for retransmission request messages to avoid excessive system pressure caused by frequent retransmissions. Between each retransmission, a certain amount of time will be waited before the next retransmission. The retransmission interval can be adjusted according to actual conditions.
[0074] In one embodiment, the state machine of the sending end is modified to a retransmission state, and the first request message is retransmitted, including: modifying the state machine of the sending end to a first retransmission state; while resending the first request message to the receiving end, receiving a fourth message sent by the receiving end; if the fourth message is a response message to the first request message, the state machine is modified to a first sending state, and the second request message is used as the first request message; if the fourth message is a response message to the second request message, the state machine is modified to a second retransmission state, and the first request message is retransmitted based on the second retransmission state.
[0075] The fourth message is the same as the third message, both indicating the message sent by the receiving end. The "third" and "fourth" are used only to distinguish the messages. Similarly, the fifth, sixth, seventh, eighth, and ninth messages mentioned later are also used to indicate the messages sent by the receiving end. The "fifth," "sixth," "seventh," "eighth," and "ninth" are used only to distinguish the messages. Whether the receiving end sends the third message or any other message, it can be represented by the fourth, fifth, sixth, seventh, eighth, or ninth message.
[0076] In this embodiment, the retransmission state may include a first retransmission state and a second retransmission state. When the state machine is in the first retransmission state, it indicates that the transmitting end has two data for which a response message has not been received. When the state machine is in the second retransmission state, it indicates that the transmitting end has one data for which a response message has not been received. When it is determined that the first request message needs to be retransmitted, the state machine of the transmitting end may be modified to the first retransmission state, and while retransmitting the first request message to the receiving end, a fourth message sent by the receiving end may be received. If the fourth message is a response message to the first request message, the state machine is modified to the first transmission state, and the second request message is used as the first request message. If the fourth message is a response message to the second request message, the state machine is modified to the second retransmission state, and the first request message is retransmitted based on the second retransmission state.
[0077] This embodiment can ensure that the sending end does not miss request data for which a response message needs to be received by setting different retransmission states.
[0078] For example, Figure 2 A flow chart of a data communication method based on SPI provided in an embodiment of the present invention is shown as follows: Figure 2As shown, when the state machine is in the second sending state, if the received third message is not ack(n), the first request message data(n) needs to be retransmitted, and the state machine of the sender is modified to the first retransmission state. While retransmitting data(n), the fourth message is received. If the fourth message is ack(n), the state machine is modified to the first sending state. If the fourth message is ack(n+1), the state machine is modified to the second retransmission state, and the first request message is retransmitted based on the second retransmission state.
[0079] In one embodiment, the retransmission of the first request message based on the second retransmission state includes: resending the first request message to the receiving end while receiving the fifth message sent by the receiving end; if the fifth message is a response message to the first request message, the state machine is modified to an idle state.
[0080] In this embodiment, if the state machine is in the second retransmission state, then while sending the first request message to the receiving end, the fifth message sent by the receiving end is received. If the fifth message is a response message to the first request message, the state machine is modified to the idle state. For example, Figure 2 As shown, when the state machine is in the second retransmission state, while retransmitting data(n), a fifth message is received. If the fifth message is ack(n), the state machine is changed to the idle state. This embodiment ensures the accuracy of the data transmission process by switching the state machine when the transmitting end receives different types of messages.
[0081] In one embodiment, when the fourth message is a request message, the method further includes: modifying the state machine to a first retransmission response state; while sending a response message corresponding to the request message to the receiving end, receiving a new sixth message sent by the receiving end, and modifying the state machine to the first retransmission state; using the sixth message as a new fourth message, modifying the state of the state machine based on the new fourth message, and executing corresponding steps.
[0082] In this embodiment, if the fourth message is a request message, a response to the request message is required. Specifically, the state machine is modified to the first retransmission response state. A response message corresponding to the request message is sent to the receiving end. Simultaneously, the sixth message sent by the receiving end is received and the state machine is modified to the first retransmission state. The sixth message is then treated as the new fourth message, and the state machine state is modified based on the new fourth message, and the corresponding steps are executed. By changing the state of the state machine after receiving a request message, this embodiment ensures that the state machine prioritizes responding to the request message upon receiving it.
[0083] For example, Figure 3A schematic diagram of modifying the state of a state machine provided by an embodiment of the present invention, such as Figure 3 As shown, if the sending end receives the request message pdata(m), the state machine is modified to the first retransmission response state, and while sending the response message pack(m) to the receiving end, the new sixth message sent by the receiving end is received (the process diagram of receiving the sixth message is not shown), and the state machine is modified to the first retransmission state. The sixth message is used as the new fourth message, and the state of the state machine is modified based on the new fourth message, and subsequent processing continues. That is, if the fourth message is a response message to the first request message, the state machine is modified to the first sending state, and the second request message is used as the first request message; if the fourth message is a response message to the second request message, the state machine is modified to the second retransmission state, and the first request message is retransmitted based on the second retransmission state; if the fourth message is a request message, the state machine is modified to the first retransmission response state.
[0084] In one embodiment, when the fifth message is a request message, the method further includes: modifying the state machine to a second retransmission response state; while sending a response message corresponding to the request message to the receiving end, receiving the seventh message sent by the receiving end, and modifying the state machine to a second retransmission state; using the seventh message as a new fifth message, modifying the state of the state machine based on the new fifth message, and executing corresponding steps.
[0085] In this embodiment, when the state machine is in the second retransmission state, if the message received is a request message while a first request message is sent to the receiving end, the state machine is modified to the second retransmission response state. While a response message corresponding to the request message is sent to the receiving end, a seventh message sent by the receiving end is received, and the state machine is modified to the second retransmission state. The seventh message is used as the new fifth message, and the state of the state machine is modified based on the new fifth message. The corresponding steps are performed, that is, when the fifth message is a response message to the first request message, the state machine is modified to the idle state. By changing the state of the state machine after receiving a request message, this embodiment ensures that the state machine prioritizes responding to the request message when it receives it.
[0086] For example, Figure 4 A schematic diagram of a second modification state machine state provided by an embodiment of the present invention, such as Figure 4 As shown, if the sending end receives the request message pdata(m), the state machine is modified to the second retransmission response state, and a response message pack(m) is sent to the receiving end while receiving the new seventh message sent by the receiving end, and the state machine is modified to the second retransmission state.
[0087] A data communication method based on SPI is provided in a first embodiment of the present invention, comprising: when the state machine of the transmitting end is in an idle state, sending a first request message to the receiving end, and modifying the state machine to a first transmitting state; while sending a second request message to the receiving end, receiving a third message sent by the receiving end, and modifying the state machine to a second transmitting state; determining whether the first request message needs to be retransmitted based on the third message; if not, modifying the state machine of the transmitting end to the first transmitting state, using the second request message as the first request message, and continuing to send a new second request message and receive a new third message; if necessary, modifying the state machine of the transmitting end to a retransmission state, and retransmitting the first request message. By sending data to the receiving end and receiving data sent by the receiving end at the same time, all bandwidth resources can be utilized, communication performance can be improved, and the problem of low communication performance in the prior art when communicating based on the SPI communication protocol is solved.
[0088] Based on the above embodiment, a modified embodiment of the above embodiment is proposed. It should be noted that, in order to simplify the description, only the differences from the above embodiment are described in the modified embodiment.
[0089] In one embodiment, when the third message is a request message, the method further includes: modifying the state machine to a second sending response state; while sending a response message corresponding to the request message to the receiving end, receiving an eighth message sent by the receiving end, and modifying the state machine to the second sending state; using the eighth message as a new third message, and executing the step of determining whether the first request message needs to be retransmitted based on the third message.
[0090] In this embodiment, if the third message sent by the receiving end is a request message while the second request message is sent to the receiving end, the state machine is modified to the second sending response state, and the eighth message sent by the receiving end is received while the response message corresponding to the request message is sent to the receiving end, and the state machine is modified to the second sending state; the eighth message is used as the new third message, and the step of determining whether the first request message needs to be retransmitted based on the third message is performed. For example, Figure 5 A schematic diagram of a third state machine modification state provided by an embodiment of the present invention, such as Figure 5 As shown, if the sending end receives the request message pdata(m), the state machine is modified to the second sending response state, and a response message pack(m) is sent to the receiving end while receiving the eighth message sent by the receiving end, and the state machine is modified to the second sending state.
[0091] In one embodiment, the method also includes: when the state machine of the sending end is in an idle state, if a request message sent by the receiving end is received, the state machine is modified to a third response state; and a response message corresponding to the request message is sent to the receiving end to modify the state machine to an idle state.
[0092] Among them, when the state machine is in the third response state, it can indicate that the sending end has not received a request message for which a response message has been received, but needs to send a response message to the receiving end.
[0093] In this embodiment, when the state machine of the sending end is in the idle state, if a request message from the receiving end is received, the state machine is modified to the third response state; a response message corresponding to the request message is sent to the receiving end, and the state machine is modified to the idle state. For example, Figure 6 A schematic diagram of a fourth modification state machine state provided by an embodiment of the present invention, such as Figure 6 As shown, if the sending end receives the request message pdata(m), the state machine is modified to the third response state, and after sending the response message pack(m) to the receiving end, the state machine is modified to the idle state.
[0094] In one embodiment, the method also includes: when the state machine of the sending end is in an idle state, if the sending end receives a request message sent by the receiving end while sending a first request message to the receiving end, the state machine is modified to a first sending response state; a response message corresponding to the request message is sent to the receiving end, and a ninth message sent by the receiving end is received, and the state machine is modified to the first sending state; based on the ninth message, it is determined whether the first request message needs to be retransmitted; if not, the state machine is modified to an idle state; if necessary, the state machine is modified to a retransmission state, and the first request message is retransmitted.
[0095] In this embodiment, when the state machine of the sending end is in the idle state, if the sending end receives a request message sent by the receiving end while sending the first request message to the receiving end, the state machine needs to be modified to the first sending response state, and while sending the response message corresponding to the request message to the receiving end, the ninth message sent by the receiving end is received, and the state machine is modified to the first sending state; based on the ninth message, it is determined whether the first request message needs to be retransmitted; if not, the state machine is modified to the idle state; if necessary, the state machine is modified to the retransmission state, and the first request message is retransmitted.
[0096] For example, Figure 7 A schematic diagram of a fifth modification state machine state provided by an embodiment of the present invention, such as Figure 7As shown, if the sending end receives the request message pdata(m), the state machine is modified to the first sending response state, and a response message pack(m) is sent to the receiving end while receiving the ninth message sent by the receiving end, and the state machine is modified to the first sending state.
[0097] The embodiments of the present invention provide several specific implementation methods based on the technical solutions of the above embodiments.
[0098] As a specific implementation method of this embodiment, Figure 8 A schematic diagram of a normal communication provided by an embodiment of the present invention, such as Figure 8 As shown in the figure, the sender is A and the receiver is B. At this point, only A sends a request message. In frame n, the sender sends data(n), and the receiver sends ack(n-1). In frame n+1, the sender sends data(n+1), and the receiver sends ack(n). In frame n+2, the sender sends data(n+2), and the receiver sends ack(n+1). By predicting the ack one frame in advance, the traditional method of waiting for a response before sending the next message is broken.
[0099] Figure 9 A schematic diagram of abnormal communication provided by an embodiment of the present invention, such as Figure 9 As shown in the figure, in frame n, the sender sends data(n). The receiver should have sent ack(n-1), but it hasn't yet acknowledged the data in frame n-1. Therefore, in frame n+1, the sender sends data(n-1), and the receiver sends ack(n). In frame n+2, because the sender hasn't received ack(n-1), the sender continues to send data(n-1), and the receiver sends ack(n-1). In frame n+3, the sender has already received ack(n-1) and will continue to send data(n+1). However, because data(n-1) was sent in the previous frame, it now receives ack(n-1). In frame n+4, the sender and receiver resume communication, and the sender continues to send data(n+2), and the receiver sends ack(n+1).
[0100] Figure 10 A schematic diagram of another abnormal communication provided by an embodiment of the present invention, such as Figure 10 As shown in the figure, when the sender retransmits data(n-1) in the n+1 frame, it does not receive the response message of data(n). Therefore, the sender A will continue to retransmit data(n-1) in the n+2 frame. If ack(n-1) is received in the n+2 frame, the sender will retransmit data(n) in the n+3 frame and resume communication in the n+4 frame.
[0101] Figure 11 A schematic diagram of a normal communication provided by an embodiment of the present invention, such as Figure 11 As shown in the figure, both A and B send request messages. In the nth frame, A sends data(n) and B sends data(k). In the n+1th frame, both ends send response messages: A sends ack(k) and B sends ack(n). In the n+2th frame, A sends data(n+1) and B sends data(k+1).
[0102] Figure 12 A schematic diagram of another abnormal communication provided by an embodiment of the present invention, such as Figure 12 As shown in the figure, in frame n, end A sends data(n) and end B sends data(k). In frame n+1, end A sends ack(k), but end B does not send ack(n). Therefore, in frame n+2, end A resends data(n), while end B continues to send data(k+1). In frame n+3, end A sends ack(k+1), and end B sends ack(n). In frame n+4, end A sends data(n+1) and end B sends data(k+2). Communication between A and B is restored, and communication between B and A is unaffected.
[0103] Example 2
[0104] Figure 13 This is a flow chart of an SPI-based data communication method provided in Example 2 of the present invention. This method is applicable to data transmission and can be performed by an SPI-based data communication device, which can be implemented in software and / or hardware and is generally integrated into a vehicle. In this embodiment, vehicles include, but are not limited to, smart vehicles. For details not yet fully detailed in this embodiment, please refer to Example 1.
[0105] like Figure 13 As shown, a data communication method based on SPI provided in the second embodiment of the present invention includes the following steps:
[0106] S210: When the state machine of the receiving end is in an idle state, receive a first request message sent by the sending end, and change the state of the state machine to a third response state.
[0107] S220. While sending a third message to the sending end, receive a second request message sent by the sending end.
[0108] S230: While continuing to send a new third message to the sending end, receive a request message sent by the sending end, where the request message is a first request message or a second request message.
[0109] In this embodiment, the receiving end changes the state of the state machine in the same manner as the transmitting end. When the state machine of the receiving end is in the idle state, it receives the first request message sent by the transmitting end and changes the state of the state machine to the third response state. While simultaneously sending the third message to the transmitting end, it receives the second request message from the transmitting end. In the next frame, while continuing to send a new third message to the transmitting end, it also receives the request message from the transmitting end, which may be the first request message or the second request message.
[0110] A second embodiment of the present invention provides an SPI-based data communication method, comprising: when a state machine at a receiving end is in an idle state, receiving a first request message sent by a transmitting end, and modifying the state of the state machine to a third response state; while simultaneously sending the third message to the transmitting end, receiving a second request message sent by the transmitting end; while continuing to send a new third message to the transmitting end, receiving a request message sent by the transmitting end, wherein the request message is either the first request message or the second request message. While the receiving end sends data to the transmitting end, it also receives the data sent by the transmitting end, thereby utilizing all bandwidth resources and improving communication performance, thereby resolving the problem of low communication performance in the prior art when communicating based on the SPI communication protocol.
[0111] In one embodiment, the third message is a response message or a blank frame corresponding to the request message.
[0112] In this embodiment, after receiving a request message, if the receiving end detects an error in the received request message, it will set an error flag (Negative Acknowledgement, NACK) in the response message to inform the other end that the message transmission failed. Similarly, if one end detects that the response is missing or the response data is erroneous, it can also record the error information.
[0113] In one embodiment, the method further includes: when the state machine of the receiving end is in the third response state, if no request message sent by the sending end is received while sending a third message to the sending end, then the state of the state machine is modified to an idle state.
[0114] In one embodiment, the method further includes: when the state machine of the receiving end is in the state of sending data, while receiving the request message sent by the sending end, sending a request message to the sending end, changing the state machine from the state of sending data to the corresponding response state; while sending the response message to the sending end, if the request message sent by the sending end is not received again, changing the state machine from the corresponding response state to the original state of sending data; wherein, the response message corresponds to the request message sent by the sending end.
[0115] In one embodiment, modifying the state machine from the state of sending data to the corresponding response state includes: if the state of the state machine sending data is the first sending state, modifying the state machine to the first sending response state; if the state of the state machine sending data is the second sending state, modifying the state machine to the second sending response state; if the state of the state machine sending data is the first retransmission state, modifying the state machine to the first retransmission response state; if the state of the state machine sending data is the second retransmission state, modifying the state machine to the second retransmission response state.
[0116] Example 3
[0117] Figure 14 This is a structural diagram of an SPI-based data communication device provided in Example 3 of the present invention. The device is applicable to data transmission, wherein the device can be implemented by software and / or hardware and is generally integrated in a vehicle.
[0118] like Figure 14 As shown, the device includes:
[0119] A first sending module 310 is configured to, when the state machine of the sending end is in an idle state, send a first request message to the receiving end to modify the state machine to a first sending state;
[0120] The second sending module 320 is configured to receive a third message sent by the receiving end while sending the second request message to the receiving end, and modify the state machine to a second sending state;
[0121] A determination module 330 is configured to determine whether the first request message needs to be retransmitted based on the third message;
[0122] The third sending module 340 is used to modify the state machine of the sending end to the first sending state if not needed, use the second request message as the first request message, and continue to send new second request messages and receive new third messages; if necessary, modify the state machine of the sending end to the retransmission state and retransmit the first request message.
[0123] This embodiment provides an SPI-based data communication device, comprising: a first sending module, configured to, when a state machine of a sending end is in an idle state, send a first request message to a receiving end, thereby modifying the state machine to a first sending state; a second sending module, configured to, while simultaneously sending a second request message to the receiving end, receive a third message sent by the receiving end, and modify the state machine to a second sending state; a determination module, configured to determine, based on the third message, whether the first request message needs to be retransmitted; a third sending module, configured to, if not necessary, modify the state machine of the sending end to the first sending state, use the second request message as the first request message, and continue to send new second request messages and receive new third messages; and, if necessary, modify the state machine of the sending end to a retransmission state, thereby retransmitting the first request message. By simultaneously sending data to the receiving end and receiving data sent by the receiving end, all bandwidth resources can be utilized, communication performance can be improved, and the problem of low communication performance in prior art communications based on the SPI communication protocol can be solved.
[0124] Furthermore, the third sending module 340 includes:
[0125] Modifying the state machine of the transmitting end to a first retransmission state;
[0126] Resending the first request message to the receiving end while receiving a fourth message sent by the receiving end;
[0127] If the fourth message is a response message to the first request message, modifying the state machine to the first sending state, and treating the second request message as the first request message;
[0128] If the fourth message is a response message to the second request message, the state machine is modified to a second retransmission state, and the first request message is retransmitted based on the second retransmission state.
[0129] Further, the retransmitting the first request message based on the second retransmission state includes:
[0130] Resending the first request message to the receiving end while receiving a fifth message sent by the receiving end;
[0131] If the fifth message is a response message to the first request message, the state machine is modified to an idle state.
[0132] Further, when the fourth message is a request message, the apparatus further includes:
[0133] Modifying the state machine to a first retransmission response state;
[0134] While sending a response message corresponding to the request message to the receiving end, receiving a new sixth message sent by the receiving end, and modifying the state machine to a first retransmission state;
[0135] The sixth message is used as a new fourth message, the state of the state machine is modified based on the new fourth message, and corresponding steps are executed.
[0136] Further, when the fifth message is a request message, the apparatus further includes:
[0137] Modifying the state machine to a second retransmission response state;
[0138] while sending a response message corresponding to the request message to the receiving end, receiving a seventh message sent by the receiving end, and modifying the state machine to a second retransmission state;
[0139] The seventh message is used as a new fifth message, the state of the state machine is modified based on the new fifth message, and corresponding steps are executed.
[0140] Further, when the third message is a request message, the apparatus further includes:
[0141] Modifying the state machine to a second send-response state;
[0142] while sending a response message corresponding to the request message to the receiving end, receiving an eighth message sent by the receiving end, and modifying the state machine to a second sending state;
[0143] The eighth message is used as a new third message, and the step of determining whether the first request message needs to be retransmitted based on the third message is performed.
[0144] Furthermore, the device further comprises:
[0145] When the state machine of the sending end is in an idle state, if a request message sent by the receiving end is received, the state machine is modified to a third response state;
[0146] Send a response message corresponding to the request message to the receiving end, and modify the state machine to an idle state.
[0147] Furthermore, the device further comprises:
[0148] When the state machine of the sending end is in an idle state, if the sending end receives a request message sent by the receiving end while sending a first request message to the receiving end, the state machine is modified to a first sending response state;
[0149] Sending a response message corresponding to the request message to the receiving end, receiving a ninth message sent by the receiving end, and modifying the state machine to a first sending state;
[0150] Determining whether the first request message needs to be retransmitted based on the ninth message;
[0151] If not required, the state machine is modified to an idle state; if required, the state machine is modified to a retransmission state, and the first request message is retransmitted.
[0152] Furthermore, the determination module 330 includes:
[0153] When the third message is a response message corresponding to the first request message and the response message is verified to be correct, determining that the first request message does not need to be retransmitted;
[0154] When the third message is a response message corresponding to the first request message and the response message verification is incorrect, determining that the first request message needs to be retransmitted;
[0155] When the third message is a response message corresponding to the first request message and the response message includes an error flag, determining that the first request message needs to be retransmitted;
[0156] When the third message is a blank frame, it is determined that the first request message needs to be retransmitted.
[0157] The above-mentioned SPI-based data communication device can execute the SPI-based data communication method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0158] Example 4
[0159] Figure 15 This is a structural diagram of an SPI-based data communication device provided in a fourth embodiment of the present invention. The device is applicable to data transmission, wherein the device can be implemented by software and / or hardware and is generally integrated in a vehicle.
[0160] like Figure 15 As shown, the device includes:
[0161] The receiving module 410 is configured to receive a first request message sent by the sending end when the state machine of the receiving end is in an idle state, and change the state of the state machine to a third response state;
[0162] A fourth sending module 420, configured to receive a second request message sent by the sending end while sending the third message to the sending end;
[0163] The fifth sending module 430 receives a request message sent by the sending end while continuing to send a new third message to the sending end, where the request message is the first request message or the second request message.
[0164] This embodiment provides an SPI-based data communication device, comprising: a receiving module, configured to receive a first request message sent by a transmitting end when a state machine of the receiving end is in an idle state, and to modify the state of the state machine to a third response state; a fourth sending module, configured to receive a second request message sent by the transmitting end while simultaneously sending a third message to the transmitting end; and a fifth sending module, configured to receive a request message sent by the transmitting end while continuing to send a new third message to the transmitting end, wherein the request message is either the first request message or the second request message. While the receiving end is sending data to the transmitting end, it also receives data sent by the transmitting end, thereby utilizing all bandwidth resources and improving communication performance. This solves the problem of low communication performance in prior art communications based on the SPI communication protocol.
[0165] Furthermore, the third message is a response message or a blank frame corresponding to the request message.
[0166] Furthermore, the device further comprises:
[0167] When the state machine of the receiving end is in the third response state, if no request message sent by the sending end is received while the third message is sent to the sending end, the state of the state machine is modified to the idle state.
[0168] Furthermore, the device further comprises:
[0169] When the state machine of the receiving end is in a state of sending data, while receiving a request message sent by the sending end, sending a request message to the sending end to change the state machine from the state of sending data to a corresponding response state;
[0170] While sending a response message to the sending end, if no request message is received from the sending end again, modifying the state machine from the corresponding response state to the original data sending state;
[0171] The response message corresponds to the request message sent by the sending end.
[0172] Furthermore, the step of changing the state machine from a data sending state to a corresponding response state includes:
[0173] If the data sending state of the state machine is the first sending state, modify the state machine to the first sending response state;
[0174] If the data sending state of the state machine is the second sending state, modifying the state machine to the second sending response state;
[0175] If the state of the state machine sending data is the first retransmission state, modify the state machine to the first retransmission response state;
[0176] If the state of the state machine sending data is the second retransmission state, the state machine is modified to the second retransmission response state.
[0177] The above-mentioned SPI-based data communication device can execute the SPI-based data communication method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0178] Example 5
[0179] Figure 16 A schematic diagram of a vehicle 10 is shown that may be used to implement an embodiment of the present invention. The components shown herein, their connections and relationships, and their functions are provided as examples only and are not intended to limit implementations of the inventions described and / or claimed herein.
[0180] like Figure 16 As shown, vehicle 10 includes at least one processor 11 and memory, such as read-only memory (ROM) 12 and random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor, and processor 11 can perform various appropriate actions and processes based on the computer programs stored in ROM 12 or loaded from storage unit 18 into RAM 13. RAM 13 can also store various programs and data required for the operation of vehicle 10. Processor 11, ROM 12, and RAM 13 are interconnected via bus 14. An input / output (I / O) interface 15 is also connected to bus 14.
[0181] Various components in the vehicle 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the vehicle 10 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0182] The processor 11 may be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as an SPI-based data communication method.
[0183] In some embodiments, the SPI-based data communication method can be implemented as a computer program that is tangibly contained in a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on the vehicle 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the SPI-based data communication method described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to perform the SPI-based data communication method in any other suitable manner (e.g., by means of firmware).
[0184] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0185] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0186] In the context of the present invention, computer-readable storage media can be tangible media that can contain or store a computer program for use with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Computer-readable storage media can include but are not limited to electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, computer-readable storage media can be machine-readable signal media. More specific examples of machine-readable storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0187] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0188] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0189] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a hosting product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS services.
[0190] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in the present invention can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved. This is not limited herein.
[0191] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.
Claims
1. A data communication method based on SPI, characterized in that: The method comprises: When the state machine of the sending end is in an idle state, sending a first request message to the receiving end to modify the state machine to a first sending state; While sending the second request message to the receiving end, receiving a third message sent by the receiving end, and modifying the state machine to a second sending state; determining whether the first request message needs to be retransmitted based on the third message; If not necessary, the state machine of the sending end is modified to the first sending state, the second request message is used as the first request message, and the new second request message is continued to be sent and the new third message is received; if necessary, the state machine of the sending end is modified to the retransmission state, and the first request message is retransmitted.
2. The method according to claim 1, characterized in that The modifying the state machine of the sending end to a retransmission state and retransmitting the first request message includes: Modifying the state machine of the transmitting end to a first retransmission state; Resending the first request message to the receiving end while receiving a fourth message sent by the receiving end; If the fourth message is a response message to the first request message, modifying the state machine to the first sending state, and treating the second request message as the first request message; If the fourth message is a response message to the second request message, the state machine is modified to a second retransmission state, and the first request message is retransmitted based on the second retransmission state.
3. The method according to claim 2, characterized in that The retransmitting the first request message based on the second retransmission state includes: Resending the first request message to the receiving end while receiving a fifth message sent by the receiving end; If the fifth message is a response message to the first request message, the state machine is modified to an idle state.
4. The method according to claim 2, characterized in that When the fourth message is a request message, the method further includes: Modifying the state machine to a first retransmission response state; While sending a response message corresponding to the request message to the receiving end, receiving a new sixth message sent by the receiving end, and modifying the state machine to a first retransmission state; The sixth message is used as a new fourth message, the state of the state machine is modified based on the new fourth message, and corresponding steps are executed.
5. The method according to claim 3, characterized in that When the fifth message is a request message, the method further includes: Modifying the state machine to a second retransmission response state; while sending a response message corresponding to the request message to the receiving end, receiving a seventh message sent by the receiving end, and modifying the state machine to a second retransmission state; The seventh message is used as a new fifth message, the state of the state machine is modified based on the new fifth message, and corresponding steps are executed.
6. The method according to claim 1, characterized in that When the third message is a request message, the method further includes: Modifying the state machine to a second send-response state; while sending a response message corresponding to the request message to the receiving end, receiving an eighth message sent by the receiving end, and modifying the state machine to a second sending state; The eighth message is used as a new third message, and the step of determining whether the first request message needs to be retransmitted based on the third message is performed.
7. The method according to claim 1, characterized in that The method further comprises: When the state machine of the sending end is in an idle state, if a request message sent by the receiving end is received, the state machine is modified to a third response state; Send a response message corresponding to the request message to the receiving end, and modify the state machine to an idle state.
8. The method according to claim 1, characterized in that The method further comprises: When the state machine of the sending end is in an idle state, if the sending end receives a request message sent by the receiving end while sending a first request message to the receiving end, the state machine is modified to a first sending response state; Sending a response message corresponding to the request message to the receiving end, receiving a ninth message sent by the receiving end, and modifying the state machine to a first sending state; Determining whether the first request message needs to be retransmitted based on the ninth message; If not required, the state machine is modified to an idle state; if required, the state machine is modified to a retransmission state, and the first request message is retransmitted.
9. The method according to claim 1, characterized in that The determining whether the first request message needs to be retransmitted based on the third message includes: When the third message is a response message corresponding to the first request message and the response message is verified to be correct, determining that the first request message does not need to be retransmitted; When the third message is a response message corresponding to the first request message and the response message verification is incorrect, determining that the first request message needs to be retransmitted; When the third message is a response message corresponding to the first request message and the response message includes an error flag, determining that the first request message needs to be retransmitted; When the third message is a blank frame, it is determined that the first request message needs to be retransmitted.
10. A data communication method based on SPI, characterized in that: The method comprises: When the state machine of the receiving end is in an idle state, receiving a first request message sent by the sending end, and changing the state of the state machine to a third response state; while sending the third message to the sending end, receiving a second request message sent by the sending end; While continuing to send the new third message to the sending end, a request message sent by the sending end is received, where the request message is the first request message or the second request message.
11. The method according to claim 10, characterized in that The third message is a response message or a blank frame corresponding to the request message.
12. The method according to claim 10, characterized in that The method further comprises: When the state machine of the receiving end is in the third response state, if no request message sent by the sending end is received while the third message is sent to the sending end, the state of the state machine is modified to the idle state.
13. The method according to claim 10, characterized in that The method further comprises: When the state machine of the receiving end is in a state of sending data, while receiving a request message sent by the sending end, sending a request message to the sending end to change the state machine from the state of sending data to a corresponding response state; While sending a response message to the sending end, if no request message is received from the sending end again, modifying the state machine from the corresponding response state to the original data sending state; The response message corresponds to the request message sent by the sending end.
14. The method according to claim 13, characterized in that The step of changing the state machine from a data sending state to a corresponding response state includes: If the data sending state of the state machine is the first sending state, modify the state machine to the first sending response state; If the data sending state of the state machine is the second sending state, modifying the state machine to the second sending response state; If the state of the state machine sending data is the first retransmission state, modify the state machine to the first retransmission response state; If the state of the state machine sending data is the second retransmission state, the state machine is modified to the second retransmission response state.
15. A data communication device based on SPI, characterized in that: The device comprises: A first sending module, configured to send a first request message to a receiving end to modify the state machine to a first sending state when the state machine of the sending end is in an idle state; A second sending module is configured to receive a third message sent by the receiving end while sending a second request message to the receiving end, and modify the state machine to a second sending state; a determining module, configured to determine whether the first request message needs to be retransmitted based on the third message; The third sending module is used to modify the state machine of the sending end to the first sending state if not needed, use the second request message as the first request message, and continue to send new second request messages and receive new third messages; if necessary, modify the state machine of the sending end to the retransmission state and retransmit the first request message.
16. A data communication device based on SPI, characterized in that: The device comprises: a receiving module, configured to receive a first request message sent by the transmitting end when the state machine of the receiving end is in an idle state, and modify the state of the state machine to a third response state; a fourth sending module, configured to receive a second request message sent by the sending end while sending the third message to the sending end; The fifth sending module receives a request message sent by the sending end while continuing to send a new third message to the sending end, where the request message is the first request message or the second request message.
17. A vehicle, characterized in that: The vehicle comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to perform the SPI-based data communication method according to any one of claims 1 to 9 or 10 to 14.
18. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the SPI-based data communication method according to any one of claims 1 to 9 or 10 to 14 when executed.