Data transmission method, communication device, system, electronic apparatus and storage medium

By providing clock pulses to the slave device in the SPI communication system, the problem that the slave device cannot independently send and receive data is solved, and independent data transmission of the slave device in the SPI communication system is realized.

CN116366223BActive Publication Date: 2026-07-03SUNNY OPTICAL ZHEJIANG RES INST CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SUNNY OPTICAL ZHEJIANG RES INST CO LTD
Filing Date
2021-12-28
Publication Date
2026-07-03

Smart Images

  • Figure CN116366223B_ABST
    Figure CN116366223B_ABST
Patent Text Reader

Abstract

This application relates to a data transmission method, communication device, system, electronic device, and storage medium. The data transmission method includes: during data transmission, sending a data frame located at the top of the transmission frame buffer from the data to be transmitted to a preset receiving device, and shifting the already transmitted data frame to the bottom of the transmission frame buffer; wherein, when the data to be transmitted is empty and the communication device is a master device using the SPI communication protocol, generating an empty data frame and sending it to the preset receiving device, and shifting the empty data frame to the bottom of the transmission frame buffer. This enables the slave device to independently transmit and receive data in a communication system based on the SPI communication protocol by providing a clock when the master device has empty data to be transmitted, allowing the slave device to transmit and receive data based on clock pulses.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data transmission, and in particular to data transmission methods, communication equipment, systems, electronic devices, and storage media. Background Technology

[0002] The SPI communication protocol, employing a master-slave mechanism, can be applied to communication systems with one master and multiple slaves. In this system, the master can determine communication with slave devices via a chip select line. SPI timing is controlled by the master; full-duplex SPI transmit and receive share the same clock line, and the master controls the pausing and resuming of timing. Therefore, in current master-slave communication systems based on the SPI protocol, when the master sends data to the slave, the slave needs to enter receive mode beforehand. Furthermore, when the slave sends data to the master, it needs to wait for the master to read it; thus, the slave cannot independently transmit and receive data.

[0003] There is currently no effective solution to the problem that the slave device cannot independently send and receive data in related technologies. Summary of the Invention

[0004] This embodiment provides a data transmission method, communication device, system, electronic device, and storage medium to solve the problem in related technologies where the slave device cannot independently send and receive data.

[0005] In a first aspect, this embodiment provides a data transmission method for a communication device, the communication device including a transmission module based on the SPI communication protocol and operating in full-duplex mode, the transmission module including a transmit frame buffer with adjustable length, the method including:

[0006] During data transmission, the data frame at the top of the transmission frame buffer is sent to a preset receiving device, and the sent data frame is shifted to the bottom of the transmission frame buffer; wherein, when the data to be transmitted is empty and the communication device is the host of the SPI communication protocol, an empty data frame is generated and sent to the preset receiving device, and the empty data frame is shifted to the bottom of the transmission frame buffer.

[0007] In some embodiments, the method further includes:

[0008] During the data transmission process, when the data to be transmitted is empty and the communication device is a slave device of the SPI communication protocol, an empty transmission data frame is generated and the empty transmission data frame is shifted to the bottom of the transmission frame buffer.

[0009] In some embodiments, during the operation of the communication device, the transmission module remains in a data receiving state, and the method further includes:

[0010] During the data reception process, the received data frames are checked for their frame format, and the received data frames that pass the frame format check are determined to be valid frames.

[0011] If the valid frame is an acknowledgment frame, determine whether there is a corresponding data frame in the transmission frame buffer. If there is, remove the corresponding data frame from the transmission frame buffer.

[0012] In some embodiments, the transmission module further includes a receive frame buffer and an application programming interface, and the method further includes:

[0013] During the data reception process, if the valid frame is a non-acknowledgment frame, it is determined whether the received frame buffer contains a received data frame that is consistent with the non-acknowledgment frame.

[0014] If the receive buffer does not contain a receive data frame that matches the non-acknowledgment frame, then the data field of the non-acknowledgment frame is transmitted to the application interface.

[0015] In some embodiments, the method further includes:

[0016] During the data reception process, the received non-acknowledgment frames are processed into FIFO format and stored in the receive frame buffer, and the received data frames that overflow from the receive frame buffer are removed.

[0017] In some embodiments, the method further includes:

[0018] Set the transmitted data frame that has been shifted by a preset number of bits in the transmitted frame buffer as a retransmitted data frame, and retransmit the retransmitted data frame based on the transmitted frame buffer.

[0019] In some embodiments, the transmission module further includes an acknowledgment frame buffer, and the method further includes:

[0020] During the data transmission process, if there is data to be responded to in the response frame buffer, the data to be responded to in the response frame buffer and the data to be sent in the transmission frame buffer are sent to a preset receiving device in turn according to a preset rule.

[0021] Secondly, this embodiment provides a communication device for performing the data transmission method described in the first aspect.

[0022] Thirdly, this embodiment provides a communication system, including a master device and a slave device; wherein the master device and the slave device are connected for communication based on the SPI communication protocol;

[0023] Both the master device and the slave device are the communication devices described in the second aspect above.

[0024] Fourthly, this embodiment provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the data transmission method described in the first aspect above.

[0025] Fifthly, this embodiment provides a storage medium on which a computer program is stored, which, when executed by a processor, implements the data transmission method described in the first aspect above.

[0026] Compared with related technologies, the data transmission method, communication device, system, electronic device, and storage medium provided in this embodiment, during the data transmission process, send the data frame located at the top of the transmission frame buffer to a preset receiving device, and shift the already sent data frame to the bottom of the transmission frame buffer; wherein, when the data to be transmitted is empty and the communication device is a master device using the SPI communication protocol, an empty data frame is generated and sent to the preset receiving device, and the empty data frame is shifted to the bottom of the transmission frame buffer. This enables the slave device to independently send and receive data in a communication system based on the SPI communication protocol by providing a clock when the master device has empty data to be transmitted, allowing the slave device to send and receive data based on clock pulses.

[0027] Details of one or more embodiments of this application are set forth in the following drawings and description to make other features, objects and advantages of this application more readily apparent. Attached Figure Description

[0028] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:

[0029] Figure 1 This is a hardware structure block diagram of the terminal for the data transmission method of this embodiment;

[0030] Figure 2 This is a flowchart of the data transmission method in this embodiment;

[0031] Figure 3 This is a schematic diagram of the transmission module in this embodiment;

[0032] Figure 4 This is a schematic diagram of the data transmission frame format in this embodiment;

[0033] Figure 5 This is a flowchart of the data transmission method according to a preferred embodiment;

[0034] Figure 6 This is a flowchart of the data receiving method according to a preferred embodiment;

[0035] Figure 7 This is a schematic diagram of the communication system in this embodiment. Detailed Implementation

[0036] To better understand the purpose, technical solution, and advantages of this application, the application is described and illustrated below in conjunction with the accompanying drawings and embodiments.

[0037] Unless otherwise defined, the technical or scientific terms used in this application shall have the general meaning as understood by one of ordinary skill in the art to which this application pertains. Words such as “a,” “an,” “an,” “the,” “the,” and “these,” used in this application, do not indicate quantitative limitation and may be singular or plural. The terms “comprising,” “including,” “having,” and any variations thereof used in this application are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that comprises a series of steps or modules (units) is not limited to the listed steps or modules (units) but may include steps or modules (units) not listed, or may include other steps or modules (units) inherent to such processes, methods, products, or devices. The terms “connected,” “linked,” and “coupled,” used in this application, are not limited to physical or mechanical connections but may include electrical connections, whether direct or indirect. The term “multiple” used in this application refers to two or more. The "and / or" operator describes the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: A alone, A and B simultaneously, and B alone. Typically, the character " / " indicates that the objects before and after it are in an "or" relationship. The terms "first," "second," and "third," etc., used in this application are merely for distinguishing similar objects and do not represent a specific ordering of the objects.

[0038] The method embodiments provided in this example can be executed on a terminal, computer, or similar computing device. For example, it can run on a terminal. Figure 1 This is a hardware structure block diagram of the terminal for the data transmission method in this embodiment. For example... Figure 1 As shown, a terminal may include one or more ( Figure 1Only one is shown in the diagram. A processor 102 and a memory 104 for storing data are also included. The processor 102 may be, but is not limited to, a microprocessor (MCU) or a programmable logic device (FPGA). The terminal may also include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that… Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the terminal described above. For example, the terminal may also include components that are larger than... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown are illustrated.

[0039] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the data transmission method in this embodiment. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby implementing the aforementioned method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0040] The transmission device 106 is used to receive or send data via a network. This network includes a wireless network provided by the terminal's communication provider. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 can be a Radio Frequency (RF) module used for wireless communication with the Internet.

[0041] This embodiment provides a data transmission method for a communication device. The communication device includes a transmission module based on the SPI communication protocol, operating in full-duplex mode. The transmission module includes a transmit frame buffer with adjustable length. Figure 2 This is a flowchart of the data transmission method in this embodiment, as shown below. Figure 2 As shown, the process includes the following steps:

[0042] Step S210: During the data transmission process, the data frame at the top of the data to be transmitted is sent to a preset receiving device, and the transmitted data frame that has been sent is moved to the bottom of the data frame buffer; wherein, when the data to be transmitted is empty and the communication device is a host of the SPI communication protocol, an empty data frame is generated and sent to the preset receiving device, and the empty data frame is moved to the bottom of the data frame buffer.

[0043] Specifically, the transmission module based on the SPI communication protocol can be a software architecture module based on SPI communication. Figure 3 This is a schematic diagram of the transmission module in this embodiment, as shown below. Figure 3 As shown, the transmission module may specifically include: an application programming interface (API), a transmit message queue, a receive message queue, an acknowledgment frame buffer, a transmit frame buffer, a receive frame buffer, an SPI transmit data register, and an SPI receive data register. Furthermore, the transmit and receive frame buffers can be adjustable in length, allowing for adjustments to their sizes based on the actual application scenario to improve data transmission efficiency. Furthermore, when transmitting data using the above transmission module, the data to be transmitted from the API can be passed to the transmit message queue for waiting. If data exists in the acknowledgment frame buffer, the data in the acknowledgment frame buffer and the data in the transmit frame buffer can be transmitted alternately according to a preset rule; if no data exists in the acknowledgment frame buffer, only the data in the transmit frame buffer can be transmitted. Additionally, if the communication device is an SPI-based master, the transmission module may also include a transmission control unit for switching the communication time slices of each slave device. The acknowledgment frame buffer, transmit frame buffer, and receive frame buffer each contain several frame bits, each capable of holding one frame of data.

[0044] During data transmission, the data frame at the top of the transmit frame buffer can be sent to a preset receiving device. The transmitted data frame is then moved from the top of the transmit frame buffer to the bottom in a circular queue. When the top frame position of the transmit frame buffer is empty, a data frame can be retrieved from the transmit message queue and added to the top frame position of the transmit frame buffer as a transmit data frame, which is then sent to the preset receiving device. Additionally, when the transmission module receives a valid frame, and this valid frame is an acknowledgment frame, it can iterate and compare the acknowledgment frame with the data in the transmit frame buffer. If a transmit data frame corresponding to the acknowledgment frame exists in the transmit frame buffer, it can be removed from the transmit frame buffer, and the corresponding frame position in the transmit frame buffer can be set to empty, awaiting data loading from the transmit message queue. The acknowledgment frame is the corresponding data frame sent by the device based on the received transmit data frame.

[0045] Furthermore, when the data to be sent is empty (i.e., the top frame bit of the transmit frame buffer is empty, and the data waiting to be sent in the transmit message queue is empty), if the communication device is a master based on the SPI communication protocol, it can generate an empty transmit data frame, send it to the slave receiving device, and shift this empty transmit data frame to the bottom of the transmit frame buffer. By sending an empty transmit data frame, a clock can be provided to the slave, ensuring a constant clock pulse on the clock line, thus enabling the slave to freely send data based on the clock pulse, thereby achieving independent data transmission and reception by the slave. When the communication device is a slave based on the SPI communication protocol, the empty transmit data frame can be directly considered as completed and shifted to the bottom of the transmit frame buffer.

[0046] In addition, for a data frame that has moved a preset number of bits in the transmission frame buffer but still has not received a corresponding acknowledgment frame, it can be determined as an acknowledgment timeout, and the data frame can be set as a retransmission frame and retransmitted, thereby improving the stability of data transmission.

[0047] Additionally, the SPI receive data register is always in receive mode. The transmission module performs frame format verification on the received data; data that fails the frame format verification is discarded, while data that passes the verification is considered a valid frame. Furthermore, Figure 4 This is a schematic diagram of the data transmission frame format in this embodiment, as shown below. Figure 4As shown, the transmission frame header field is 16 bits in size, fixed at 0x5555, and is used to indicate the start of a data transmission frame. The frame length field is 12 bits in size, used to indicate the total number of bytes in the transmission frame from the beginning of the transmission frame header field to the end of the checksum field. The acknowledgment field is 1 bit in size, used to indicate whether the transmission frame is an acknowledgment frame. A value of 0 indicates a non-acknowledgment frame; a value of 1 indicates an acknowledgment frame. The reserved field is 3 bits in size, used for protocol extensions. The frame identifier field is used to represent transmission frame identification information, such as the frame ID (Identity document). Each non-acknowledgment frame has a unique frame ID; the frame ID of an acknowledgment frame is the same as the frame ID of the corresponding non-acknowledgment frame. The frame content field is used to represent the message content; this field is not included in acknowledgment frames. The checksum field is the sum of all bytes in the above fields using unsigned integers, used for valid frame verification. Additionally, Figure 4 The “…” in the text represents other fields that can be set according to the application scenario. Further, a valid frame is specifically a data frame whose actual received data content matches the content of each field in the transmitted frame. The specific verification process for a valid frame can be as follows: according to the aforementioned transmitted frame format, determine whether the received data frame contains the transmitted frame header field, whether the frame length matches the length of the received data frame, and whether the check field matches the result calculated from the received data frame. In addition, other valid frame verification rules can be set according to the actual application scenario, which are not limited here. By determining the validity of the received data frame based on frame format verification, communication failures caused by frame misalignment during synchronous transmission can be avoided, thereby improving the accuracy of data transmission.

[0048] Additionally, upon receiving a valid frame that is a non-acknowledgment frame, the acknowledgment frame buffer can be traversed to determine if a corresponding acknowledgment frame already exists. If not, a corresponding acknowledgment frame can be generated and placed in the acknowledgment frame buffer for transmission. The non-acknowledgment frame can then be compared with the data in the receive frame buffer to determine if it is a retransmission frame. If it is not a retransmission frame, its data field can be passed to the receive message queue, allowing the application interface to read data from it. If it is a retransmission frame, it will not be sent to the receive message queue, thus maintaining the uniqueness of data in the receive message queue. Furthermore, upon receiving a non-acknowledgment frame, it can be placed in the receive frame buffer, and any data frames overflowing from the receive frame buffer can be directly removed. Further, to improve the accuracy of retransmission message verification during data transmission, the capacity of the receive frame buffer should be larger than the capacity of the send frame buffer.

[0049] Through the above steps, during data transmission, the data frame at the top of the transmission frame buffer is sent to the preset receiving device, and the already sent data frame is shifted to the bottom of the transmission frame buffer. Specifically, when the data to be transmitted is empty and the communication device is a master device using the SPI communication protocol, an empty data frame is generated and sent to the preset receiving device, and the empty data frame is shifted to the bottom of the transmission frame buffer. This enables the master device to provide a clock signal to the slave device when the data to be transmitted is empty, allowing the slave device to send and receive data based on clock pulses, thus realizing independent data transmission and reception by the slave device in an SPI-based communication system.

[0050] In one embodiment, the above data transmission method further includes the following steps:

[0051] Step S211: During the data transmission process, when the data to be transmitted is empty and the communication device is a slave device of the SPI communication protocol, an empty transmission data frame is generated and the empty transmission data frame is shifted to the bottom of the transmission frame buffer.

[0052] In one embodiment, during the operation of the communication device, the transmission module remains in an enabled data receiving state, and the above data transmission method further includes the following steps:

[0053] Step S220: During data reception, the received data frames undergo frame format verification, and the received data frames that pass the frame format verification are determined to be valid frames. Specifically, the transmission module can be configured by setting a control register to ensure that it is always in data reception mode during the operation of the communication device. This allows the interrupt routine of the transmission module to be triggered when the clock pulse arrives on the clock line, thus enabling data reception. In other words, the transmission module in this embodiment can continuously receive data and perform frame format verification on all received data, determining the data that passes the verification as valid frames and discarding the data that fails the verification.

[0054] Step S230: If the valid frame is an acknowledgment frame, determine whether there is a corresponding data frame in the sending frame buffer. If there is, remove the corresponding data frame from the sending frame buffer.

[0055] Steps S220 to S230 above perform frame format verification on the received data frames, thereby avoiding communication failures caused by misalignment of transmission frames during synchronous transmission and improving the accuracy of data transmission.

[0056] In one embodiment, the transmission module further includes a receive frame buffer and an application programming interface (API), and the above data transmission method further includes the following steps:

[0057] Step S240: During the data reception process, if the valid frame is a non-acknowledgment frame, determine whether the received frame buffer contains a received data frame that is consistent with the non-acknowledgment frame.

[0058] Step S250: If the receive buffer does not contain a receive data frame that matches the non-acknowledgment frame, then the data field of the non-acknowledgment frame is transmitted to the application interface.

[0059] In another embodiment, the above data transmission method further includes the following steps:

[0060] Step S260: During the data reception process, the received non-acknowledgment frames are processed into FIFO format and stored in the receive frame buffer, and the received data frames that overflow from the receive frame buffer are removed.

[0061] In another embodiment, the above data transmission method may further include the following steps:

[0062] Step S270: Set the transmitted data frame that has been shifted by a preset number of bits in the transmission frame buffer as a retransmission data frame, and retransmit the retransmission data frame based on the transmission frame buffer.

[0063] Specifically, if the transmission module has not received a corresponding acknowledgment frame after the transmitted data frame has shifted a preset number of bits in the transmission frame buffer, it can be determined that the acknowledgment for the transmitted data frame has timed out, and thus the transmitted data frame can be retransmitted. Specifically, the preset number of bits can be the capacity of the transmission frame buffer, i.e., the length of the transmission frame buffer. For example, if the capacity of the transmission frame buffer is N frame bits, after the transmitted data frame is completed, by cyclically shifting N bits from the bottom to the top of the transmission frame buffer, it can be considered that the transmitted data frame has shifted one full position. If the transmission module still has not received a corresponding acknowledgment frame after the transmitted data frame has shifted one full position, it can be determined that the acknowledgment for the transmitted data frame has timed out, and the transmitted data frame is designated as a retransmission frame, thereby improving the accuracy and stability of data transmission.

[0064] In one embodiment, the transmission module further includes an acknowledgment frame buffer, and the above data transmission method may further include the following steps:

[0065] During data transmission, if there is data to be acknowledged in the acknowledgment frame buffer, the data to be acknowledged in the acknowledgment frame buffer and the data to be sent in the transmission frame buffer are sent alternately to the preset receiving device according to preset rules.

[0066] The present embodiment will now be described and illustrated through preferred embodiments.

[0067] Figure 5This is a flowchart of a data transmission method according to a preferred embodiment of the present data transmission method, which is used in a communication device, such as... Figure 5 As shown, the data transmission method includes the following steps:

[0068] Step S510: Data is sent from the application programming interface. The data to be sent is loaded into the message queue and waits to be sent.

[0069] Step S520: When there is data in the acknowledgment frame buffer, the data in the acknowledgment frame buffer and the data in the sending frame buffer are sent alternately; when there is no data in the acknowledgment frame buffer, only the data in the sending frame buffer is sent; wherein, the data in the acknowledgment frame buffer is sent in FIFO form, and the data frames that have been sent are removed from the acknowledgment frame buffer.

[0070] Step S530: The data frame located at the top of the sending frame buffer is sent, and after the sending is completed, the data frame is placed at the bottom of the sending frame buffer in the form of a circular queue.

[0071] Step S540: When the frame bit at the top of the sending frame buffer is empty, a frame of data to be sent is obtained from the sending message queue, its frame format is filled, and then loaded into the top frame bit of the sending frame buffer.

[0072] In step S550, if the frame bit at the top of the sending frame buffer is empty and the data in the sending message queue is empty, if the communication device is a slave, the empty data frame at the top of the sending frame buffer is directly shifted to the bottom of the sending frame buffer; if the communication device is a master, the empty data frame is sent to the preset receiving device and the empty data frame is shifted to the bottom of the sending frame buffer.

[0073] In step S560, if the transmission module has not yet received a corresponding acknowledgment frame for a data frame that has been shifted by one week, the data frame is retransmitted.

[0074] Figure 6 This is a flowchart of a data receiving method according to a preferred embodiment of the present data receiving method, which is used in a communication device, such as... Figure 6 As shown, the data receiving method includes the following steps:

[0075] Step S610: Perform frame format verification on the received data frames, discard the data that fails the frame format verification, and determine the data that passes the frame format verification as valid frames;

[0076] Step S620: If a valid frame is received, and the valid frame is an acknowledgment frame, then determine whether there is a corresponding data frame in the sending frame buffer. If there is, remove the corresponding data frame from the sending frame buffer.

[0077] Step S630: If the valid frame is a non-acknowledgment frame, determine whether there is an acknowledgment frame corresponding to the non-acknowledgment frame in the acknowledgment frame buffer. If not, generate an acknowledgment frame corresponding to the non-acknowledgment frame and put it into the acknowledgment frame buffer to wait for transmission.

[0078] Step S640: Determine whether there is a received data frame in the received frame buffer that is the same as the non-acknowledgment frame. If so, the non-acknowledgment frame is identified as a retransmission frame. Otherwise, the non-acknowledgment frame is passed to the received message queue for the application interface to read.

[0079] Step S650: Push non-acknowledgment frames into the receive frame buffer in the form of a FIFO, and remove the overflowing data frames in the receive frame buffer.

[0080] In step S660, the application programming interface receives data from the receive message queue.

[0081] This embodiment provides a communication device for executing the data transmission method provided in the above embodiment.

[0082] Additionally, this embodiment provides a communication system 70. Figure 7 This is a schematic diagram of the structure of the communication system 70, as shown below. Figure 7 As shown, the communication system includes a master device 72 and a slave device 74; wherein the master device 72 and the slave device 74 are connected for communication based on the SPI communication protocol; the master device 72 and the slave device 74 are the communication devices of the above embodiment.

[0083] The aforementioned communication system 70, through a master device 72 and a slave device 74 based on the SPI communication protocol, performs data communication according to the data transmission method of the above embodiment. It can provide a clock to the slave device when the master device has no data to send, so that the slave device can send and receive data based on the clock pulse, thereby realizing the independent sending and receiving of data by the slave device in the communication system based on the SPI communication protocol.

[0084] This embodiment also provides an electronic device including a memory and a processor, the memory storing a computer program and the processor being configured to run the computer program to perform the steps in any of the above method embodiments.

[0085] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.

[0086] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:

[0087] During data transmission, the data frame at the top of the transmission frame buffer is sent to the preset receiving device, and the sent data frame is shifted to the bottom of the transmission frame buffer. In the case where the data to be transmitted is empty and the communication device is a host device using the SPI communication protocol, an empty data frame is generated and sent to the preset receiving device, and the empty data frame is shifted to the bottom of the transmission frame buffer.

[0088] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementations, and will not be repeated in this embodiment.

[0089] Furthermore, in conjunction with the data transmission methods provided in the above embodiments, this embodiment can also provide a storage medium for implementation. The storage medium stores a computer program; when executed by a processor, the computer program implements any of the data transmission methods described in the above embodiments.

[0090] It should be understood that the specific embodiments described herein are merely illustrative of the application and not intended to limit it. All other embodiments derived by those skilled in the art based on the embodiments provided in this application without inventive effort are within the scope of protection of this application.

[0091] Obviously, the accompanying drawings are merely some examples or embodiments of this application. Those skilled in the art can apply this application to other similar situations based on these drawings without any creative effort. Furthermore, it is understood that although the work done in this development process may be complex and lengthy, for those skilled in the art, certain design, manufacturing, or production modifications made based on the technical content disclosed in this application are merely conventional technical means and should not be considered as insufficient disclosure of this application.

[0092] The term "embodiment" in this application refers to a specific feature, structure, or characteristic described in connection with an embodiment that may be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily imply the same embodiment, nor does it imply that it is mutually exclusive with or independent of other embodiments. It will be clearly or implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments without conflict.

[0093] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of patent protection. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the appended claims.

Claims

1. A data transmission method for a communication device, characterized in that, The communication device includes a transmission module based on the SPI communication protocol, operating in full-duplex mode. The transmission module includes an adjustable-length transmit frame buffer and a transmit message queue. The method includes: During data transmission, the data frame at the top of the transmission frame buffer is sent to a preset receiving device, and the already sent data frame is shifted to the bottom of the transmission frame buffer. When the top frame position of the transmission frame buffer is empty, a data frame is retrieved from the transmission message queue and filled into the top frame position of the transmission frame buffer as a transmission data frame. Specifically, when the data to be transmitted is empty and the communication device is the host of the SPI communication protocol, an empty transmission data frame is generated and sent to the preset receiving device, and the empty transmission data frame is shifted to the bottom of the transmission frame buffer. The empty data to be transmitted includes both an empty top frame position of the transmission frame buffer and an empty data queue waiting to be transmitted. The transmitted data frame that has been shifted by a preset number of bits in the transmitted frame buffer is set as a retransmitted data frame, and the retransmitted data frame is retransmitted based on the transmitted frame buffer; the preset number of bits is the capacity of the transmitted frame buffer. Remove the data frame corresponding to the received response frame from the transmit frame buffer.

2. The data transmission method according to claim 1, characterized in that, The method further includes: During the data transmission process, when the data to be transmitted is empty and the communication device is a slave device of the SPI communication protocol, an empty transmission data frame is generated and the empty transmission data frame is shifted to the bottom of the transmission frame buffer.

3. The data transmission method according to claim 1, characterized in that, During the operation of the communication device, the transmission module remains in an enabled data receiving state, and the method further includes: During the data reception process, the received data frames are checked for their frame format, and the received data frames that pass the frame format check are determined to be valid frames. If the valid frame is an acknowledgment frame, determine whether there is a corresponding data frame in the transmission frame buffer. If there is, remove the corresponding data frame from the transmission frame buffer.

4. The data transmission method according to claim 3, characterized in that, The transmission module further includes a receive frame buffer and an application programming interface, and the method further includes: During the data reception process, if the valid frame is a non-acknowledgment frame, it is determined whether the received frame buffer contains a received data frame that is consistent with the non-acknowledgment frame. If the receive frame buffer does not contain a receive data frame that matches the non-acknowledgment frame, then the data field of the non-acknowledgment frame is transmitted to the application interface.

5. The data transmission method according to claim 4, characterized in that, The method further includes: During the data reception process, the received non-acknowledgment frames are processed into FIFO format and stored in the receive frame buffer, and the received data frames that overflow from the receive frame buffer are removed.

6. The data transmission method according to any one of claims 1 to 5, characterized in that, The transmission module further includes a response frame buffer, and the method further includes: During the data transmission process, if there is data to be responded to in the response frame buffer, the data to be responded to in the response frame buffer and the data to be sent in the transmission frame buffer are sent to a preset receiving device in turn according to a preset rule.

7. A communication device, characterized in that, The communication device is used to perform the data transmission method according to any one of claims 1 to 6.

8. A communication system, characterized in that, include: A master device and a slave device; wherein the master device and the slave device are connected for communication based on the SPI communication protocol; Both the master device and the slave device are the communication devices described in claim 7.

9. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the data transmission method according to any one of claims 1 to 6.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the data transmission method according to any one of claims 1 to 6.