CN112822002A - SPI (Serial peripheral interface) -based communication method and device, electronic equipment and storage medium - Google Patents

SPI (Serial peripheral interface) -based communication method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN112822002A
CN112822002A CN202110002599.2A CN202110002599A CN112822002A CN 112822002 A CN112822002 A CN 112822002A CN 202110002599 A CN202110002599 A CN 202110002599A CN 112822002 A CN112822002 A CN 112822002A
Authority
CN
China
Prior art keywords
frame
data
current
alignment
frame number
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202110002599.2A
Other languages
Chinese (zh)
Other versions
CN112822002B (en
Inventor
江志强
林锦泸
卢长城
曾少忠
苏昭清
管瑜
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Horizon Information Technology Co Ltd
Original Assignee
Beijing Horizon Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Horizon Information Technology Co Ltd filed Critical Beijing Horizon Information Technology Co Ltd
Priority to CN202110002599.2A priority Critical patent/CN112822002B/en
Publication of CN112822002A publication Critical patent/CN112822002A/en
Application granted granted Critical
Publication of CN112822002B publication Critical patent/CN112822002B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L5/00Arrangements affording multiple use of the transmission path
    • H04L5/14Two-way operation using the same type of signal, i.e. duplex
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus

Landscapes

  • Engineering & Computer Science (AREA)
  • Signal Processing (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Communication Control (AREA)

Abstract

An SPI-based communication method, an electronic device, and a storage medium are disclosed. In this embodiment, the communication method based on the serial peripheral interface may include: sending a first alignment frame to opposite-end equipment, and receiving a second alignment frame from the opposite-end equipment at the same time so as to carry out frame alignment; when the frame alignment is successful, sending a first data frame to opposite-end equipment, and receiving a second data frame from the opposite-end equipment; and analyzing the second data frame. This application embodiment can realize SPI's full duplex communication, has not only saved the latency of equipment communication, has improved communication efficiency, and the utilization ratio of hardware resources such as SPI communication's master device, slave unit and SPI bus also can obtain promoting.

Description

SPI (Serial peripheral interface) -based communication method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of automatic driving technologies, and in particular, to a Serial Peripheral Interface (SPI) based communication method and apparatus, an electronic device, and a storage medium.
Background
In an embedded system for automatic driving, the amount of data transmitted between a system on chip (SoC) and a Micro Control Unit (MCU) is increasing, and the rate is required to be at the Mbps level, so that a Serial Peripheral Interface (SPI) bus is basically used for communication in the same circuit board.
Disclosure of Invention
At present, the communication scheme between the SoC and the MCU is that the SoC sends an instruction to the MCU through an SPI bus, the MCU analyzes the instruction and prepares data and reminds the SoC through an input/output (IO) interface, and then the SoC reads the prepared data of the MCU. In order to solve the technical problem, embodiments of the present disclosure desirably provide a communication method and apparatus based on an SPI, an electronic device, and a storage medium, so as to implement full-duplex communication of the SPI.
According to an aspect of the present application, there is provided a communication method based on a serial peripheral interface, including: sending a first alignment frame to opposite-end equipment, and receiving a second alignment frame from the opposite-end equipment at the same time so as to carry out frame alignment; when the frame alignment is successful, sending a first data frame to opposite-end equipment, and receiving a second data frame from the opposite-end equipment; and analyzing the second data frame.
According to an aspect of the present application, there is provided a serial peripheral interface-based communication apparatus, including: a receiving unit configured to receive a second alignment frame from a peer device for frame alignment; receiving a second data frame from the opposite terminal equipment; a transmitting unit configured to transmit a first alignment frame to a peer device for the frame alignment while the receiving unit receives the second alignment frame; and sending a first data frame to the peer device while the receiving unit receives the second data frame; a parsing unit configured to parse the second data frame.
According to an aspect of the present application, there is provided an electronic device including: one or more processors; and a memory storing a computer program that, when executed by the processor, causes the processor to execute the serial peripheral interface-based communication method.
According to an aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, causes the processor to carry out the above-mentioned serial peripheral interface-based communication method.
According to the method, the device, the equipment and the storage medium of the embodiment of the disclosure, the master equipment (for example, SoC) sends the instruction and the data through the SPI bus, and meanwhile, the slave equipment (for example, MCU) also transmits the data of the instruction to the master equipment, so that full-duplex communication is realized, the transmission time is saved, the efficiency is improved, and real parallel communication is realized.
Drawings
The above and other objects, features and advantages of the present application will become more apparent by describing in more detail embodiments of the present application with reference to the attached drawings. The accompanying drawings are included to provide a further understanding of the embodiments of the application and are incorporated in and constitute a part of this specification, illustrate embodiments of the application and together with the description serve to explain the principles of the application. In the drawings, like reference numbers generally represent like parts or steps.
FIG. 1 is a block diagram of an exemplary deployment of a system to which the present application is applicable.
Fig. 2 is a flowchart illustrating an SPI-based communication method according to an exemplary embodiment of the present application.
Fig. 3 is a schematic diagram of a frame structure used for SPI communication according to an exemplary embodiment of the present application.
Fig. 4 is a frame structure diagram of a first data frame according to an exemplary embodiment of the present application.
Fig. 5 is a frame structure diagram of a second data frame according to an exemplary embodiment of the present application.
Fig. 6 is a frame structure diagram of a second data frame according to another exemplary embodiment of the present application.
Fig. 7 is a schematic diagram of a master-side SPI communication flow provided in an exemplary embodiment of the present application.
Fig. 8 is a slave-side SPI communication flow diagram provided by an exemplary embodiment of the present application.
Fig. 9 is a schematic structural diagram of an SPI-based communication device according to another exemplary embodiment of the present application.
Fig. 10 is a schematic structural diagram of an electronic device according to an exemplary embodiment of the present application.
Detailed Description
Hereinafter, example embodiments according to the present application will be described in detail with reference to the accompanying drawings. It should be understood that the described embodiments are only some embodiments of the present application and not all embodiments of the present application, and that the present application is not limited by the example embodiments described herein.
Summary of the application
As described above, in the communication scheme between the SoC and the MCU in the related art, the SoC sends an instruction to the MCU through the SPI bus, the MCU parses the instruction, prepares data and reminds the SoC through an input/output (IO) interface, and then the SoC reads the prepared data from the MCU.
In order to solve the above technical problem, a basic idea of the embodiments of the present disclosure is to provide an SPI-based communication method, device, and storage medium, in which a current device (hereinafter, a master device or a slave device) may receive a second alignment frame from a peer device (hereinafter, a slave device or a master device) for frame alignment while transmitting a first alignment frame to the peer device; when the frame alignment is successful, the current device may receive a second data frame from the peer device while transmitting the first data frame to the peer device, so as to obtain content such as instructions, data, and the like by parsing the second data frame. Therefore, according to the embodiment of the application, when the master device (for example, SoC in the following) sends the instruction and the data through the SPI bus, the slave device (for example, MCU in the following) also transmits the data of the instruction to the master device, and when the slave device transmits the data of the instruction to the master device, the slave device also receives the next instruction through the SPI bus, so that SPI full-duplex communication is realized, transmission time is saved, efficiency is improved, and real parallel communication is realized.
The embodiment of the application can be applied to any system capable of supporting SPI. In some examples, the embodiments of the present application may be particularly applicable to SPI communication in embedded systems for artificial intelligence technologies such as autonomous driving.
Exemplary System
Fig. 1 is an exemplary block diagram of an embedded system to which an embodiment of the present application is applicable. As shown in fig. 1, an embedded system to which the embodiment of the present application is applicable may include: a system on chip (SoC) and a Micro Control Unit (MCU) that can communicate through a Serial Peripheral Interface (SPI).
In specific application, any one of the MCU and the SoC in the embedded system can be used as a following master device, and correspondingly, the other one of the MCU and the SoC can be used as a following slave device. For example, when the SoC serves as a master device and the MCU serves as a slave device, the SoC may transmit an instruction to the MCU through the SPI, and the MCU may prepare data required by the instruction and transmit the data to the SoC at the same time.
In some examples, the SoC and MCU may be loaded in the same circuit board and communicate through the SPI. In some examples, the MCU may be, but is not limited to, an MCU that supports a single-chip system such as 8-bit/16-bit/32-bit. The SoC may be, but is not limited to, an SoC that supports an operating system such as Mac, Windows, Linux, etc.
Exemplary method
Fig. 2 is a flowchart illustrating an SPI-based communication method according to an exemplary embodiment of the present application. As shown in fig. 2, the exemplary method may include the steps of:
step S201, sending a first alignment frame to an opposite terminal device, and receiving a second alignment frame from the opposite terminal device to perform frame alignment;
step S202, when the frame alignment is successful, a first data frame is sent to the opposite terminal equipment, and a second data frame from the opposite terminal equipment is received;
in step S203, the second data frame is parsed.
In the embodiment of the application, the current device and the opposite-end device are synchronized by frame alignment, then in the interaction process of data and instructions, the current device sends out a first data frame and simultaneously receives a second data frame corresponding to the first data frame, and the required instructions or data can be obtained by analyzing the second data frame. For example, if the current device is a master device and a first data frame carries an instruction a, a second data frame received at the same time carries data a' corresponding to the instruction a. Assuming that the current device is a slave device, the first data frame carries data a ', and the second data frame received at the same time carries an instruction a corresponding to the request for the data a'. That is, the master device may receive data required for the current instruction while transmitting the current instruction, and the slave device may transmit data required for the instruction to the master device while receiving the current instruction. Therefore, the full-duplex communication of the SPI is realized, the waiting time of the SoC and the MCU is saved compared with the prior SPI half-duplex scheme, the communication efficiency is improved, and the utilization rate of hardware resources such as the master device, the slave device and the SPI bus can be effectively improved.
Two exemplary implementations of the above-described method of the embodiments of the present application are described in detail below.
First embodiment
In this first embodiment, the current device is a master device, and the peer device is a slave device.
In this embodiment, the first data frame may carry one of the following information or any combination thereof: the current frame number, the current frame data length, the next frame number, the next frame data length, a state flag for indicating the current equipment state, the current frame transmission control data and/or frame data, and a check code for verifying whether the data is correct or not. The data required by the next frame of the slave device can be indicated in the current frame by carrying the frame number of the next frame in the first data frame, so that the slave device can start to prepare the data required by the next frame after receiving the current frame, and the slave device can simultaneously send the second data frame corresponding to the next first data frame to the slave device when the master device sends the next first data frame, thereby realizing SPI full duplex communication.
In this embodiment, the first alignment frame may carry one of the following information or any combination thereof: the device comprises a current frame number, a next frame number, a data length of the next frame, a state mark for indicating the current equipment state, current frame transmission control data and/or frame data and a check code for verifying whether the data is correct, wherein the value of the current frame number is a preset frame number.
In this embodiment, the second data frame may carry one of the following information or any combination thereof: the current frame number, the current frame data length, a state flag for indicating the state of the opposite terminal equipment, data corresponding to the current frame number, and a check code for verifying whether the data is correct or not.
In this embodiment, the second alignment frame may carry one of the following information or any combination thereof: the current frame number with the value of the preset frame number, the data length of the current frame, a state mark for indicating the state of the opposite terminal equipment, data corresponding to the current frame number, and a check code for verifying whether the data is correct or not.
Fig. 3 shows an exemplary format of each frame in the embodiment of the present application. Fig. 4 shows a frame structure of the first data frame.
As shown in fig. 3 and 4, a frame for SPI communication in the embodiment of the present application may include three parts, namely a start character, N information fields (N is an integer not less than 1), and an end character. In some examples, the start of the frame may be predefined as 0x2C for determining the start of the frame. The end-character may be predefined as "0 x 7E" for judging the end of the frame.
In the embodiment of the present application, the number N of information fields in a frame may be predefined. In some examples, the length of each of the N information fields and its meaning are as follows:
byte0 is the current frame number, which is used to identify which instruction is currently sent; the current frame number can be represented by 1-255, and can be customized actually;
byte1-2 is the length of the current frame data, and is used for judging the length of the received current frame transmission control data and frame data;
byte3 is the next frame number, which identifies which command the master device is to issue to the slave device next time; the next frame number can be represented by 1-255, and the value can be defined according to the application scene;
byte4-5 is the next frame data length and is used to give the slave device how much data is needed for the next frame;
the Byte6 is a status indication bit for indicating the transmission status, wherein the bit0-3 is the status indication of the master device, the bit4-7 is the status indication of the slave device, and the specific values and the meanings represented by the values are shown in the following table 1.
Figure BDA0002882132440000061
TABLE 1
The bytes 7-N-1 are used for carrying the current frame transmission control data and frame data.
ByteN is the data checksum of Byte 0-Byte (N-1), such as CRC 8.
In practical applications, the frame number of the current frame and the frame number of the next frame may be defined according to the requirements of a specific scene.
In this embodiment, the second alignment frame and the second data frame from the peer device may also adopt the frame format shown in fig. 3. Unlike the first data frame and first frame alignment, the effect of Byte3-5 is different. When the opposite terminal device receives an instruction or data error from the current device, the first data frame may further include one or two of the following items: the instruction identification of the previous frame and the data length of the previous frame. In this way, in the second aligned frame and the second data frame of the peer device, the Byte3-5 takes 0 (or other meaningless values) by default (i.e., in the case of normal SPI communication), the Byte3-5 will have a certain value only when the peer device finds that the command or data received by the peer device is wrong and needs to request the command or data again from the current device, the value of Byte3 is equal to the frame number (i.e., command identifier) of the frame requested by the peer device, and the values of Byte4-5 are equal to the data length of the frame. Fig. 5 shows a frame structure of a second data frame when the SPI communication is normal, and fig. 6 shows a frame structure of a second data frame when a command or data of a previous frame is requested from the current device when a command or data received by the peer device is erroneous.
Through the frame format, both sides of the SPI communication can not only conveniently perform frame analysis to obtain data or instructions, but also carry the next frame number in the first data frame sent by the master device, so that the slave device can obtain the next frame number after receiving the current first data frame, prepare the data required for the next frame in time and send the data required for the next first data frame to the master device at the same time when the master device sends the next first data frame. Thus, SPI full-duplex communication is realized.
In at least some embodiments, the format of the first alignment frame and the first data frame may be identical, with only the information carried being different. In other words, the first alignment frame and the second alignment frame may be data frames of a predefined frame number. For example, the predefined frame number may be the first frame (i.e., a frame with a frame number of 1 or 0) or any other frame number. For example, assuming that the SoC is the current device, the MCU is the peer device, and the SoC is the master device in the system shown in fig. 1, the format of the first alignment frame may be "0 x2C 0x 010x 00010x 020 x 1000 x00 x00 x00x (crc8)0x 7E", and the format of the second alignment frame may be "0 x2C 0x 010x 00010x 000 x00 x00 x00x (crc8)0x 7E". In this example, the process of step S101 is: the SoC sends the first frame and the self state to the MCU, and the MCU sends the frame number of the first frame and the self state to the SoC at the same time.
In at least some embodiments, before sending a first data frame to a peer device, it may be determined whether frame alignment is successful, so as to start transmission of the first data frame and the second data frame when the frame alignment is successful. If the frame alignment is successful, the above step S202 is continuously executed, and if the frame alignment is failed, the frame alignment may be performed again until the frame alignment is successful or the number of times of the frame alignment reaches the preset upper limit value. If the number of frame alignments reaches a preset upper limit, a notification may be sent to the upper control module. The two pieces of equipment for SPI communication can be synchronized through frame alignment, and it is ensured that frames sent by the two pieces of equipment at the same time are corresponding (namely, an instruction in the frame sent by the master equipment and data in the frame sent by the slave equipment are corresponding), so that the master equipment can receive the data requested by the instruction while sending the instruction, and SPI full duplex communication is realized.
In some examples, determining whether frame alignment is successful may include one or both of: verifying whether the data in the second alignment frame is correct; and judging whether the frame numbers of the current frames in the first alignment frame and the second alignment frame are consistent or not. Strict synchronization between two pieces of equipment of SPI communication can be ensured through two judgments, and requirements of SPI full-duplex communication are met.
One implementation of the above example may be: verifying whether the second alignment frame is normal, and determining whether the state of the opposite terminal equipment is normal according to the state indication in the second alignment frame; when the second alignment frame is normal and the state of the opposite terminal equipment is normal, confirming that the side frame alignment of the current equipment is successful; and when the second alignment frame is abnormal or the state of the opposite terminal equipment is abnormal, the first alignment frame is sent to the opposite terminal equipment again. In the embodiment of the present application, when both device sides of SPI communication confirm that alignment is successful, it is considered that frame alignment is successful.
In the foregoing implementation, verifying whether the second alignment frame is normal may include: determining whether the data in the second alignment frame is correct according to the check code in the second alignment frame, and comparing the current frame number in the second alignment frame with the current frame number in the first alignment frame; and when the data in the second alignment frame is correct and the frame number of the second alignment frame is consistent with that of the current frame of the first alignment frame, confirming that the second alignment frame is normal. Here, whether the data in the frame is correct can be determined by a "checksum" in the frame.
In the foregoing implementation manner, whether the state of the peer device is normal is determined according to the state indication in the second alignment frame, and step S202 of sending the first data frame to the peer device is executed when the state of the peer device is normal. If the state of the opposite terminal equipment is abnormal, the first alignment frame can be sent to the opposite terminal equipment again to perform frame alignment again.
After the frame alignment is successful, both SPI communication parties can normally communicate, and the current equipment and the opposite-end equipment can carry out full-duplex communication through the SPI.
The process of data interaction between the current device and the opposite device through the SPI may be: the current device sends a first data frame with a frame number y (y is an integer greater than 1) to the opposite device, and the opposite device returns a second data frame with a frame number y to the current device, wherein the second data frame carries data corresponding to the frame number y.
After the current device receives the second data frame with the frame number y, the current device analyzes the second data frame to obtain data, a frame number and a state indicating value indicating the state of the opposite device, firstly judges whether the data in the second data frame is correct, whether the frame number is consistent with the frame number of the first data frame sent by the current device, and whether the state of the opposite device is normal, if the data in the second data frame is correct, the frame number is consistent with the frame number of the first data frame sent by the second data frame, and the state of the opposite terminal equipment is normal, the current device will continue with the next first data frame (i.e. the first data frame with the frame number of y + 1), assign the frame number in Byte3 to Byte0, assign the length of Byte4-5 to Byte1-2, assign the frame number of the next frame to be transmitted to Byte3 and assign its length to Byte4-5, to generate the first data frame with the frame number of y +1, and wait for a period of time.
After receiving the first data frame with the frame number y, the opposite terminal equipment analyzes the first data frame to obtain data, a frame number and a state indicating value indicating the current equipment state, firstly judges whether the data in the first data frame is correct, whether the frame number is consistent with the frame number of a second data frame sent by the opposite terminal equipment, whether the current equipment state is normal, if the data in the first data frame is correct, the frame number is consistent with the frame number of the second data frame sent by the opposite terminal equipment and the current equipment state is normal, the opposite terminal equipment prepares the data H required by the next second data frame (namely the second data frame with the frame number y + 1) according to the frame number in the Byte3 and the length of the Byte4-5 in the first data frame with the frame number y, assigns the frame number in the Byte3 in the first data frame with the frame number y to the Byte0, assigns the length of the Byte4-5 to the Byte1-2 and fills the prepared data H in a data field (Byte 7-N-1), to generate a second data frame with frame number y +1 and wait for a period of time.
After a period of time elapses when the current device generates a first data frame with a frame number of y +1 and the peer device generates a second data frame with a frame number of y +1, the current device and the peer device interact with the first data frame with the frame number of y +1 and the second data frame with the frame number of y +1 through the SPI bus under the control of a clock initiated by the current device.
Under the condition that the received data and the received command are judged to be normal by the current equipment and the opposite terminal equipment respectively, the data interaction operation is repeated between the current equipment and the opposite terminal equipment through the SPI bus, and therefore SPI full duplex communication is achieved.
During the data and command interaction process of the two devices in the SPI communication through the embodiment, an abnormal event may be generated, and the abnormal event may possibly destroy the strict synchronization between the two devices in the SPI communication. In similar situations, frame alignment needs to be performed again to ensure that both devices communicating at the SPI are in strict synchronization.
Alternatively, in at least some embodiments, frame alignment may be re-performed to ensure strict synchronization between two devices communicating SPI when one or more of the following events occur: 1. restarting the current equipment abnormally; 2. and the opposite terminal equipment is abnormally restarted. Besides, strict synchronization between two devices of SPI communication can be ensured by performing frame alignment again when other similar events occur, and the embodiment of the present application is not limited to specific events.
In some examples, after the current device is abnormally restarted, a first alignment frame may be sent to the peer device to perform frame alignment again, so as to ensure that the SPI full duplex communication requirements are met and strict synchronization between the two pieces of SPI equipment is ensured after the current device is powered on again. The exception reset herein may include, but is not limited to, an exception reset, a software reset, a hardware reset, etc., the exception reset may include a software reset, a hardware reset, and the hardware reset may include, but is not limited to, a pull-up, a pull-down, or a power-up again.
Assuming that the current device is abnormally restarted for some reasons, the current device may retransmit the first frame for frame alignment at this time, but the frame numbers of the frames returned by the peer device at the same time may not coincide with the frame number of the first frame. At this time, after receiving the first frame sent by the current device, the opposite-end device finds that the instruction of the current device is inconsistent with the instruction sent by the opposite-end device, and the instruction of the current device is the first frame (i.e., an alignment frame), so that when data interaction is performed between the current device and the opposite-end device in the next frame, the current device will continue to resend the first frame to the opposite-end device, and meanwhile, the opposite-end device will also send the first frame for frame alignment to the current device, so that the current device and the opposite-end device perform frame alignment again.
The following table 2 shows a data interaction process of performing frame alignment again between the current device and the peer device after the current device is abnormally restarted. The current frame in table 2 refers to the first frame sent after the current device is abnormally restarted, and "X" represents the frame number of the first frame from the peer device received after the current device is abnormally restarted, because the frame from the peer device currently received by the current device is not the first frame, and frame alignment cannot be completed, the current frame number in the current frame of the current device is 1, and the frame number of the next frame is still 1, because the current device of the next frame will simultaneously receive the first frame from the peer device, the current frame number in the next frame of the current device is 1, and the frame number of the next frame is 2.
Current devices Opposite terminal equipment
Current frame Byte0=1;Byte=1;Byte6=0 Byte0=X;Byte=0;Byte6=0
The next frame Byte0=1;Byte=2;Byte6=0 Byte0=1;Byte=0;Byte6=0
TABLE 2
In some examples, after the peer device is abnormally restarted, the peer device may initiate and perform frame alignment again through the alignment frame, so as to ensure that the SPI full duplex communication requirements are met and strict synchronization between the two pieces of SPI equipment is ensured after the current equipment is powered back up. In particular, the current device may complete a frame alignment operation initiated by the peer device by sending a first alignment frame to the peer device after receiving a second alignment frame (e.g., the first frame described above) from the peer device. The exception reset herein may include, but is not limited to, an exception reset, a software reset, a hardware reset, etc., the exception reset may include a software reset, a hardware reset, and the hardware reset may include, but is not limited to, a pull-up, a pull-down, or a power-up again.
If the peer device is abnormally restarted for some reasons, after the abnormal restart, the peer device sends a second alignment frame to the current device to initiate a frame alignment operation, so as to perform frame alignment again. The following table 3 shows a data interaction process of frame re-alignment between the current device and the peer device after the peer device is abnormally restarted. As shown in table 3, after the peer device is abnormally restarted, the current device sends a current frame with a frame number k to the peer device according to a sequence of normal data interaction, and the current frame carries a frame number k +1 of a next frame, and the peer device sends a first frame (frame number 1) for frame alignment to the current device at the same time because of the abnormal restart, the current device finds the kth frame sent by itself and receives the first frame, and determines that the peer device requests frame alignment again, at this time, the current device sends the first frame (frame number 1, frame number 2 carrying the next frame) for frame alignment at the next frame, and the peer device sends the first frame sent by itself and receives the kth frame, and continues to send the first frame at the next frame, so that the current device and the peer device can re-frame alignment through two-frame interaction after the abnormal restart of the peer device, therefore, the SPI communication between the current device and the opposite-end device can be strictly synchronized after the opposite-end device is abnormally restarted.
Current devices Opposite terminal equipment
Current frame Byte0=k;Byte=k+1;Byte6=0 Byte0=1;Byte=0;Byte6=0
The next frame Byte0=1;Byte=2;Byte6=0 Byte0=1;Byte=0;Byte6=0
TABLE 3
In the embodiment of the present application, in order to avoid that both SPI communication parties fall into infinite loop frame alignment operation due to other errors, control may be performed by setting an upper limit of frame alignment. For example, the upper limit of the number of times of frame alignment may be set to M (M is an integer not less than 1), and if the number of times of frame alignment exceeds the upper limit value M, a message that the SPI communication abnormality may not be reported to the upper control module is currently set. If the number of frame alignments is below the upper limit value M, the frame alignment operation may continue. The value of the upper limit value M may be configured or adjusted according to the requirements of the actual application scenario. For example, the upper limit value M may be set to a fixed value (e.g., 5), or may be dynamically adjusted by the upper control module.
In this embodiment, in step S203, the second data frame is analyzed, and it may also be verified whether the target data is successfully received, where the target data is obtained by analyzing the second data frame and corresponds to the current frame number in the first data frame. If the target data reception is successful, the request for data may continue through the next first data frame.
In at least some embodiments, when the target data is successfully received, it may be determined whether the current state of the peer device is normal according to the state flag in the second data frame. When the current state of the peer device is normal, the current frame number in the next first data frame may be assigned as the next frame number in the current first data frame, the next frame number in the next first data frame may be assigned as the next frame number in the current first data frame, and meanwhile, the state flag in the next first data frame is set to be a predetermined first value (for example, the bit0-3 of Byte6 in the examples of fig. 3 and 4 above is set to be 0), where the first value may indicate that the current device is normal, so as to continue to request data from the peer device.
During the data and command interaction process of the two devices in the SPI communication through the embodiment, an abnormal event may be generated, and the abnormal event may possibly cause an error in data interacted between the two devices in the SPI communication. Alternatively, in at least some embodiments, two devices communicating at the SPI may be corrected by an error correction mechanism when one or more of the following events occur: 1. the data of the current equipment receiving the opposite terminal equipment is wrong; 2. and the opposite terminal equipment receives the instruction and data of the current equipment and generates errors.
In some examples, the error correction mechanism may include: if the current state of the peer device is normal, but the peer device receives an instruction or data of the current device and has an error, the peer device may carry a corresponding frame number (e.g., Byte3-5 in the example of fig. 3 above) in a frame provided to the current device, so that the current device may assign the current frame number in the next first data frame to the previous frame number carried in the second data frame, and set the state flag in the next first data frame to the first value above, so as to continue to request data from the peer device.
In some examples, the error correction mechanism may further include: when the data received by the current device from the peer device is in error (i.e. when the target data reception fails), the next frame number in the next first data frame may be assigned as the current frame number in the current first data frame, and the status flag in the next first data frame may be set to a predetermined second value (e.g. bit0-3 of Byte6 in the examples of fig. 3 and 4 above is set to 1), where the second value may be used to indicate that the data received by the current device is abnormal. In this way, when the data received by the current device is in error, the corresponding data can be requested from the opposite device again.
In at least some embodiments, verifying whether the target data was received successfully may include: judging whether the frame numbers of the second data frame and the current frame in the first data frame are consistent; and verifying whether the data in the second data frame is correct; when the frame number of the current frame in the second data frame is consistent with that of the first data frame and the data in the second data frame is correct, the target data is successfully received; and when the second data frame is consistent with the current frame number in the first data frame and the data in the second data frame is wrong, the target data fails to be received. In this embodiment, whether the data is successfully received can be determined in time by the frame number.
In some examples, the specific process of verifying whether the data in the second data frame is correct may include: parsing the second data frame to obtain data (e.g., Byte 1-N-1 in the example of FIG. 3 or Byte 7-N-1 in the example of FIG. 3) and a check code, calculating a checksum (one type of check code) based on the data (e.g., Byte 1-N-1 in the example of FIG. 3 or Byte 7-N-1 in the example of FIG. 3), comparing the calculated checksum with the check code parsed from the second data frame, wherein a consistency of the calculated checksum and the check code indicates that the data in the second data frame is correct, and a non-consistency of the calculated checksum and the check code parsed from the second data frame indicates that the data in the second data frame is incorrect.
In at least some embodiments, when the current frame number in the second data frame is inconsistent with the current frame number in the first data frame, it may be continuously determined whether the current frame number in the second data frame is equal to the predetermined frame number (e.g., frame number 1 of the first frame above) to confirm whether the peer device is requesting re-frame alignment. And if the current frame number in the second data frame is equal to the preset frame number, determining the next first data frame as a first alignment frame so as to perform frame alignment again. Here, the specific process of frame alignment may refer to the above related description, and is not described in detail.
In at least some embodiments, when the current frame number in the second data frame is not consistent with the current frame number in the first data frame, if the current frame number in the second data frame is not equal to the predetermined frame number, the current frame number in the next first data frame may be assigned as the predetermined frame number (e.g., frame number 1 of the above first frame), and the status flag in the next first data frame may be assigned as a predetermined third value (e.g., bit0-3 of Byte6 in the example of fig. 3 and 4 above is assigned as 2), where the third value is used to indicate that the instruction sent by the current device does not coincide with the received data, and the third value may notify the peer device that the current device has initiated a frame alignment operation because the received data does not coincide with the instruction sent by the peer device, so as to correct SPI errors in time and ensure normal SPI communication.
For example, when the current device receives the data of the peer device and has an error (for example, the current device parses the second data frame from the peer device to obtain the data and the checksum value therein, and determines that the received data has an error by calculating the checksum value in the data and finding that the calculated checksum value is not consistent with the checksum value in the second data frame), the status indicator bit Byte6 of the next first data frame may be assigned 0x01 (indicating "received data exception"), Byte3 may be assigned the command number (i.e., frame number) of the frame, Byte4-5 may be assigned the length value of the frame, and the MCU may be informed to retransmit the data of the frame at the next data interaction, and thus, when the data is wrong, the opposite terminal equipment can be informed to resend the data of the frame, and the situation that the data cannot be repaired when the data is missing or wrong is avoided. Table 4 shows an error correction example, when the current device sends a first data frame with a frame number of 3 to the peer device, the current device receives a second data frame with a frame number of 3 at the same time, and finds out a received data error by analyzing a field Byte6 in the second data frame with the frame number of 3, then the Byte3-5 in the first data frame with the frame number of 4 carries the frame number and the frame data length of the 3 rd frame, the Byte6 in the first data frame with the frame number of 4 is set to a value "0 x 01" indicating "received data is abnormal," the current device sends the first data frame with the frame number of 4 to the peer device, and receives a second data frame with a frame number of 4 returned by the peer device at the same time, and the peer device receives the first data frame with the frame number of 4, finds that Byte3 is a frame number of 3, and then prepares the second data frame with the frame number of 3. In the next data interaction, the current device retransmits the first data frame with the frame number of 3 to the opposite terminal device, and simultaneously the opposite terminal device returns the second data frame with the frame number of 3 to the current device, so that the current device acquires the data with errors from the opposite terminal device again, and data error correction is realized.
Current devices Opposite terminal equipment
Current frame Byte0=3;Byte=4;Byte6=0 Byte0=3;Byte=0
The next frame Byte0=4;Byte=3;Byte6=0x01 Byte0=4;Byte=0
Next frame Byte0=3;Byte=4;Byte6=0 Byte0=3;Byte=0
Next frame of next frame Byte0=4;Byte=5;Byte6=0 Byte0=4;Byte=0
TABLE 4
For another example, when the data and/or command received by the peer device from the current device has an error (for example, the peer device parses the first data frame from the current device to obtain the data and checksum value therein, calculates the checksum value in the data, finds that the calculated checksum value is not consistent with the checksum value in the first data frame, and thus determines that the received data and/or command has an error), it needs to re-request the data and/or command in the frame from the current device, and may assign the status indicator bit Byte6 of the next second data frame to 0x10 (indicating "data exception for received command"), Byte3 to the command number (i.e., frame number) of the frame, Byte4-5 to the length value of the frame, and inform the current device to re-send the command and/or data of the frame at the next data interaction, therefore, when the instruction and/or data received by the opposite terminal equipment are wrong, the current equipment can be informed to resend the instruction and/or data of the frame, and the condition that the instruction or data are missed or wrong and cannot be repaired is avoided. Table 5 shows an error correction example, when the current device sends a first data frame with frame number 3 to the peer device, the peer device finds that the received data or command of the current device is erroneous, then the bytes 3-5 in the second data frame with frame number 4 carry the frame number and frame data length of the 3 rd frame, the Byte6 in the second data frame with frame number 4 is set to a value "0 x 10" indicating "receive command data abnormal", the current device sends the first data frame with frame number 4 to the peer device, and simultaneously receives the second data frame with frame number 4 returned by the peer device, the current device finds that the Byte3 is frame number 3 after receiving the second data frame with frame number 4, then in the next data interaction, the current device sends the first data frame with frame number 3 to the peer device again, and at the same time, the peer device returns the second data frame with frame number 3 to the current device, so that, and the opposite terminal equipment requests the first data frame with the command or data error from the current equipment again, so that data error correction is realized.
Figure BDA0002882132440000141
TABLE 5
Assuming that the current device is an SoC and the peer device is an MCU, fig. 7 shows an SPI communication procedure on the current device side, which may include the following steps:
step S701, start;
step S702, determining whether the current synchronization frequency (i.e. the total frame alignment number) is smaller than a preset upper limit value M, if so, continuing step S703, otherwise, continuing step S717;
step S703, sending a first alignment frame for frame alignment and receiving a second alignment frame sent by the MCU;
step 704, determining whether the data in the second alignment frame is correct, if yes, continuing step 705, otherwise returning to step 702;
step S705, judging whether the frame number in the Byte0 in the second alignment frame is consistent with the frame number in the Byte0 in the first alignment frame, if so, continuing the step S706, otherwise, returning to the step S702;
step S706, judging whether the MCU state indicated by the Byte6 in the second alignment frame is normal, if so, continuing the step S707, otherwise, returning to the step S702;
step S707, assigning the frame number of the Byte3 to the Byte0, assigning the lengths of the bytes 4-5 to the bytes 1-2, generating a first data frame to be transmitted, and waiting;
step S708, the current device initiates a clock for controlling SPI communication between the current device and the peer device, sends the first data frame under the control of the clock, and receives a second data frame returned by the MCU, where a frame number of Byte0 in the second data frame is equal to a frame number of Byte0 in the first data frame, and the second data frame carries data corresponding to the frame number;
step S709, determining whether the Byte0 frame number in the second data frame is consistent with the Byte0 frame number in the sent first data frame, if yes, continuing step S710, otherwise, continuing step S713;
step S710, determining whether the data in the second data frame is correct, if yes, continuing step S711, otherwise, continuing step S715;
step 711, determining whether the MCU status indicated by Byte6 in the second data frame is normal, if yes, continuing step 712, otherwise, continuing step 716;
step S712, assigning the Byte6 to be 0x0, assigning the Byte3 to be next frame data, assigning the bytes 4-5 to be next frame length to generate a next first data frame to be sent, waiting for a period of time, and returning to step S707;
step S713, determining whether the second data frame is a second alignment frame, if yes, returning to step S702, otherwise, continuing to step S714;
specifically, the second data frame is parsed to obtain the frame number in the Byte0 field, if the frame number is 1, it is indicated as the second alignment frame, and if the frame number is not 1, it is indicated as the second alignment frame.
Step S714, assigning the Byte6 to be 0x02, assigning the Byte3 to be the frame number of the previous frame, assigning the bytes 4-5 to be the length of the previous frame, so as to generate the next first data frame to be sent, waiting for a period of time, and continuing to the step S707;
step S715, assigning the Byte6 to be 0x01, assigning the Byte3 to be the frame number of the previous frame, assigning the bytes 4-5 to be the length of the previous frame, so as to generate the next first data frame to be sent, waiting for a period of time, and continuing to step S707;
step S716, assigning the Byte6 value as 0x0, the Byte3 value as the frame number of the previous frame, and the Byte4-5 value as the length of the previous frame, so as to generate the next first data frame to be sent, wait for a period of time, and continue to step S707;
step S717, the SoC reports the SPI communication error to an upper control module (e.g., an AI chip in the body system);
alternatively, the SoC may also handle the SPI communication error itself.
Step S718, ending the current SPI communication.
Fig. 8 shows an SPI communication procedure on the peer device side, which may include the following steps:
step S801, start;
step S802, receiving a first alignment frame for frame alignment and sending a second alignment frame;
step S803, determining whether the data in the first alignment frame is correct, if yes, continuing step S804, otherwise returning to step S802;
step S804, analyzing the Byte3-5 in the first alignment frame, and preparing the data in the second data frame to be sent according to the frame number and the frame length indicated by the Byte 3-5;
step S805, under the clock control initiated by the current device, receiving a first data frame from the SoC, and simultaneously sending a second data frame to the SoC, where the second data frame includes the data prepared in step S804;
step S806, determining whether the instruction and/or data in the first data frame from the SoC is correct, if yes, continuing step S807, otherwise, continuing step S808;
step S807, assigning the Byte6 value to be 0x0, the Byte3 value to be 0, and the Byte4-5 value to be 0, so as to generate the next second data frame to be sent, wait for a period of time, and continue to the step S805;
step S808, determining whether the first data frame from the SoC is a first alignment frame, that is, whether the value of Byte0 in the first data frame is 1, if yes, returning to step S802, otherwise, continuing to step S809;
in step S809, the Byte6 is assigned as 0x10, the Byte3 is assigned as the frame number of the previous frame, and the bytes 4-5 are assigned as the data length of the previous frame, so as to generate the next second data frame to be sent, wait for a period of time, and continue to step S805.
Second embodiment
In this second embodiment, the current device is a slave device, and the peer device is a master device.
The specific implementation process in the second embodiment is the same as the implementation process in the first embodiment, except that the current device in the second embodiment is equivalent to the "opposite device" in the first embodiment, the "first alignment frame" is equivalent to the "second alignment frame" in the first embodiment, and the "first data frame" is equivalent to the "second data frame" in the first exemplary scheme, and the "opposite device" in the second embodiment is equivalent to the "current device" in the first embodiment, the "second alignment frame" is equivalent to the "first alignment frame" in the first embodiment, and the "second data frame" is equivalent to the "first data frame" in the first exemplary scheme, and the specific process is not repeated.
In this embodiment, the second data frame may carry one of the following information or any combination thereof: the current frame number, the current frame data length, the next frame number, the next frame data length, a state flag for indicating the current equipment state, the current frame transmission control data and/or frame data, and a check code for verifying whether the data is correct or not.
In this embodiment, the second alignment frame may carry one of the following information or any combination thereof: the device comprises a current frame number, a next frame number, a data length of the next frame, a state mark for indicating the current equipment state, current frame transmission control data and/or frame data and a check code for verifying whether the data is correct, wherein the value of the current frame number is a preset frame number.
In this embodiment, the first data frame may carry one of the following information or any combination thereof: the current frame number, the current frame data length, a state flag for indicating the state of the opposite terminal equipment, data corresponding to the current frame number, and a check code for verifying whether the data is correct or not.
In this embodiment, the first alignment frame may carry one of the following information or any combination thereof: the current frame number with the value of the preset frame number, the data length of the current frame, a state mark for indicating the state of the opposite terminal equipment, data corresponding to the current frame number, and a check code for verifying whether the data is correct or not.
In this embodiment, after the current device is abnormally restarted, the data in the first alignment frame is determined, that is, the data in the first alignment frame is prepared, so that the first alignment frame is sent to the peer device under the trigger of the clock signal initiated by the peer device (i.e., "current device" in the first embodiment, above, "master device").
In this embodiment, when the status flag in the second data frame from the peer device is the third value, the data in the first alignment frame, that is, the data required for preparing the first alignment frame, is determined, so that the first alignment frame is sent to the peer device under the trigger of the clock signal initiated by the peer device (that is, "current device" in the first embodiment, above, "master device").
In this embodiment, when the second data frame from the peer device includes a next frame number and the status flag in the second data frame is a predetermined first value, the data corresponding to the next frame number is determined, that is, the data corresponding to the next frame number is prepared, and the first data frame with the current frame number being the next frame number is generated, so that the first data frame is sent to the peer device under the trigger of the clock signal initiated by the peer device.
In this embodiment, when the second data frame from the peer device includes the previous frame number and the status flag in the second data frame is a predetermined second value (for example, Byte6 ═ 0x01 above), the data corresponding to the previous frame number is determined, that is, the data corresponding to the previous frame number is prepared, and the first data frame with the current frame number being the previous frame number is generated, so as to send the first data frame to the peer device under the trigger of the clock signal initiated by the peer device.
In this embodiment, whether the data in the second data frame is correct is verified; it is determined whether the current frame number of the second data frame is equal to a predetermined frame number (e.g., frame number 1 of the first frame above). And when the data in the second data frame is wrong and the current frame number in the second data frame is a preset frame number, determining the data in the first alignment frame, namely the data required for preparing the first alignment frame, and generating the first alignment frame so as to send the first alignment frame to the opposite terminal equipment under the triggering of a clock signal initiated by the opposite terminal equipment. When the data in the second data frame is erroneous and the current frame number in the second data frame is not the second aligned frame, determining the data corresponding to the next frame number (i.e. preparing or collecting the data corresponding to the next frame number), while carrying the current frame number in the next first data frame, and setting the status flag in the next first data frame to a predetermined fourth value (e.g. Byte6 ═ 0x10 above), which may be used to indicate that the current device is receiving data anomalies.
The method of the embodiment of the application can achieve the following technical effects: 1. the full-duplex communication of the SPI is realized, and compared with the prior SPI half-duplex scheme, the method saves the waiting time of the SoC and the MCU and improves the efficiency; 2. hardware IO ports are saved, so that unnecessary IO port interrupt triggering of the SoC is reduced; 3. the adjustable data number is transmitted, and the use rate of the SPI bus is optimized; 4. and the transmission standard is unified, so that the development of the SPI bus protocol for subsequent SoC and MCU is facilitated.
Exemplary devices
Fig. 9 is a schematic structural diagram of an SPI-based communication device in an embodiment of the present disclosure. As shown in fig. 9, an SPI-based communication device in an embodiment of the present disclosure may include:
a receiving unit 91 configured to receive a second alignment frame from a peer device for frame alignment; receiving a second data frame from the opposite terminal equipment;
a sending unit 92 configured to send a first alignment frame to a peer device for the frame alignment while the receiving unit receives the second alignment frame; and sending a first data frame to the peer device while the receiving unit receives the second data frame;
a parsing unit 93 configured to parse the second data frame.
The SPI based communication apparatus shown in fig. 9 can be realized by the following first embodiment when the device is a master device, and the SPI based communication apparatus shown in fig. 9 can be realized by the following second embodiment when the device is a slave device.
First embodiment
The first data frame may carry one or any combination of the following information: the device comprises a current frame number, a current frame data length, a next frame number, a next frame data length, a state mark for indicating the current equipment state, current frame transmission control data and/or frame data, and a check code for verifying whether the data is correct or not; and/or the presence of a gas in the gas,
the first alignment frame may carry one or any combination of the following information: a current frame number, a next frame number and a data length of the next frame, which are taken as preset frame numbers, a state mark for indicating the state of current equipment, current frame transmission control data and/or frame data and a check code for verifying whether the data is correct or not; and/or the presence of a gas in the gas,
the second data frame may carry one or any combination of the following information: the current frame number, the current frame data length, a state mark for indicating the state of the opposite terminal equipment, data corresponding to the current frame number, and a check code for verifying whether the data is correct or not; and/or the presence of a gas in the gas,
the second alignment frame may carry one or any combination of the following information: the current frame number with the value of the preset frame number, the data length of the current frame, a state mark for indicating the state of the opposite terminal equipment, data corresponding to the current frame number, and a check code for verifying whether the data is correct or not.
In some examples, the SPI-based communication device may further include: a frame alignment determination unit configured to determine whether frame alignment is successful, and notify the transmission unit 92 that transmission of the first data frame and the second data frame can be started when frame alignment is successful.
In some examples, the frame alignment determining unit may be specifically configured to determine whether frame alignment is successful by one or two of: verifying whether the data in the second alignment frame is correct; and judging whether the frame numbers of the current frames in the first alignment frame and the second alignment frame are consistent or not.
In some examples, the frame alignment unit may be further configured to determine whether the state of the peer device is normal according to a state flag in the second alignment frame, and notify the sending unit 92 to send the first data frame to the peer device when the state of the peer device is normal.
In some examples, the sending unit 92 may be further configured to send the first alignment frame to the peer device to perform frame alignment again after the current device is abnormally restarted.
In some examples, the SPI-based communication device may further include: and the data frame judging unit is configured to verify whether the target data is successfully received, and the target data is obtained by analyzing the second data frame through the analyzing unit 93 and corresponds to the current frame number in the first data frame.
In some examples, the SPI-based communication device may further include: and a frame generation unit. The data frame determining unit may be further configured to determine whether the current state of the peer device is normal according to the state flag in the second data frame when the target data is successfully received, and notify the frame generating unit when the state of the peer device is determined to be normal; a frame generating unit, configured to execute one of the following operations when the data frame determining unit determines that the current state of the peer device is normal: 1) assigning a current frame number in a next first data frame as a next frame number in the current first data frame, assigning the next frame number in the next first data frame as the next frame number of the next frame number in the current first data frame, and simultaneously setting a status flag in the next first data frame as a preset first value, wherein the first value indicates that the current equipment is normal; 2) assigning the current frame number in the next first data frame as the previous frame number carried in the second data frame, and setting the state flag in the next first data frame as the first value.
In some examples, the data frame determination unit configured to verify whether the target data is successfully received may include: judging whether the frame numbers of the second data frame and the current frame in the first data frame are consistent; and verifying whether the data in the second data frame is correct; when the frame number of the current frame in the second data frame is consistent with that of the first data frame and the data in the second data frame is correct, the target data is successfully received; and when the second data frame is consistent with the current frame number in the first data frame and the data in the second data frame is wrong, the target data is failed to be received.
In some examples, the above-mentioned data frame determination unit may be further configured to notify the frame generation unit when it is determined that the target data reception fails, and the frame generation unit may be further configured to assign a next frame number in a next first data frame to be a current frame number in the current first data frame when the target data reception fails, and set a status flag in the next first data frame to a predetermined second value, where the second value is used to indicate that the current device is abnormal in receiving data.
In some examples, the data frame determination unit may be further configured to, when the current frame number in the second data frame is inconsistent with the current frame number in the first data frame, continue to determine whether the current frame number in the second data frame is equal to the predetermined frame number, and notify the frame generation unit. The frame generation unit may be further configured to determine a next first data frame as the first aligned frame when the notification of the data frame determination unit indicates that a current frame number in the second data frame is equal to the predetermined frame number; and when the notification of the data frame judging unit indicates that the current frame number in the second data frame is not equal to the predetermined frame number, assigning the current frame number in the next first data frame as the predetermined frame number, and simultaneously assigning the status flag in the next first data frame as a predetermined third value, wherein the third value is used for indicating that the instruction sent by the current equipment does not accord with the received data.
Second embodiment
The second data frame may carry one or any combination of the following information: the device comprises a current frame number, a current frame data length, a next frame number, a next frame data length, a state mark for indicating the current equipment state, current frame transmission control data and/or frame data, and a check code for verifying whether the data is correct or not; and/or the presence of a gas in the gas,
the second alignment frame may carry one or any combination of the following information: a current frame number, a next frame number and a data length of the next frame, which are taken as preset frame numbers, a state mark for indicating the state of current equipment, current frame transmission control data and/or frame data and a check code for verifying whether the data is correct or not; and/or the presence of a gas in the gas,
the first data frame may carry one or any combination of the following information: the current frame number, the current frame data length, a state mark for indicating the state of the opposite terminal equipment, data corresponding to the current frame number, and a check code for verifying whether the data is correct or not; and/or the presence of a gas in the gas,
the first alignment frame may carry one or any combination of the following information: the current frame number with the value of the preset frame number, the data length of the current frame, a state mark for indicating the state of the opposite terminal equipment, data corresponding to the current frame number, and a check code for verifying whether the data is correct or not.
In some examples, the frame generation unit may be further configured to perform one or more of: 1) after the current equipment is abnormally restarted, determining data in a first alignment frame; 2) when the status flag in the second data frame is a predetermined third value, and the third value is used for indicating that the instruction sent by the opposite terminal device does not accord with the received data, determining the data in the first alignment frame; 3) when the second data frame comprises a next frame number and the state flag in the second data frame is a preset first value, determining data corresponding to the next frame number; 4) and when the second data frame comprises the previous frame number and the state flag in the second data frame is a preset second value, determining the data corresponding to the previous frame number.
In some examples, the data frame determination unit may be further configured to verify whether the data in the second data frame is correct; and/or judging whether the current frame number of the second data frame is equal to the preset frame number or not, and informing the frame generation unit; a frame generation unit, further configured to determine data in the first alignment frame when data in the second data frame is erroneous and a current frame number in the second data frame is the predetermined frame number; and/or when the data in the second data frame is wrong and the current frame number in the second data frame is not the second aligned frame, determining the data corresponding to the next frame number, carrying the current frame number in the next first data frame, setting the status flag in the next first data frame to be a predetermined fourth value, wherein the fourth value can be used for indicating that the current equipment receives data abnormally.
It should be noted that the SPI-based communication device in the embodiment of the present application may be implemented by software, hardware, or a combination of both.
Exemplary electronic device
FIG. 10 illustrates a block diagram of an electronic device 10 according to an embodiment of the application.
As shown in fig. 10, the electronic device 10 may include one or more processors 101 and memory 102.
Processor 131 may be a Central Processing Unit (CPU) or other form of processing unit having data processing capabilities and/or instruction execution capabilities, and may control other components in electronic device 10 to perform desired functions.
Memory 102 may include one or more computer program products that may include various forms of computer-readable storage media, such as volatile memory and/or non-volatile memory. The volatile memory may include, for example, Random Access Memory (RAM), cache memory (cache), and/or the like. The non-volatile memory may include, for example, Read Only Memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium and executed by the processor 101 to implement the method of determining an orientation of an object and/or other desired functionality of the various embodiments of the application described above.
In one example, the electronic device 10 may further include: an input device 103 and an output device 104, which are interconnected by a bus system and/or other form of connection mechanism (not shown). The input device 133 may be, for example, a microphone or an array of microphones. The input device 103 may also include, for example, a keyboard, a mouse, and the like. The output device 104 can output various information to the outside. The output devices 134 may include, for example, a display, speakers, a printer, and a communication network and remote output devices connected thereto, among others.
Of course, for simplicity, only some of the components of the electronic device 10 relevant to the present application are shown in fig. 10, and components such as buses, input/output interfaces, and the like are omitted. In addition, the electronic device 10 may include any other suitable components depending on the particular application.
Exemplary computer program product and computer-readable storage Medium
In addition to the above-described methods and apparatus, embodiments of the present application may also be a computer program product comprising computer program instructions that, when executed by a processor, cause the processor to perform the steps in an SPI-based communication method according to various embodiments of the present application described in the "exemplary methods" section of this specification above.
The computer program product may be written with program code for performing the operations of embodiments of the present application in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server.
Furthermore, embodiments of the present application may also be a computer-readable storage medium having stored thereon computer program instructions that, when executed by a processor, cause the processor to perform steps in an SPI-based communication method according to various embodiments of the present application, as described in the "exemplary methods" section above of this specification.
The computer-readable storage medium may take any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may include, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The foregoing describes the general principles of the present application in conjunction with specific embodiments, however, it is noted that the advantages, effects, etc. mentioned in the present application are merely examples and are not limiting, and they should not be considered essential to the various embodiments of the present application. Furthermore, the foregoing disclosure of specific details is for the purpose of illustration and description and is not intended to be limiting, since the foregoing disclosure is not intended to be exhaustive or to limit the disclosure to the precise details disclosed.
The block diagrams of devices, apparatuses, systems referred to in this application are only given as illustrative examples and are not intended to require or imply that the connections, arrangements, configurations, etc. must be made in the manner shown in the block diagrams. These devices, apparatuses, devices, systems may be connected, arranged, configured in any manner, as will be appreciated by those skilled in the art. Words such as "including," "comprising," "having," and the like are open-ended words that mean "including, but not limited to," and are used interchangeably therewith. The words "or" and "as used herein mean, and are used interchangeably with, the word" and/or, "unless the context clearly dictates otherwise. The word "such as" is used herein to mean, and is used interchangeably with, the phrase "such as but not limited to".
It should also be noted that in the devices, apparatuses, and methods of the present application, the components or steps may be decomposed and/or recombined. These decompositions and/or recombinations are to be considered as equivalents of the present application.
The previous description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present application. Various modifications to these aspects will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other aspects without departing from the scope of the application. Thus, the present application is not intended to be limited to the aspects shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
The foregoing description has been presented for purposes of illustration and description. Furthermore, the description is not intended to limit embodiments of the application to the form disclosed herein. While a number of example aspects and embodiments have been discussed above, those of skill in the art will recognize certain variations, modifications, alterations, additions and sub-combinations thereof.

Claims (10)

1. A communication method based on a serial peripheral interface comprises the following steps:
sending a first alignment frame to opposite-end equipment, and receiving a second alignment frame from the opposite-end equipment at the same time so as to carry out frame alignment;
when the frame alignment is successful, sending a first data frame to opposite-end equipment, and receiving a second data frame from the opposite-end equipment;
and analyzing the second data frame.
2. The method of claim 1, wherein,
the first data frame carries at least one of the following information: the device comprises a current frame number, a current frame data length, a next frame number, a next frame data length, a state mark for indicating the current equipment state, current frame transmission control data and/or frame data, and a check code for verifying whether the data is correct or not; and/or the presence of a gas in the gas,
the first alignment frame carries at least one of the following information: a current frame number, a next frame number and a data length of the next frame, which are taken as preset frame numbers, a state mark for indicating the state of current equipment, current frame transmission control data and/or frame data and a check code for verifying whether the data is correct or not; and/or the presence of a gas in the gas,
the second data frame carries at least one of the following information: the current frame number, the current frame data length, a state mark for indicating the state of the opposite terminal equipment, data corresponding to the current frame number, and a check code for verifying whether the data is correct or not; and/or the presence of a gas in the gas,
the second alignment frame carries at least one of the following information: the current frame number with the value of the preset frame number, the data length of the current frame, a state mark for indicating the state of the opposite terminal equipment, data corresponding to the current frame number, and a check code for verifying whether the data is correct or not.
3. The method of claim 2, before sending the first data frame to the peer device, further comprising: determining whether the frame alignment is successful, so as to start transmission of the first data frame and the second data frame when the frame alignment is successful.
4. The method of claim 1, further comprising: and judging whether the state of the opposite terminal equipment is normal or not according to the state mark in the second alignment frame, and executing the step of sending the first data frame to the opposite terminal equipment when the state of the opposite terminal equipment is normal.
5. The method of claim 1 or 2, further comprising: and after the current equipment is abnormally restarted, sending a first alignment frame to the opposite terminal equipment to perform frame alignment again.
6. The method of claim 1, after parsing the second data frame, further comprising: and verifying whether the target data is successfully received, wherein the target data is obtained by analyzing the second data frame and corresponds to the current frame number in the first data frame.
7. The method of claim 1, wherein,
the second data frame carries at least one of the following information: the device comprises a current frame number, a current frame data length, a next frame number, a next frame data length, a state mark for indicating the current equipment state, current frame transmission control data and/or frame data, and a check code for verifying whether the data is correct or not; and/or the presence of a gas in the gas,
the second alignment frame carries at least one of the following information: a current frame number, a next frame number and a data length of the next frame, which are taken as preset frame numbers, a state mark for indicating the state of current equipment, current frame transmission control data and/or frame data and a check code for verifying whether the data is correct or not; and/or the presence of a gas in the gas,
the first data frame carries at least one of the following information: the current frame number, the current frame data length, a state mark for indicating the state of the opposite terminal equipment, data corresponding to the current frame number, and a check code for verifying whether the data is correct or not; and/or the presence of a gas in the gas,
the first alignment frame carries at least one of the following information: the current frame number with the value of the preset frame number, the data length of the current frame, a state mark for indicating the state of the opposite terminal equipment, data corresponding to the current frame number, and a check code for verifying whether the data is correct or not.
8. A serial peripheral interface based communication device, comprising:
a receiving unit configured to receive a second alignment frame from a peer device for frame alignment; receiving a second data frame from the opposite terminal equipment;
a transmitting unit configured to transmit a first alignment frame to a peer device for the frame alignment while the receiving unit receives the second alignment frame; and sending a first data frame to the peer device while the receiving unit receives the second data frame;
a parsing unit configured to parse the second data frame.
9. An electronic device, comprising:
one or more processors; and
memory storing a computer program which, when executed by the processor, causes the processor to perform the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program is stored which, when executed by a processor, causes the processor to carry out the method according to any one of claims 1 to 7.
CN202110002599.2A 2021-01-04 2021-01-04 SPI-based communication method and device, electronic equipment and storage medium Active CN112822002B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110002599.2A CN112822002B (en) 2021-01-04 2021-01-04 SPI-based communication method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110002599.2A CN112822002B (en) 2021-01-04 2021-01-04 SPI-based communication method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN112822002A true CN112822002A (en) 2021-05-18
CN112822002B CN112822002B (en) 2023-07-21

Family

ID=75856925

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110002599.2A Active CN112822002B (en) 2021-01-04 2021-01-04 SPI-based communication method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112822002B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113688094A (en) * 2021-08-24 2021-11-23 中汽创智科技有限公司 Data communication method, device and system of vehicle-mounted machine system and storage medium
CN116032733A (en) * 2022-11-29 2023-04-28 合众新能源汽车股份有限公司 Method, device, equipment and medium based on intelligent central control system vehicle control communication

Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1851682A (en) * 2006-03-28 2006-10-25 华为技术有限公司 Method for realizing serial peripheral unit interface
CN101119224A (en) * 2006-08-01 2008-02-06 上海未来宽带技术及应用工程研究中心有限公司 ATCA frame based FRU debugging and testing device
CN102819512A (en) * 2012-06-28 2012-12-12 惠州市德赛西威汽车电子有限公司 Full-duplex communication device based on SPI and method thereof
CN104836927A (en) * 2015-02-10 2015-08-12 数据通信科学技术研究所 Voice synchronization method and terminal
CN105208467A (en) * 2015-08-20 2015-12-30 电子科技大学 Frame aligning apparatus of broadband access network system
CN107562666A (en) * 2017-09-26 2018-01-09 威创集团股份有限公司 Method, system and the relevant apparatus of communication between devices based on spi bus
CN109787703A (en) * 2019-02-28 2019-05-21 烽火通信科技股份有限公司 A kind of modification method of timestamp, clock synchronizing method and system
CN109902053A (en) * 2017-12-07 2019-06-18 厦门雅迅网络股份有限公司 A kind of SPI communication method, terminal device and storage medium based on dual controller
CN110311875A (en) * 2018-03-20 2019-10-08 华为技术有限公司 A kind of data transmission method and device
CN110334046A (en) * 2019-07-11 2019-10-15 南方电网科学研究院有限责任公司 SPI full-duplex communication method, device and system
US10467007B1 (en) * 2017-08-08 2019-11-05 Bae Systems Information And Electronic Systems Integration Inc. Core for controlling multiple serial peripheral interfaces (SPI's)
CN110463135A (en) * 2017-03-31 2019-11-15 华为技术有限公司 Full duplex transmission method and device
CN111130710A (en) * 2019-12-10 2020-05-08 常州新途软件有限公司 SPI-based duplex communication method

Patent Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1851682A (en) * 2006-03-28 2006-10-25 华为技术有限公司 Method for realizing serial peripheral unit interface
CN101119224A (en) * 2006-08-01 2008-02-06 上海未来宽带技术及应用工程研究中心有限公司 ATCA frame based FRU debugging and testing device
CN102819512A (en) * 2012-06-28 2012-12-12 惠州市德赛西威汽车电子有限公司 Full-duplex communication device based on SPI and method thereof
CN104836927A (en) * 2015-02-10 2015-08-12 数据通信科学技术研究所 Voice synchronization method and terminal
CN105208467A (en) * 2015-08-20 2015-12-30 电子科技大学 Frame aligning apparatus of broadband access network system
CN110463135A (en) * 2017-03-31 2019-11-15 华为技术有限公司 Full duplex transmission method and device
US10467007B1 (en) * 2017-08-08 2019-11-05 Bae Systems Information And Electronic Systems Integration Inc. Core for controlling multiple serial peripheral interfaces (SPI's)
CN107562666A (en) * 2017-09-26 2018-01-09 威创集团股份有限公司 Method, system and the relevant apparatus of communication between devices based on spi bus
CN109902053A (en) * 2017-12-07 2019-06-18 厦门雅迅网络股份有限公司 A kind of SPI communication method, terminal device and storage medium based on dual controller
CN110311875A (en) * 2018-03-20 2019-10-08 华为技术有限公司 A kind of data transmission method and device
CN109787703A (en) * 2019-02-28 2019-05-21 烽火通信科技股份有限公司 A kind of modification method of timestamp, clock synchronizing method and system
CN110334046A (en) * 2019-07-11 2019-10-15 南方电网科学研究院有限责任公司 SPI full-duplex communication method, device and system
CN111130710A (en) * 2019-12-10 2020-05-08 常州新途软件有限公司 SPI-based duplex communication method

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113688094A (en) * 2021-08-24 2021-11-23 中汽创智科技有限公司 Data communication method, device and system of vehicle-mounted machine system and storage medium
CN113688094B (en) * 2021-08-24 2024-03-22 中汽创智科技有限公司 Data communication method, device and system of vehicle-mounted system and storage medium
CN116032733A (en) * 2022-11-29 2023-04-28 合众新能源汽车股份有限公司 Method, device, equipment and medium based on intelligent central control system vehicle control communication

Also Published As

Publication number Publication date
CN112822002B (en) 2023-07-21

Similar Documents

Publication Publication Date Title
US8892714B2 (en) Managing inventory data for components of a server system
CN112822002A (en) SPI (Serial peripheral interface) -based communication method and device, electronic equipment and storage medium
TWI602122B (en) Firmware updating method
WO2011137640A1 (en) File transmission method, file transmission apparatus and file reception apparatus
US20130003751A1 (en) Method and system for exponential back-off on retransmission
CN109450912B (en) Data transmission method, device and equipment
CN112423321A (en) Upgrading method and device based on wireless broadcast and electronic equipment
US7783964B2 (en) Redundant 3-wire communication system and method
CN111752579A (en) Bluetooth terminal upgrading method and device, storage medium and electronic equipment
US6977901B2 (en) Packet transmission/reception processor
JP2009244991A (en) Data communication method, data communication system, electronic control unit, and circuit board
US20210014006A1 (en) System and method for implementing a hybrid automatic repeat request process
US11868209B2 (en) Method and system for sequencing data checks in a packet
US10101987B2 (en) Method and system of processing an image upgrade
CN116204214A (en) BMC upgrading method, device and system, electronic equipment and storage medium
US9621339B1 (en) Host devices and data transmission methods
CN107665123B (en) Firmware updating method
CN112511636B (en) Data transmission system, method, device, computer equipment and storage medium
JP6110415B2 (en) Communication apparatus and communication method
CN108075860B (en) Method and device for data transmission with a hearing device
CN112363962A (en) Data communication method, system, electronic device and computer storage medium
CN111666089B (en) Firmware updating method of electronic device, chip, electronic device and storage medium
CN113301130A (en) Communication method and device of sewing equipment controller, terminal equipment and storage medium
CN117411593A (en) Protocol layer packet transmission sequence processing system, method and medium of USB3.1 host computer speed reduction bridge
JP2003186767A (en) Facing connection test method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant