CN112822002B - SPI-based communication method and device, electronic equipment and storage medium - Google Patents

SPI-based communication method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN112822002B
CN112822002B CN202110002599.2A CN202110002599A CN112822002B CN 112822002 B CN112822002 B CN 112822002B CN 202110002599 A CN202110002599 A CN 202110002599A CN 112822002 B CN112822002 B CN 112822002B
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.)
Active
Application number
CN202110002599.2A
Other languages
Chinese (zh)
Other versions
CN112822002A (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

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)
  • Theoretical Computer Science (AREA)
  • Signal Processing (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Communication Control (AREA)

Abstract

Disclosed are an SPI-based communication method, an electronic device, and a storage medium. In the embodiment of the application, the communication method based on the serial peripheral interface may include: transmitting a first alignment frame to opposite terminal equipment, and simultaneously receiving a second alignment frame from the opposite terminal equipment so as to perform frame alignment; 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 at the same time; and analyzing the second data frame. According to the method and the device for achieving the full duplex communication of the SPI, the waiting time of equipment communication is saved, the communication efficiency is improved, and the utilization rate of hardware resources such as a master equipment, a slave equipment and an SPI bus of the SPI communication can be improved.

Description

SPI-based communication method and device, electronic equipment and storage medium
Technical Field
The disclosure relates to the technical field of automatic driving, and in particular relates to a communication method and device based on a serial peripheral interface (SPI, serial Peripheral Interface), electronic equipment and a storage medium.
Background
In an automatic driving embedded system, the amount of data transmitted between a system-on-chip (SoC) and a micro control unit (MCU, microcontroller Unit) is increasing, and the rate is required to be in the Mbps level, so that communication is basically performed by using a serial peripheral interface (SPI, serial Peripheral Interface) bus 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 the SPI bus, the MCU prepares data after analyzing the instruction and reminds the SoC through an input-output (IO) interface, and the SoC reads the data prepared by the MCU. In order to solve the technical problem, the embodiment of the disclosure is expected to provide a communication method and device based on SPI, electronic equipment and storage medium, so as to realize full duplex communication of SPI.
According to one aspect of the present application, there is provided a communication method based on a serial peripheral interface, including: transmitting a first alignment frame to opposite terminal equipment, and simultaneously receiving a second alignment frame from the opposite terminal equipment so as to perform frame alignment; 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 at the same time; and analyzing the second data frame.
According to one aspect of the present application, there is provided a communication device based on a serial peripheral interface, comprising: a receiving unit configured to receive a second alignment frame from the peer device for frame alignment; and receiving a second data frame from the peer device; 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 transmitting a first data frame to the peer device while the receiving unit receives the second data frame; and the analyzing unit is configured to analyze the second data frame.
According to one aspect of the present application, there is provided an electronic device comprising: one or more processors; and a memory storing a computer program which, when executed by the processor, causes the processor to perform the above-described serial peripheral interface-based communication method.
According to one aspect of the present application, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, causes the processor to perform the above-described serial peripheral interface based communication method.
According to the method, the device, the equipment and the storage medium of the embodiment of the disclosure, when the master equipment (for example, soC) sends the instruction and the data through the SPI bus, the slave equipment (for example, MCU) also transmits the data of the instruction to the master equipment, so that full duplex communication is realized, transmission time is saved, efficiency is improved, and real parallel communication is realized.
Drawings
The foregoing and other objects, features and advantages of the present application will become more apparent from the following more particular description of embodiments of the present application, as illustrated in the accompanying drawings. The accompanying drawings are included to provide a further understanding of embodiments of the application and are incorporated in and constitute a part of this specification, illustrate the application and not constitute a limitation to the application. In the drawings, like reference numerals generally refer to like parts or steps.
FIG. 1 is an exemplary deployment configuration diagram of a system to which the present application is applicable.
Fig. 2 is a flowchart of an SPI-based communication method according to an exemplary embodiment of the present application.
Fig. 3 is a schematic frame structure used for SPI communication according to an exemplary embodiment of the present application.
Fig. 4 is a schematic frame structure of a first data frame according to an exemplary embodiment of the present application.
Fig. 5 is a schematic frame structure of a second data frame according to an exemplary embodiment of the present application.
Fig. 6 is a schematic frame structure of a second data frame according to another exemplary embodiment of the present application.
Fig. 7 is a schematic diagram of a master device side SPI communication flow according to an exemplary embodiment of the present application.
Fig. 8 is a flowchart of a slave-side SPI communication provided in 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 apparent that the described embodiments are only some of the embodiments of the present application and not all of the embodiments of the present application, and it should be understood that the present application is not limited by the example embodiments described herein.
Summary of the application
As described above, in the related art, the communication scheme between the SoC and the MCU is that the SoC sends an instruction to the MCU through the SPI bus, the MCU parses the instruction and prepares data and reminds the SoC through an input-output (IO) interface, and then the SoC reads the data prepared by the MCU.
In order to solve the above technical problems, a basic idea of an embodiment of the present disclosure is to provide an SPI-based communication method and apparatus, and a storage medium, in which a current apparatus (hereinafter, master apparatus or slave apparatus) may receive a second alignment frame from a counterpart apparatus (hereinafter, slave apparatus or master apparatus) for frame alignment while transmitting the first alignment frame to the counterpart apparatus; 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, thereby obtaining content such as instructions, data, and the like by parsing the second data frame. Therefore, the embodiment of the application can realize that the slave device (for example, the MCU below) also transmits the data of the instruction to the master device while the master device (for example, the SoC below) transmits the instruction and the data through the SPI bus, and the slave device also receives the next instruction through the SPI bus while transmitting the data of the instruction to the master device, 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, embodiments of the present application may be particularly applicable to SPI communications in embedded systems such as autopilot technology.
Exemplary System
Fig. 1 is an exemplary block diagram of an embedded system to which embodiments of the present application are applicable. As shown in fig. 1, an embedded system applicable to an embodiment of the present application may include: a system on chip (SoC) and a micro control unit (MCU, microcontroller Unit) that can communicate through a serial peripheral interface (SPI, serial Peripheral Interface).
In a specific application, any one of the MCU and the SoC in the embedded system can be used as a master device, and the other one of the MCU and the SoC can be used as a slave device. For example, when the SoC is a master and the MCU is a slave, the SoC may transmit an instruction to the MCU through the SPI, and the MCU may prepare data required for 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 supporting a single chip microcomputer system such as 8 bit/16 bit/32 bit. The SoC may be, but is not limited to, a SoC that supports an operating system such as Mac, windows, linux.
Exemplary method
Fig. 2 is a flowchart of 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, a first alignment frame is sent to the opposite terminal equipment, and a second alignment frame from the opposite terminal equipment is received at the same time so as to perform frame alignment;
step S202, when 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 at the same time;
in step S203, the second data frame is parsed.
In the embodiment of the application, the current device and the opposite terminal device are synchronized through frame alignment, then in the interaction process of data and instructions, the current device sends out a first data frame and can receive 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, assuming that the current device is a master device, the first data frame carries the instruction a, and then the 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 then 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 current instruction to the master device while receiving the instruction. Therefore, compared with the prior SPI half-duplex scheme, the full-duplex SPI communication method and device achieve full-duplex SPI communication, saves waiting time of SoC and MCU, improves communication efficiency, and effectively improves utilization rate of hardware resources such as a master device, a slave device and an SPI bus.
Two exemplary implementations of the above-described methods of 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 opposite device is a slave device.
In this embodiment, the first data frame may carry one or any combination of the following information: the method comprises the steps of a current frame number, a current frame data length, a next frame number, a next frame data length, a state mark for indicating the state of the current equipment, current frame transmission control data and/or frame data and a check code for verifying whether the data are correct or not. By carrying the frame number of the next frame in the first data frame, the data required by the next frame of the slave device can be indicated in the current 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 or any combination of the following information: the method comprises the steps of taking a current frame number with a preset frame number as a value, taking the next frame data length as a value, taking a state mark for indicating the state of the current equipment as a value, taking the current frame transmission control data and/or frame data as a value, and taking the check code for verifying whether the data are correct or not as a value.
In this embodiment, the second data frame may carry one or any combination of the following information: the method comprises the steps of a current frame number, a 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 are correct or not.
In this embodiment, the second alignment frame may carry one or any combination of the following information: the method comprises the steps of taking a current frame number with a preset frame number as a value, a current frame data length, a state mark for indicating the state of opposite terminal equipment, data corresponding to the current frame number and a check code for verifying whether the data are correct or not.
Fig. 3 shows an exemplary format of each frame in an embodiment of the present application. Fig. 4 shows a frame structure of a 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, which are a start symbol, N information fields (N is an integer not less than 1), and an end symbol, respectively. In some examples, the initiator of the frame may be predefined as 0x2C for determining the start of the frame. The ending symbol may be predefined as "0x7E" 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 and is used for identifying which instruction is currently transmitted; the current frame number can be represented by 1-255, and the customization can be specifically required in practice;
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 is used to identify which command the next time the master device is to send to the slave device; the next frame number can be represented by 1-255, and the value of the next frame number can be defined according to the application scene;
byte4-5 is the length of the next frame data and is used to know how much data is needed for the next frame to the slave;
byte6 is a status indication bit for indicating a transmission status, where bits 0-3 are status indications of the master device, and bits 4-7 are status indications of the slave device, and specific values and meanings represented by the values are shown in table 1 below.
TABLE 1
Byte 7-N-1 is used to carry current frame transmission control data and frame data.
ByteN is the data checksum of Byte0 through Byte (N-1), such as CRC8.
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 be in the frame format shown in fig. 3. Unlike the first data frame and the first frame alignment, the effects of bytes 3-5 are different. When the command or data received by the opposite terminal device from the current device is wrong, one or two of the following may be included in the first data frame: the instruction identification of the previous frame and the data length of the previous frame. Thus, in the second alignment frame and the second data frame of the opposite terminal device, by default (i.e., when the SPI communication is normal), byte3-5 takes 0 (other meaningless values may be taken), and only when the opposite terminal device finds that the received command or data is wrong and needs to re-request the command or data from the current device, byte3-5 will have a certain value, and the value of Byte3 is equal to the frame number (i.e., command identifier) of the frame requested by the opposite terminal device, and the values of bytes 4-5 are equal to the data length of the frame. Fig. 5 shows a frame structure of a second data frame when 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 a current device when a command or data received by a counterpart device is erroneous.
Through the frame format, the two side devices of SPI communication can conveniently perform frame analysis to obtain data or instructions, and can carry the next frame number in the first data frame sent by the main device, so that the slave device can obtain the next frame number after receiving the current first data frame, prepare the data required by the next frame in time and send the data required by the next first data frame to the main device from the slave device while sending the next first data frame. Thus, SPI full duplex communication is realized.
In at least some embodiments, the formats of the first alignment frame and the first data frame may be identical, and only the information carried is different. In other words, the first aligned frame and the second aligned 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 and the MCU is the opposite device in the system shown in fig. 1, the SoC is the master device, the format of the first alignment frame may be "0x2C 0x01 0x00010x02 0x100 0x0 0x00x (crc 8) 0x7E", and the format of the second alignment frame may be "0x2C 0x01 0x0001 0x00 0x00 0x0 0x00x (crc 8) 0x7E". In this example, the process of step S101 is: the SoC transmits the first frame and the self state to the MCU, and the MCU simultaneously transmits the first frame number and the self state to the SoC.
In at least some embodiments, a determination may be made as to whether frame alignment was successful prior to sending a first data frame to a peer device, such that transmission of the first data frame and the second data frame begins when the frame alignment was successful. If the frame alignment is successful, the above step S202 is continued, and if the frame alignment fails, the frame alignment may be performed again until the frame alignment is successful or the number of times of the frame alignment reaches a preset upper limit value. If the number of frame alignment reaches a preset upper limit, a notification may be sent to the upper control module. The two devices of the SPI communication can be synchronized through frame alignment, so that the frames sent by the two devices at the same time are ensured to be corresponding (namely, the command in the frame sent by the master device and the data in the frame sent by the slave device are corresponding), so that the master device can receive the data requested by the command while sending the command, and the SPI full duplex communication is realized.
In some examples, determining whether frame alignment was successful may include one or both of: verifying whether the data in the second aligned frame is correct; and judging whether the current frame number in the first aligned frame is consistent with the current frame number in the second aligned frame. The two-term judgment can ensure the strict synchronization between the two devices in SPI communication, and meets the requirement of SPI full duplex communication.
One implementation of the above example may be: verifying whether the second alignment frame is normal or not, and determining whether the state of the opposite terminal equipment is normal or not according to the state indication in the second alignment frame; when the second alignment frame is normal and the opposite terminal equipment state is normal, confirming that the current equipment side frame is successfully aligned; 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 sides of the SPI communication confirm that the alignment is successful, the frame alignment is considered to be successful.
In the above implementation manner, verifying whether the second alignment frame is normal may include: determining whether the data in the second aligned frame is correct according to the check code in the second aligned frame, and comparing the current frame number in the second aligned frame with the current frame number in the first aligned frame; and when the data in the second alignment frame is correct and the second alignment frame is consistent with the current frame number of the first alignment frame, confirming that the second alignment frame is normal. Here, whether the data in the frame is correct may be determined by a "checksum" in the frame.
In the above implementation manner, according to the status indication in the second alignment frame, it is determined whether the status of the peer device is normal, and when the status of the peer device is normal, step S202 of sending the first data frame to the peer device is performed. If the state of the opposite terminal device is abnormal, the first alignment frame can be sent to the opposite terminal device again to perform frame alignment again.
After the frame alignment is successful, the SPI communication parties can normally communicate, and the current equipment and the opposite-end equipment can perform full duplex communication through the SPI.
The process of the current device and the opposite device exchanging data through the SPI can be: the current device sends a first data frame with a frame number y (y is an integer greater than 1) to the opposite terminal device, and meanwhile, the opposite terminal device returns a second data frame with the 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, analyzing the second data frame to obtain data, a frame number and a state indication value indicating the state of the opposite terminal device, firstly judging 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, judging whether the state of the opposite terminal 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 current device, judging whether the state of the opposite terminal device is normal, if the state of the second data frame is normal, continuing to enable the current device to carry out the next first data frame (namely, the first data frame with the frame number of y+1), firstly assigning the frame number in Byte3 to Byte0, assigning the lengths of Byte4-5 to Byte3 and assigning the frame number of the next frame to be sent to Byte4-5, generating the first data frame with the frame number of y+1, and waiting for a period of time.
After receiving the first data frame with the frame number y, the opposite terminal device analyzes the first data frame to obtain data, a frame number and a state indication value indicating the state of the current device, firstly judges whether the data in the first data frame is correct, whether the frame number is consistent with the frame number of the second data frame sent by the opposite terminal device or not, 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 device and the state of the current device is normal, the opposite terminal device prepares the data H required by the next second data frame (namely, the second data frame with the frame number of y+1) according to the frame number in Byte3 in the first data frame with the frame number y, assigns the length of Byte3 to Byte0 and the length of Byte4-5 to Byte1-2, fills the prepared data H in a data field (Byte 7-N-1) to generate the second data frame with the frame number of y+1, and waits for a period of time.
After the current device generates a first data frame with the frame number of y+1 and the opposite terminal device generates a second data frame with the frame number of y+1 and a period of time passes, under the clock control initiated by the current device, the current device and the opposite terminal device interact 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 condition that the current equipment and the opposite terminal equipment respectively judge that the received data and the received command are normal, the operation of data interaction is repeated between the current equipment and the opposite terminal equipment through the SPI bus, so that SPI full duplex communication is realized.
During the process of data and instruction interaction between the two devices in the SPI communication through the embodiment, an abnormal event may be generated, and the abnormal event is likely to break the strict synchronization between the two devices in the SPI communication. In a similar situation, frame alignment needs to be re-performed to ensure that the two devices for SPI communication are properly synchronized.
Alternatively, in at least some embodiments, frame alignment may be re-performed to ensure tight synchronization between the two devices of the SPI communication upon occurrence of one or more of the following events: 1. the current equipment is restarted; 2. the opposite terminal equipment is restarted. In addition, when other similar events occur, strict synchronization between the two devices of the SPI communication can be ensured by carrying out frame alignment again, and the embodiment of the application is not limited for specific events.
In some examples, after the current device is abnormally restarted, the first alignment frame may be sent to the opposite device to perform frame alignment again, so as to ensure that the SPI two devices are strictly synchronized after the current device is powered up again, and the SPI full duplex communication requirement is met. The abnormal restart herein may include, but is not limited to, an abnormal reset, a software reset, a hardware reset, etc., the abnormal 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 reason, the current device may retransmit the first frame for frame alignment, but the frame number of the frame simultaneously returned by the opposite device 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 peer device finds that the instruction of the current device is inconsistent with the instruction sent by the peer device and the instruction of the current device is the first frame (i.e. aligned frame), so that when the current device and the peer device interact with each other in the next frame, the current device will continue to resend the first frame to the peer device, and at the same time the peer device will send the first frame for frame alignment to the current device, so that the current device and the peer device perform frame alignment again.
Table 2 below shows the data interaction process for re-frame alignment 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 restarted, and "X" represents the frame number of the first frame from the peer device received after the current device is restarted, and since the frame currently received by the current device from the peer device is not the first frame, the frame alignment cannot be completed, and thus the current frame number of the current device is 1, the next frame number is still 1, and since the next frame current device will simultaneously receive the first frame from the peer device, the current frame number of the next frame of the current device is 1, and the next frame number is 2.
Current device 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 restarted, the peer device may initiate and re-align the frame through the aligned frame, so as to ensure that the SPI two devices are strictly synchronized after the current device is powered up again, and meet the SPI full duplex communication requirement. Specifically, the current device may complete the frame alignment operation initiated by the peer device by sending the first alignment frame to the peer device after receiving the second alignment frame (e.g., the first frame described above) from the peer device. The abnormal restart herein may include, but is not limited to, an abnormal reset, a software reset, a hardware reset, etc., the abnormal 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 peer device is abnormally restarted for some reason, after the abnormal restart, the peer device may send a second alignment frame to the current device to initiate a frame alignment operation to re-perform frame alignment. Table 3 below shows the data interaction process for the re-frame alignment between the current device and the peer device after the peer device has been 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 the sequence of normal data interaction, the current frame carries a frame number k+1 of the next frame, and the peer device sends a first frame (frame number 1) for frame alignment to the current device at the same time due to the abnormal restart, and the current device finds out the k frame sent by itself and receives the first frame, and then determines that the peer device requests to be aligned again, at this time, the current device sends the first frame (frame number 1 and frame number 2 carrying the next frame) for frame alignment in the next frame, and the peer device sends the first frame sent by itself and receives the k frame, and then continues to send the first frame in the next frame.
Current device 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 Table 3
In the embodiment of the present application, in order to avoid that both SPI communication parties fall into frame alignment operation of infinite loop due to other errors, control may also be performed by setting an upper limit of frame alignment. For example, the upper limit of the frame alignment number may be set to M (M is an integer not less than 1), and if the frame alignment number exceeds the upper limit M, a message that SPI communication abnormality cannot be reported to the upper control module is currently set. If the frame alignment number 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, the second data frame is parsed in step S203, and it is also possible to verify whether the target data is successfully received, where the target data is obtained by parsing 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 received successfully, 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 of the next frame number in the current first data frame, and the state flag in the next first data frame may be set to a predetermined first value (e.g., bit0-3 of Byte6 in the examples of fig. 3 and 4 is set to 0), which may indicate that the current device is normal, so as to continuously request data from the peer device.
In the process of data and instruction interaction between the two devices in the SPI communication through the embodiment, an abnormal event may be generated, and the abnormal event is likely to cause errors in the data interacted between the two devices in the SPI communication. Alternatively, in at least some embodiments, both devices of the SPI communication may correct by an error correction mechanism when one or more of the following events occur: 1. the current equipment receives the data of the opposite terminal equipment and generates errors; 2. the opposite terminal equipment receives the instruction and the data of the current equipment and generates errors.
In some examples, the error correction mechanism may include: the current state of the peer device is normal, but the peer device receives the command or data of the current device and has an error, the peer device may carry a corresponding frame number (for example, bytes 3 to 5 in the example of fig. 3) in the 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 last frame number carried in the second data frame, and set the state flag in the next first data frame to the first value described above, so as to continuously request data from the peer device.
In some examples, the error correction mechanism may further include: when the data of the current device receiving the peer device is in error (i.e. when the target data fails to be received), the next frame number in the next first data frame may be assigned to the current frame number in the current first data frame, and meanwhile, the status flag in the next first data frame may be set to a predetermined second value (for example, bit0-3 of Byte6 in the examples of fig. 3 and fig. 4 is set to 1), where the second value may be used to indicate that the current device receives the data abnormally. In this way, when the data received by the current device is wrong, the corresponding data can be re-requested from the opposite terminal device.
In at least some embodiments, verifying whether the target data was received successfully may include: judging whether the current frame number in the second data frame is consistent with the current frame number in the first data frame; and verifying whether the data in the second data frame is correct; 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 correct, the target data is successfully received; 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 reception fails. In this embodiment, whether the data is successfully received can be determined by the frame number in time.
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 checksum (one of the checkcodes) 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), and comparing the calculated checksum with the checksum parsed from the second data frame, both of which agree that the data in the second data frame is correct, and both of which disagree that the data in the second data frame is incorrect.
In at least some embodiments, when the second data frame is inconsistent with the current frame number in the first data frame, a determination may be continued as to 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 a re-frame alignment. If the current frame number in the second data frame is equal to the predetermined 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 will not be described in detail.
In at least some embodiments, when the second data frame is inconsistent 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 to the predetermined frame number (e.g., frame number 1 of the first frame above), while the status flag in the next first data frame is assigned to a predetermined third value (e.g., bits 0-3 of Byte6 in the examples of fig. 3 and 4 are assigned to 2), the third value is used to indicate that the command issued by the current device is inconsistent with the received data, and by means of the third value, the current device of the peer device may be notified that the frame alignment operation is initiated due to the received data not being consistent with the command issued by the current device, so as to correct the SPI in time, and ensure that the SPI communication is normal.
For example, when the current device receives data of the peer device and errors occur (for example, the current device analyzes a second data frame from the peer device to obtain data and checksum values therein, and finds that the calculated checksum values are inconsistent with the checksum values in the second data frame by calculating the checksum values in the data, so as to determine that the received data has errors), the peer device needs to re-request the data in the frame, and the state indicator Byte6 of the next first data frame can be assigned with 0x01 (indicating "abnormal received data"), the Byte3 can be assigned with the command number (i.e. frame number) of the frame, and the Byte4-5 can be assigned with the length value of the frame, and meanwhile, the MCU is informed to resend the data of the frame when the next data interaction occurs, so that the peer device can be informed to resend the data of the frame when the data has errors, thereby avoiding that the data is missed or cannot be repaired when the data has errors. Table 4 shows an error correction example in which the current device receives the second data frame with frame number 3 at the same time when the first data frame with frame number 3 is transmitted to the opposite device, finds that the received data is wrong by parsing the field Byte6 in the second data frame with frame number 3, carries the frame number and the frame data length of the 3 rd frame in bytes 3 to 5 in the first data frame with frame number 4, sets Byte6 in the first data frame with frame number 4 to a value "0x01" indicating "abnormal received data", and prepares the second data frame with frame number 3 by the current device transmitting the first data frame with frame number 4 to the opposite device while receiving the second data frame with frame number 4 returned by the opposite device, and after the opposite device receives the first data frame with frame number 4, finds that Byte3 is frame number 3. In the next data interaction, the current device resends the first data frame with the frame number of 3 to the opposite terminal device, and meanwhile, 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 achieved.
Current device 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 Table 4
For another example, when the data and/or the instruction received by the opposite terminal device from the current device have errors (for example, the opposite terminal device analyzes the first data frame from the current device to obtain the data and the checksum value therein, and finds that the calculated checksum value is inconsistent with the checksum value in the first data frame, so as to determine that the received data and/or the instruction has errors), the opposite terminal device needs to re-request the data and/or the instruction in the frame, and the state indicator bit Byte6 of the next second data frame can be assigned as 0x10 (indicating that the received instruction data is abnormal), the Byte3 is assigned as the instruction number (i.e. the frame number) of the frame, and the Byte4-5 is assigned as the length value of the frame, and meanwhile, the current device is informed to resend the instruction and/or the data of the frame when the opposite terminal device receives the instruction and/or the data is wrong, so that the current device can be informed to resend the instruction and/or the data of the frame, and the instruction or the data received by the opposite terminal device cannot be repaired. Table 5 shows an error correction example, when the current device finds that the received data or instruction is wrong when sending the first data frame with the frame number of 3 to the opposite device, then in the second data frame with the frame number of 4, the bytes 3-5 carry the frame number and the frame data length of the 3 rd frame, the Byte6 in the second data frame with the frame number of 4 is set to a value of "0x10" indicating "abnormal data of the received instruction", the current device sends the first data frame with the frame number of 4 to the opposite device, meanwhile receives the second data frame with the frame number of 4 returned by the opposite device, and finds that the Byte3 is the frame number of 3 after receiving the second data frame with the frame number of 4, then in the next data interaction, the current device resends the first data frame with the frame number of 3 to the opposite device, and meanwhile the second data frame with the frame number of 3 returned by the opposite device to the current device, thus the opposite device resends the first data frame with the instruction or the data error to the current device, and realizes the error correction.
TABLE 5
Assuming that the current device is an SoC and the counterpart device is an MCU, fig. 7 shows an SPI communication procedure of the current device side, which may include the steps of:
step S701, beginning;
step S702, judging whether the current synchronization times (i.e. the total number of frame alignment) is smaller than a preset upper limit value M, if yes, continuing step S703, otherwise, continuing step S717;
step S703, transmitting a first alignment frame for frame alignment and receiving a second alignment frame transmitted by the MCU;
step S704, judging whether the data in the second alignment frame is correct, if yes, continuing step S705, otherwise, returning to step S702;
step S705, judging whether the frame number of Byte0 in the second aligned frame is consistent with the frame number of Byte0 in the first aligned frame, if so, continuing step S706, otherwise, returning to step S702;
step S706, judging whether the MCU state indicated by Byte6 in the second alignment frame is normal, if yes, continuing step S707, otherwise, returning to step S702;
step S707, assigning the frame number of Byte3 to Byte0, and assigning the lengths of Bytes 4-5 to Bytes 1-2, generating a first data frame to be transmitted, waiting;
step S708, the current device initiates a clock for controlling SPI communication between the current device and the opposite terminal device, the first data frame is sent under the control of the clock, and a second data frame returned by the MCU is received, wherein the frame number of Byte0 in the second data frame is equal to the frame number of Byte0 of the first data frame and carries data corresponding to the frame number;
Step S709, judging whether the Byte0 frame number in the second data frame is consistent with the frame number of Byte0 in the sent first data frame, if yes, continuing step S710, otherwise continuing step S713;
step S710, judging whether the data in the second data frame is correct, if yes, continuing step S711, otherwise, continuing step S715;
step S711, judging whether the MCU state indicated by Byte6 in the second data frame is normal, if yes, continuing step S712, otherwise, continuing step S716;
step S712, where Byte6 is assigned to 0x0, byte3 is assigned to the next frame data, and bytes 4-5 are assigned to the length value of the next frame, so as to generate the next first data frame to be transmitted, wait for a period of time, and return to step S707;
step S713, judging 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 its Byte0 field, and if the frame number is 1, it is indicated as a second aligned frame, and if the frame number is not 1, it is indicated as not being a second aligned frame.
Step S714, where Byte6 is assigned to 0x02, byte3 is assigned to the last frame number, and bytes 4-5 are assigned to the length value of the last frame, so as to generate a next first data frame to be transmitted, wait for a period of time, and continue step S707;
Step S715, where Byte6 is assigned to 0x01, byte3 is assigned to the last frame number, and Bytes 4-5 are assigned to the length value of the last frame, so as to generate the next first data frame to be sent, wait for a period of time, and continue step S707;
step S716, byte6 is assigned to 0x0, byte3 is assigned to the last frame number, and Byte 4-5 are assigned to the length value of the last frame, so as to generate the next first data frame to be transmitted, wait for a period of time, and continue step S707;
step S717, the SoC reports the SPI communication error to an upper control module (e.g., AI chip in the vehicle body system);
alternatively, the SoC may also handle the SPI communication error itself.
Step S718, the current SPI communication is ended.
Fig. 8 shows an SPI communication procedure at the opposite device side, which may include the steps of:
step S801, start;
step S802, receiving a first alignment frame for frame alignment and transmitting a second alignment frame;
step S803, judging whether the data in the first alignment frame is correct, if yes, continuing step S804, otherwise, returning to step S802;
step S804, analyzing Byte 3-5 in the first aligned frame, and preparing data in the second data frame to be transmitted according to the frame number and the frame length indicated by the Byte 3-5;
Step S805, under the control of the clock initiated by the current device, receiving a first data frame from the SoC, and simultaneously sending a second data frame to the SoC, wherein the second data frame contains the data prepared in step S804;
step S806, judging 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, byte6 is assigned 0x0, byte3 is assigned 0, and bytes 4 to 5 are assigned 0 to generate a next second data frame to be transmitted, wait for a period of time, and continue with step S805;
step S808, judging whether the first data frame from the SoC is a first alignment frame, namely whether the value of Byte0 in the first data frame is 1, returning to step S802 if yes, otherwise continuing to step S809;
step S809, the Byte6 is assigned to 0x10, the Byte3 is assigned to the last frame number, and the bytes 4-5 are assigned to the data length of the last frame, so as to generate the next second data frame to be transmitted, wait for a period of time, and continue with 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 procedure in the second embodiment is the same as that in the first embodiment, except that the current device in the second embodiment corresponds to the "peer device" in the first embodiment, the "first alignment frame" corresponds to the "second alignment frame" in the first embodiment, the "first data frame" corresponds to the "second data frame" in the first exemplary scheme, and the "peer device" in the second embodiment corresponds to the "current device" in the first embodiment, the "second alignment frame" corresponds to the "first alignment frame" in the first embodiment, the "second data frame" corresponds to the "first data frame" in the first exemplary scheme, and the specific procedure is not repeated.
In this embodiment, the second data frame may carry one or any combination of the following information: the method comprises the steps of a current frame number, a current frame data length, a next frame number, a next frame data length, a state mark for indicating the state of the current equipment, current frame transmission control data and/or frame data and a check code for verifying whether the data are correct or not.
In this embodiment, the second alignment frame may carry one or any combination of the following information: the method comprises the steps of taking a current frame number with a preset frame number as a value, taking the next frame data length as a value, taking a state mark for indicating the state of the current equipment as a value, taking the current frame transmission control data and/or frame data as a value, and taking the check code for verifying whether the data are correct or not as a value.
In this embodiment, the first data frame may carry one or any combination of the following information: the method comprises the steps of a current frame number, a 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 are correct or not.
In this embodiment, the first alignment frame may carry one or any combination of the following information: the method comprises the steps of taking a current frame number with a preset frame number as a value, a current frame data length, a state mark for indicating the state of opposite terminal equipment, data corresponding to the current frame number and a check code for verifying whether the data are 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 opposite device under the trigger of the clock signal initiated by the opposite device (that is, "current device" in the first embodiment, the above "master device").
In this embodiment, when the status flag in the second data frame from the peer device is the third value described above, the data in the first alignment frame, that is, the data required for preparing the first alignment frame, is determined so as to transmit the first alignment frame to the peer device under the trigger of the clock signal initiated by the peer device (i.e., "current device" in the first embodiment, the above "master device").
In this embodiment, when the second data frame from the peer device includes the next frame number and the status flag in the second data frame is a predetermined first value, determining data corresponding to the next frame number, that is, preparing data corresponding to the next frame number, and generating the first data frame with the current frame number being the next frame number, so as to send the first data frame to the peer device under the triggering of the clock signal initiated by the peer device.
In this embodiment, when the second data frame from the peer device includes the last frame number and the status flag in the second data frame is a predetermined second value (for example, byte 6=0x01 above), determining the data corresponding to the last frame number, that is, preparing the data corresponding to the last frame number, generating the first data frame with the current frame number being the last frame number, 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, it is verified whether the data in the second data frame is correct; 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). 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 alignment frame, the data corresponding to the next frame number is determined (i.e., the data corresponding to the next frame number is prepared or collected) while the current frame number is carried in the next first data frame, and the status flag in the next first data frame is set to a predetermined fourth value (e.g., byte 6=0x10 above) which may be used to indicate that the current device receives data abnormally.
The method of the embodiment of the application can achieve the following technical effects: 1. the full duplex communication of the SPI is realized, compared with the prior SPI half duplex scheme, the waiting time of the SoC and the MCU is saved, and the efficiency is improved; 2. the hardware IO port is saved, so that the unnecessary IO port interrupt trigger is reduced by the SoC; 3. the adjustable data number is transmitted, and the utilization rate of the SPI bus is optimized; 4. and the transmission standard is unified, so that the subsequent development of SoC and MCU on SPI bus protocol is facilitated.
Exemplary apparatus
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 the peer device for frame alignment; and receiving a second data frame from the peer device;
a transmitting unit 92 configured to transmit a first alignment frame to a counterpart device for the frame alignment while the receiving unit receives the second alignment frame; and transmitting a first data frame to the peer device while the receiving unit receives the second data frame;
and a parsing unit 93 configured to parse the second data frame.
The first embodiment described below can be implemented when the device to which the SPI-based communication apparatus shown in fig. 9 belongs is a master device, and the second embodiment described below can be implemented when the device to which the SPI-based communication apparatus shown in fig. 9 belongs is a slave device.
First embodiment
The first data frame may carry one or any combination of the following information: the method comprises the steps of a current frame number, a current frame data length, a next frame number, a next frame data length, 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 are correct or not; and/or the number of the groups of groups,
The first alignment frame may carry one or any combination of the following information: the method comprises the steps of taking a current frame number which is a preset frame number, a next frame number, a data length of a next frame, a state mark for indicating the state of current equipment, transmission control data and/or frame data of the current frame, and a check code for verifying whether the data are correct or not; and/or the number of the groups of groups,
the second data frame may carry one or any combination of the following information: the method comprises the steps of a current frame number, a current frame data length, a state mark for indicating the state of opposite terminal equipment, data corresponding to the current frame number and a check code for verifying whether the data are correct or not; and/or the number of the groups of groups,
the second alignment frame may carry one or any combination of the following information: the method comprises the steps of taking a current frame number with a preset frame number as a value, a current frame data length, a state mark for indicating the state of opposite terminal equipment, data corresponding to the current frame number and a check code for verifying whether the data are correct or not.
In some examples, the SPI-based communication device described above may further include: and 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 determination unit may be specifically configured to determine whether frame alignment is successful by one or both of: verifying whether the data in the second aligned frame is correct; and judging whether the current frame number in the first aligned frame is consistent with the current frame number in the second aligned frame.
In some examples, the frame alignment unit may be further configured to determine whether the state of the peer device is normal according to the state flag in the second aligned 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 resume frame alignment after the current device is abnormally restarted.
In some examples, the SPI-based communication device described above may further include: and a data frame determination unit configured to verify whether the target data, which is obtained by parsing the second data frame by the parsing unit 93 and corresponds to the current frame number in the first data frame, is received successfully.
In some examples, the SPI-based communication device described above may further include: and a frame generation unit. The data frame determining unit may be further configured to determine, when the target data is received successfully, whether the current state of the peer device is normal according to the state flag in the second data frame, and notify the frame generating unit when the state of the peer device is determined to be normal; and a frame generation unit configured to perform an operation of one of the following when the data frame determination unit determines that the current state of the opposite terminal 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 a next frame number of the next frame number in the current first data frame, and simultaneously setting a state flag in the next first data frame as a preset first value, wherein the first value represents that the current equipment is normal; 2) And assigning the current frame number in the next first data frame as the last frame number carried in the second data frame, and setting a state flag in the next first data frame as the first value.
In some examples, the data frame determining unit is configured to verify whether the target data is received successfully, and may include: judging whether the current frame number in the second data frame is consistent with the current frame number in the first data frame; and verifying whether the data in the second data frame is correct; 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 correct, the target data is successfully received; the target data reception fails when the second data frame coincides with the current frame number in the first data frame and the data in the second data frame is erroneous.
In some examples, the above data frame determining unit may be further configured to notify the frame generating unit when it is determined that the target data reception fails, and the frame generating unit may be further configured to assign, when the target data reception fails, a next frame number in a next first data frame to a current frame number in a current first data frame, while setting 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 receiving data abnormally.
In some examples, the above-mentioned data frame determination unit may be further configured to, when 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 that the next first data frame is the first alignment frame when the notification of the data frame determination unit indicates that the current frame number in the second data frame is equal to the predetermined frame number; and, in the notification of the data frame determination unit, indicating 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 to the predetermined frame number, and simultaneously assigning the status flag in the next first data frame to a predetermined third value, where the third value is used to indicate that the instruction issued by the current device is inconsistent with the received data.
Second embodiment
The second data frame may carry one or any combination of the following information: the method comprises the steps of a current frame number, a current frame data length, a next frame number, a next frame data length, 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 are correct or not; and/or the number of the groups of groups,
the second alignment frame may carry one or any combination of the following information: the method comprises the steps of taking a current frame number which is a preset frame number, a next frame number, a data length of a next frame, a state mark for indicating the state of current equipment, transmission control data and/or frame data of the current frame, and a check code for verifying whether the data are correct or not; and/or the number of the groups of groups,
the first data frame may carry one or any combination of the following information: the method comprises the steps of a current frame number, a current frame data length, a state mark for indicating the state of opposite terminal equipment, data corresponding to the current frame number and a check code for verifying whether the data are correct or not; and/or the number of the groups of groups,
the first alignment frame may carry one or any combination of the following information: the method comprises the steps of taking a current frame number with a preset frame number as a value, a current frame data length, a state mark for indicating the state of opposite terminal equipment, data corresponding to the current frame number and a check code for verifying whether the data are correct or not.
In some examples, the frame generation unit described above 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) Determining data in the first alignment frame when the state flag in the second data frame is a preset third value, wherein the third value is used for indicating that an instruction sent by the opposite terminal equipment is inconsistent with the received data; 3) When the second data frame comprises a next frame number and the state mark 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 a last frame number and the state mark in the second data frame is a preset second value, determining the data corresponding to the last frame number.
In some examples, the above-mentioned 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, and notifying the frame generating unit; the frame generating unit may be further configured to determine the data in the first aligned frame when the data in the second data frame is erroneous and the 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 alignment frame, determining the data corresponding to the next frame number, carrying the current frame number in the next first data frame, and setting a state mark in the next first data frame to be a preset fourth value, wherein the fourth value can be used for indicating that the current equipment receives data abnormally.
It should be noted that, in the embodiments of the present application, the SPI-based communication device 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 present 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 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) and/or cache memory (cache), and the like. The non-volatile memory may include, for example, read Only Memory (ROM), hard disk, flash memory, and the like. One or more computer program instructions may be stored on the computer readable storage medium that can be executed by the processor 101 to implement the method of determining object orientation and/or other desired functions of the various embodiments of the present 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 forms of connection mechanisms (not shown). The input device 133 may be, for example, a microphone or an array of microphones. In addition, 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 device 134 may include, for example, a display, speakers, a printer, and a communication network and remote output devices connected thereto, etc.
Of course, only some of the components of the electronic device 10 that are relevant to the present application are shown in fig. 10 for simplicity, components such as buses, input/output interfaces, etc. 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 methods and apparatus described above, embodiments of the present application may also be a computer program product comprising computer program instructions which, 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 described in the "exemplary method" section of the present specification.
The computer program product may write 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, 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, which 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 described in the above "exemplary method" section of the present specification.
The computer readable storage medium may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may include, for example, but is 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 would include the following: an electrical connection having one or more wires, a portable disk, a hard disk, random Access Memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The basic principles of the present application have been described above in connection with specific embodiments, however, it should be noted that the advantages, benefits, effects, etc. mentioned in the present application are merely examples and not limiting, and these advantages, benefits, effects, etc. are not to be considered as necessarily possessed by the various embodiments of the present application. Furthermore, the specific details disclosed herein are for purposes of illustration and understanding only, and are not intended to be limiting, as the application is not intended to be limited to the details disclosed herein as such.
The block diagrams of the devices, apparatuses, devices, systems referred to in this application are only illustrative examples and are not intended to require or imply that the connections, arrangements, configurations must be made in the manner shown in the block diagrams. As will be appreciated by one of skill in the art, the devices, apparatuses, devices, systems may be connected, arranged, configured in any manner. Words such as "including," "comprising," "having," and the like are words of openness and mean "including but not limited to," and are used interchangeably therewith. The terms "or" and "as used herein refer to and are used interchangeably with the term" and/or "unless the context clearly indicates otherwise. The term "such as" as used herein refers to, and is used interchangeably with, the phrase "such as, but not limited to.
It is also noted that in the apparatus, devices and methods of the present application, the components or steps may be disassembled and/or assembled. Such decomposition and/or recombination should be considered as equivalent to 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, this description is not intended to limit the embodiments of the application to the form disclosed herein. Although a number of example aspects and embodiments have been discussed above, a person of ordinary skill in the art will recognize certain variations, modifications, alterations, additions, and subcombinations thereof.

Claims (9)

1. A method of communication based on a serial peripheral interface, comprising:
transmitting a first alignment frame to opposite terminal equipment, and simultaneously receiving a second alignment frame from the opposite terminal equipment so as to perform frame alignment;
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 at the same time, so that an interrupt task is not required to be processed;
the second frame of data is parsed and,
wherein before sending the first data frame to the peer device, the communication method further includes: determining whether the frame alignment is successful so as to begin transmission of the first data frame and the second data frame when the frame alignment is successful.
2. The method of claim 1, wherein,
the first data frame carries at least one of the following information: the method comprises the steps of a current frame number, a current frame data length, a next frame number, a next frame data length, 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 are correct or not; and/or the number of the groups of groups,
the first alignment frame carries at least one of the following information: the method comprises the steps of taking a current frame number which is a preset frame number, a next frame number, a data length of a next frame, a state mark for indicating the state of current equipment, transmission control data and/or frame data of the current frame, and a check code for verifying whether the data are correct or not; and/or the number of the groups of groups,
The second data frame carries at least one of the following information: the method comprises the steps of a current frame number, a current frame data length, a state mark for indicating the state of opposite terminal equipment, data corresponding to the current frame number and a check code for verifying whether the data are correct or not; and/or the number of the groups of groups,
the second alignment frame carries at least one of the following information: the method comprises the steps of taking a current frame number with a preset frame number as a value, a current frame data length, a state mark for indicating the state of opposite terminal equipment, data corresponding to the current frame number and a check code for verifying whether the data are correct or not.
3. The method of claim 1, further comprising: and judging whether the state of the opposite terminal equipment is normal 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.
4. The method of claim 1 or 2, further comprising: and after the current equipment is restarted, sending a first alignment frame to the opposite-end equipment to perform frame alignment again.
5. The method of claim 1, further comprising, after parsing the second data frame: and verifying whether target data is successfully received or not, wherein the target data is obtained by analyzing the second data frame and corresponds to the current frame number in the first data frame.
6. The method of claim 1, wherein,
the second data frame carries at least one of the following information: the method comprises the steps of a current frame number, a current frame data length, a next frame number, a next frame data length, 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 are correct or not; and/or the number of the groups of groups,
the second alignment frame carries at least one of the following information: the method comprises the steps of taking a current frame number which is a preset frame number, a next frame number, a data length of a next frame, a state mark for indicating the state of current equipment, transmission control data and/or frame data of the current frame, and a check code for verifying whether the data are correct or not; and/or the number of the groups of groups,
the first data frame carries at least one of the following information: the method comprises the steps of a current frame number, a current frame data length, a state mark for indicating the state of opposite terminal equipment, data corresponding to the current frame number and a check code for verifying whether the data are correct or not; and/or the number of the groups of groups,
the first alignment frame carries at least one of the following information: the method comprises the steps of taking a current frame number with a preset frame number as a value, a current frame data length, a state mark for indicating the state of opposite terminal equipment, data corresponding to the current frame number and a check code for verifying whether the data are correct or not.
7. A serial peripheral interface based communication device, comprising:
a receiving unit configured to receive a second alignment frame from the peer device for frame alignment; and receiving a second data frame from the peer device;
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 transmitting a first data frame to the opposite terminal device while the receiving unit receives the second data frame without processing an interrupt task;
a parsing unit configured to parse the second data frame,
wherein the communication apparatus further includes a frame alignment determination unit configured to determine whether frame alignment is successful, and when frame alignment is successful, transmission of the first data frame and the second data frame is started by the transmission unit.
8. An electronic device, comprising:
one or more processors; and
a 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 6.
9. A computer readable storage medium having stored thereon a computer program which, when executed by a processor, causes the processor to perform the method of any of claims 1 to 6.
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 CN112822002A (en) 2021-05-18
CN112822002B true 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)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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

Citations (3)

* 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
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

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101119224B (en) * 2006-08-01 2010-08-18 上海未来宽带技术及应用工程研究中心有限公司 ATCA frame based FRU debugging and testing device
CN102819512B (en) * 2012-06-28 2015-11-18 惠州市德赛西威汽车电子股份有限公司 A kind of full-duplex communication device based on SPI and method thereof
CN110463135B (en) * 2017-03-31 2021-09-14 华为技术有限公司 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)
CN107562666B (en) * 2017-09-26 2020-10-23 威创集团股份有限公司 Method, system and related device for communication between devices based on SPI bus
CN109902053B (en) * 2017-12-07 2022-07-05 厦门雅迅网络股份有限公司 SPI communication method based on double controllers, terminal equipment and storage medium
CN110311875B (en) * 2018-03-20 2022-10-18 华为技术有限公司 Data transmission method and device
CN109787703B (en) * 2019-02-28 2020-08-25 烽火通信科技股份有限公司 Timestamp correction method, clock synchronization method and system
CN110334046A (en) * 2019-07-11 2019-10-15 南方电网科学研究院有限责任公司 A kind of communication means, the apparatus and system of SPI full duplex
CN111130710B (en) * 2019-12-10 2022-03-08 常州新途软件有限公司 SPI-based duplex communication method

Patent Citations (3)

* 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
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

Also Published As

Publication number Publication date
CN112822002A (en) 2021-05-18

Similar Documents

Publication Publication Date Title
CN112822002B (en) SPI-based communication method and device, electronic equipment and storage medium
WO2011137640A1 (en) File transmission method, file transmission apparatus and file reception apparatus
CN109450912B (en) Data transmission method, device and equipment
CN112817886B (en) Master-slave communication method and device based on SPI
CN112423321B (en) Upgrading method and device based on wireless broadcast and electronic equipment
CN115632900B (en) Computing equipment
US7783964B2 (en) Redundant 3-wire communication system and method
CN115687226A (en) I2c bus communication method, device and readable storage medium
JP2009244991A (en) Data communication method, data communication system, electronic control unit, and circuit board
US8108736B2 (en) Multi-partition computer system, failure handling method and program therefor
CN116578521B (en) Single-bus communication method, device, system and equipment
CN116204214A (en) BMC upgrading method, device and system, electronic equipment and storage medium
US9621339B1 (en) Host devices and data transmission methods
CN113992740B (en) Middleware based on autonomous control and data transmission method
US20180191562A1 (en) Parameter setting method for system bus and device thereof
CN112511636B (en) Data transmission system, method, device, computer equipment and storage medium
CN113556210A (en) Upper computer and method for establishing communication connection
CN108075860B (en) Method and device for data transmission with a hearing device
CN112363962A (en) Data communication method, system, electronic device and computer storage medium
CN106708759B (en) Method for controlling digital input/output interface and processor
CN114817100B (en) Data reading method and device for single board
CN113965308A (en) Connection communication method, slave device and device control system
CN115454731A (en) Device and method for building test file
CN113301130A (en) Communication method and device of sewing equipment controller, terminal equipment and storage medium
CN118337877A (en) Data processing method, device, electronic equipment and computer readable storage medium

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