CN113079073A - Full-duplex communication device based on SPI and communication method thereof - Google Patents
Full-duplex communication device based on SPI and communication method thereof Download PDFInfo
- Publication number
- CN113079073A CN113079073A CN202010025972.1A CN202010025972A CN113079073A CN 113079073 A CN113079073 A CN 113079073A CN 202010025972 A CN202010025972 A CN 202010025972A CN 113079073 A CN113079073 A CN 113079073A
- Authority
- CN
- China
- Prior art keywords
- data
- warehouse
- length
- slave
- master
- 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.)
- Pending
Links
- 230000006854 communication Effects 0.000 title claims abstract description 91
- 238000004891 communication Methods 0.000 title claims abstract description 90
- 238000000034 method Methods 0.000 title claims abstract description 38
- 230000003993 interaction Effects 0.000 claims abstract description 105
- 238000002360 preparation method Methods 0.000 claims description 111
- 238000012545 processing Methods 0.000 claims description 70
- 230000005540 biological transmission Effects 0.000 claims description 20
- 230000008569 process Effects 0.000 claims description 10
- 239000000284 extract Substances 0.000 claims description 6
- 230000006870 function Effects 0.000 description 11
- 238000013461 design Methods 0.000 description 6
- 230000000903 blocking effect Effects 0.000 description 4
- 238000004364 calculation method Methods 0.000 description 4
- 230000007246 mechanism Effects 0.000 description 3
- 230000008901 benefit Effects 0.000 description 2
- 238000011161 development Methods 0.000 description 2
- 230000002452 interceptive effect Effects 0.000 description 2
- 238000007726 management method Methods 0.000 description 2
- 230000000737 periodic effect Effects 0.000 description 2
- 230000002093 peripheral effect Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 230000002441 reversible effect Effects 0.000 description 1
- 230000001360 synchronised effect Effects 0.000 description 1
- 239000002699 waste material Substances 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L12/40006—Architecture of a communication node
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L12/40169—Flexible bus arrangements
- H04L12/40176—Flexible bus arrangements involving redundancy
- H04L12/40182—Flexible bus arrangements involving redundancy by using a plurality of communication lines
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L5/00—Arrangements affording multiple use of the transmission path
- H04L5/14—Two-way operation using the same type of signal, i.e. duplex
Landscapes
- Engineering & Computer Science (AREA)
- Signal Processing (AREA)
- Computer Networks & Wireless Communication (AREA)
- Communication Control (AREA)
Abstract
The invention discloses a full-duplex communication device based on SPI and a communication method thereof, the communication device comprises a master device, a slave device, a master-slave-in data line, a slave-out-master-in data line, a clock signal line, a chip selection signal line and a slave device state signal line which are connected between the master device and the slave device, wherein the master device and the slave device simultaneously carry out data interaction in a common period through the master-out-slave-in data line and the slave-out-master-in data line respectively, the slave device state signal line is used for transmitting the state whether the slave device can carry out the data interaction to the master device, and the master device and the slave device are respectively provided with a data warehouse for the data interaction. According to the invention, full-duplex communication based on the SPI is realized only by using five pins, and compared with the existing SPI communication scheme, the full-duplex communication system has higher efficiency and better stability; the method can truly realize that the communication efficiency is doubled under the condition of the same bus baud rate.
Description
Technical Field
The invention relates to the technical field of communication, in particular to a full-duplex communication device based on SPI and a communication method thereof.
Background
SPI (Serial Peripheral Interface, Serial Peripheral pin) is a high-speed, full-duplex, synchronous communication bus, and occupies four wires on the pins of the chip: SDI (data in), SDO (data out), SCK (clock), CS (chip select). The SPI operates in a master-slave fashion, which typically has a master device and one or more slave devices. Although the SPI communication defines a full-duplex communication mode, since master and slave devices participating in the SPI communication are not equal, communication can only be initiated by the master device and the slave devices can only participate passively, so that the SPI can only operate in a simplex or half-duplex communication mode in most products, resulting in a waste of a high communication baud rate of the SPI.
Common SPI communication methods are simplex and half-duplex:
there are three ways of simplex mode:
1. only one of two devices participating in communication needs to send data, and the other device only receives data, so that a data sending party is used as an SPI Master device (Master), and a data receiving party is used as an SPI Slave device (Slave);
2. two devices A and B participating in communication need to send and receive data, so the devices A and B are connected by two paths of SPI buses, in the first path of SPI, A is a master device B which is a slave device, A only sends data, and B only receives data; in the second path of SPI, B is that the master device A is the slave device, B only sends data and A only receives data;
3. two devices A and B participating in communication need to send and receive data, the devices A and B are connected by a simplex SPI and a full-duplex bus, the high-speed characteristic of the SPI is utilized to carry out single-item large-data-volume communication, and other full-duplex buses are used to carry out conventional instruction communication.
In the half-duplex mode, a six-wire or eight-wire SPI communication method is designed mainly by adding an additional handshake wire to the SPI. Two devices participating in communication negotiate the SPI right of use by using a handshake line, and the SPI bus is ensured to be used for sending data in turn. However, this communication method has the following problems: (1) the actual half-duplex communication is not full-duplex communication, and two communication parties cannot send data at the same time; (2) each Byte reception triggers interruption and changes the handshake pin state, which causes large consumption of system resources, complex processing logic, poor stability and low actual communication efficiency; (3) two handshake pins are in actual processing, and handshake logic conflicts happen accidentally because of the delay of level jump and software detection processing. If an eight-wire SPI design is adopted, the conflict can be effectively avoided by using four handshake wires, but the complexity of processing logic is improved again, more pin resources are consumed, and the communication efficiency is reduced.
Disclosure of Invention
The technical problem to be solved by the present invention is to provide a full duplex communication device based on SPI and a communication method thereof, which have higher efficiency and better stability.
In order to solve the technical problem, the invention provides an SPI-based full-duplex communication device, which comprises a master device, a slave device, and a master-slave-in data line, a slave-out-master-in data line, a clock signal line, a chip selection signal line and a slave device status signal line connected between the master device and the slave device, wherein the master device and the slave device perform data interaction simultaneously at a common cycle through the master-out-slave-in data line and the slave-out-master-in data line, the slave device status signal line is used for transmitting a status of whether the slave device can perform data interaction to the master device, and the master device and the slave device both have data warehouses for data interaction.
Further, the data warehouse comprises:
a sending data preparation warehouse used for filling in the data frames to be sent and cutting off the data frames or combining a plurality of data frames according to the size relationship between the length of the data frames and the length of the sending data preparation warehouse;
the data sending warehouse is used for storing the cut or combined data frames and sending the data frames to the master outgoing and slave incoming data line or the slave outgoing and master incoming data line when the master device and the slave device carry out data interaction;
a receive data warehouse for receiving data frames from the master-out slave-in data line or the slave-out master-in data line;
and the received data processing warehouse is used for splicing the cut data frames or cutting the combined data frames according to the length of the received data frames.
Further, data frames to be sent are sequentially filled into the sending data preparation warehouse end to end, each data interaction period sends the data frames according to the length of the sending data preparation warehouse, when the total length of the data frames filled in the current period is larger than the length of the sending data preparation warehouse, the filled data frames are cut off according to the length of the sending data preparation warehouse, and the remaining cut-off data frames are filled in the subsequent period.
Further, if the length of a first data frame is greater than that of the sending data preparation warehouse, the first data frame is cut into a plurality of sections according to the length of the sending data preparation warehouse, the first section is filled in a first period, and the remaining sections are sequentially filled in a subsequent period until the last section is filled in;
if the length of the first data frame is less than the length of the sending data preparation warehouse, comparing the length of the next data frame with the remaining length of the sending data preparation warehouse, and if the length of the next data frame is less than or equal to the remaining length of the sending data preparation warehouse, combining the next data frame and the first data frame into a long data frame;
and if the length of the next data frame is greater than the remaining length of the data sending preparation warehouse, finishing the filling of the current period, and waiting for the next period to send the next data frame and the subsequent data frames.
Further, the received data processing warehouse extracts data frames according to the length of the received data frames, and if the length of the received first data frame is greater than that of the received data processing warehouse, splicing and extracting are carried out after all the segments are received; and if the received data frame is the combined data frame, cutting and extracting according to the length of each data frame.
Further, when the period reaches the period of starting data interaction, the function exchange between a sending data preparation warehouse filled in data frames and a sending data warehouse is completed, the sending data preparation warehouse and the sending data warehouse are converted into a sending data warehouse, and data are sent out in the data interaction process; the sending data warehouse is changed into an empty sending data preparation warehouse to fill in a new data frame;
after the data interaction is completed and before the next data interaction begins, the received data processing warehouse which has completed processing the received data frame and the received data warehouse carry out function exchange, convert into an empty received data warehouse and wait for receiving a new data frame in the next data interaction; the receive data warehouse is then transformed into a receive data processing warehouse to continue processing the received data frames.
Further, the period of each data interaction is set according to the time when the master device and the slave device complete two preconditions, wherein the two preconditions are as follows: completing filling and sending data to prepare a warehouse; and finishing the processing of the received data processing warehouse.
Further, the slave status signal line is connected between the flow control pin S _ CTL of the master and the flow control pin S _ CTL of the slave.
The embodiment of the invention also provides a communication method of the full-duplex communication device based on the SPI, the full-duplex communication device based on the SPI comprises a master device, a slave device, a master-out-slave-in data line, a slave-out-master-in data line, a clock signal line, a chip selection signal line and a slave device state signal line, wherein the master device and the slave device are respectively provided with a data warehouse for data interaction, and the communication method comprises the following steps: the master device and the slave device perform data interaction simultaneously in a common period through the master output-slave input data line and the slave output-master input data line respectively, and the slave device transmits the state of whether the slave device can perform data interaction or not to the master device through the slave device state signal line.
Further, the data warehouse comprises:
a sending data preparation warehouse used for filling in the data frames to be sent and cutting off the data frames or combining a plurality of data frames according to the size relationship between the length of the data frames and the length of the sending data preparation warehouse;
the data sending warehouse is used for storing the cut or combined data frames and sending the data frames to the master outgoing and slave incoming data line or the slave outgoing and master incoming data line when the master device and the slave device carry out data interaction;
a receive data warehouse for receiving data frames from the master-out slave-in data line or the slave-out master-in data line;
and the received data processing warehouse is used for splicing the cut data frames or cutting the combined data frames according to the length of the received data frames.
Further, data frames to be sent are sequentially filled into the sending data preparation warehouse end to end, each data interaction period sends the data frames according to the length of the sending data preparation warehouse, when the total length of the data frames filled in the current period is larger than the length of the sending data preparation warehouse, the filled data frames are cut off according to the length of the sending data preparation warehouse, and the remaining cut-off data frames are filled in the subsequent period.
Further, if the length of a first data frame is greater than that of the sending data preparation warehouse, the first data frame is cut into a plurality of sections according to the length of the sending data preparation warehouse, the first section is filled in a first period, and the remaining sections are sequentially filled in a subsequent period until the last section is filled in;
if the length of the first data frame is less than the length of the sending data preparation warehouse, comparing the length of the next data frame with the remaining length of the sending data preparation warehouse, and if the length of the next data frame is less than or equal to the remaining length of the sending data preparation warehouse, combining the next data frame and the first data frame into a long data frame;
and if the length of the next data frame is greater than the remaining length of the data sending preparation warehouse, finishing the filling of the current period, and waiting for the next period to send the next data frame and the subsequent data frames.
Further, the received data processing warehouse extracts data frames according to the length of the received data frames, and if the length of the received first data frame is greater than that of the received data processing warehouse, splicing and extracting are carried out after all the segments are received; and if the received data frame is the combined data frame, cutting and extracting according to the length of each data frame.
Further, when the period reaches the period of starting data interaction, the function exchange between a sending data preparation warehouse filled in data frames and a sending data warehouse is completed, the sending data preparation warehouse and the sending data warehouse are converted into a sending data warehouse, and data are sent out in the data interaction process; the sending data warehouse is changed into an empty sending data preparation warehouse to fill in a new data frame;
after the data interaction is completed and before the next data interaction begins, the received data processing warehouse which has completed processing the received data frame and the received data warehouse carry out function exchange, convert into an empty received data warehouse and wait for receiving a new data frame in the next data interaction; the receive data warehouse is then transformed into a receive data processing warehouse to continue processing the received data frames.
Further, the period of each data interaction is set according to the time when the master device and the slave device complete two preconditions, wherein the two preconditions are as follows: completing filling and sending data to prepare a warehouse; and finishing the processing of the received data processing warehouse.
The embodiment of the invention has the following beneficial effects: the full-duplex communication based on the SPI is realized by only using five pins, and compared with the existing SPI communication scheme, the full-duplex communication based on the SPI has higher efficiency and better stability, occupies less resources for interruption, cache and calculation of a controller of a device, and uses less pin resources; the efficiency of memory operation is improved through a more simplified logic and a more efficient memory management method; the method can truly realize that the communication efficiency is doubled under the condition of the same bus baud rate.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a schematic diagram of an architecture of an SPI-based full-duplex communication device according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments refers to the accompanying drawings, which are included to illustrate specific embodiments in which the invention may be practiced.
Referring to fig. 1, an embodiment of the present invention provides an SPI-based full-duplex communication apparatus, including a master device, a slave device, and a master-slave-in data line, a slave-out-master-in data line, a clock signal line, a chip select signal line, and a slave device status signal line connected between the master device and the slave device, where the master device and the slave device perform data interaction simultaneously at a common cycle through the master-out-slave-in data line and the slave-out-master-in data line, respectively, the slave device status signal line is used to transmit a status of whether the slave device can perform data interaction to the master device, and both the master device and the slave device have data warehouse for data interaction.
Specifically, in this embodiment, the Master-Output-Slave-Input data line is connected between a MOSI (Master Input Slave Output) pin of the Master device and a MOSI pin of the Slave device, and the Slave-Output-Master-Input data line is connected between a MISO (Master Input Slave Output) pin of the Master device and a MISO pin of the Slave device. When the master device and the slave device carry out data interaction, data sent by the master device are input to the slave device through the master-out slave-in data line, and data sent by the slave device are input to the master device through the slave-out master-in data line. The Clock signal line is used for transmitting a Clock Signal (SCLK), the Chip selection signal line is used for transmitting a Chip selection signal (CS), and the Clock signal and the Chip selection signal are both generated and controlled by the master device.
The slave status signal line is controlled by the slave, which uses it to tell the master the status of whether or not it is available for data interaction. The state of whether the slave equipment can carry out data interaction or not transmitted by the slave equipment state signal line comprises enabling and blocking, wherein the slave equipment is indicated to be idle currently through the slave equipment enabling signal, and the data interaction can be carried out at any time; the slave device blocking signal indicates that the slave device is currently busy, and data interaction cannot be performed. As an example, the slave status signal line of the present embodiment is connected between the flow control pin S _ CTL of the master and the flow control pin S _ CTL of the slave. As previously described, the S _ CTL pin has two states, enable and block: if the slave equipment can perform data interaction, the S _ CTL is set to be in an enabling state; otherwise, the system is set to be in a blocking state. The S _ CTL pin can only change state in the non-transmission process, and if the S _ CTL is in the blocking state, the main device cannot initiate transmission, and the transmission is blocked. It is understood that, in addition to the flow control pin S _ CTL, the present embodiment may select other pins connected to the master device and the slave device, and use the signal line between the master device and the slave device as the slave device status signal line.
In this embodiment, full-duplex communication based on the SPI can be realized by the above-described design of the five signal lines (only five pins are used in both the master device and the slave device).
Due to the characteristics of the SPI bus protocol, the SPI communication parties are in master-slave roles, all data interaction must be initiated by the master device, and the slave device can only passively transmit data to the master device in three ways: 1. waiting for the master device to actively find the data required by the slave device; 2. the master device sends data and the slave device sends data at the same time; 3. by adding an additional signal line, the slave device is allowed to inform the master device to initiate data interaction. Based on the disadvantages of the three modes, the advantage of the periodic communication of the invention can be embodied.
In the three modes: 1. the latency is uncertain, and the communication efficiency of the slave device is low because the data interaction depends on the intention of the master device to actively require data, and generally, the SPI slave device in this way is mainly used for receiving the data of the master device and is not suitable for a full-duplex communication scenario. 2. Although it is in accordance with full duplex communication, because the length of the data sent by the master device is inconsistent with the length of the data sent by the slave device, and considering that the sending time of the slave device is inconsistent with that of the master device, it is necessary to add a set of design mechanism to ensure that the data of the slave device can be completely received, which increases the complexity of system design and development and reduces the reliability. 3. The additional addition of pins also increases hardware resource (pin) consumption, increases the complexity of system design and development, and reduces reliability.
In this embodiment, the master device and the slave device respectively perform data interaction in a common cycle through the master-out slave-in data line and the slave-out master-in data line, that is, a cycle communication mechanism is provided for the data interaction between the master device and the slave device, which is an improvement provided for the above three ways.
Specifically, the master device and the slave device agree to exchange data in a cycle of n seconds, and each time, the fixed length is m bytes. Since the SPI communication is dominated by the master device, when the master device initiates communication for the first time, and interacts with the slave device for m bytes of data, it waits for n seconds and then performs the next data interaction. When data interaction occurs each time, the master device and the slave device simultaneously send m bytes of data to each other according to the definition of the SPI bus.
At each interval of transmission, the master and slave devices each prepare data for the next interaction.
The length of each interactive data set to m bytes cannot exceed the maximum data quantity which can be transmitted by the SPI bus in n seconds. The relationship between m, n and baud rate B of the SPI bus is:in the case of the reference configuration where B is 20MHz, n is 0.001s and m is 1000 bytes; that is, when the bus frequency of the SPI is set to 10MHz, the baud rate is 20MHz, and the master and the slave exchange 1000 bytes of data every 1 ms.
As can be seen from the above, the periodic communication mechanism of this embodiment is optimized for the foregoing manner, for example, for the manner 1, this embodiment is equivalent to defining a period for the master device to actively acquire data, so that the waiting uncertainty is reduced, and the communication efficiency is improved; for the mode 2, the present embodiment fixes the transmission period and the data length, and is easier and more stable to implement and develop.
The communication cycle n seconds may be set empirically or experimentally. The set principle is as follows: the two preconditions for data interaction between the master device and the slave device can be completed within n seconds. The aforementioned preconditions are related to the data warehouse provided in the present embodiment, and are specifically described below.
The master and slave each maintain four "data warehouses," each of m bytes in size. A data warehouse is a dedicated piece of data storage space. The four data warehouses are respectively: a data sending preparation warehouse, a data sending warehouse, a data receiving processing warehouse and a data receiving warehouse.
Sending data to prepare a warehouse: the master and slave devices continue to fill the transmit data preparation repository with data frames ready for transmission. According to the size relation between the length of the data frame and the length of a data sending preparation warehouse, the data frame is cut off or a plurality of data frames are combined; through the process of data packet combination, a plurality of short data frames are connected together end to form a long data frame, so that the times of data interaction can be effectively reduced, and the data volume of each data interaction is improved.
A sending data warehouse: the SPI bus is used for storing the cut or combined data frames, and the cut or combined data frames in the data warehouse are sent to the SPI bus (i.e., the master-slave-in data line and the slave-out-master-in data line in this embodiment) when the master device and the slave device perform data interaction each time.
Receiving a data warehouse: each time data interaction occurs, a data frame after being cut off or combined is received from the SPI bus (i.e., the master-output slave-input data line, the slave-output master-input data line in this embodiment).
Receiving a data processing warehouse: and the device is used for splicing the cut data frames or cutting the combined data frames according to the length of the received data frames.
Although the period of each data interaction is n seconds, no data interaction is performed until both the master and the slave complete the two preconditions. The two preconditions are: 1. completing filling and sending data to prepare a warehouse; 2. and finishing the processing of the received data processing warehouse.
The period of data interaction and the two preconditions occur within the same time period, i.e. the period of data interaction corresponds to the time required by the master and slave to complete the two preconditions. It should be noted that, according to experimental calculation, the latency of two preconditions in 90% of communications is n seconds. Therefore, after waiting for n seconds in most cases, two preconditions are satisfied, and data interaction can be performed. Under the condition of 10% of few conditions, unexpected conditions exist, such as the damage of the controller, the occupation of the operation resources of the controller by other burst tasks, electromagnetic interference, unstable controller period caused by clock jitter and other external factors, and two precondition are not achieved after waiting for n seconds. This situation may be agreed upon between the master and slave devices through the handshake signals. Such extreme cases are rare and are not within the scope of the present invention.
Because the SPI communication process is controlled by the master device, the master device is able to determine whether it has completed two preconditions, while the slave device informs the master device via the slave status signal line through the S _ CTL pin whether it has completed two preconditions.
In this embodiment, the data frame is defined as follows:
data frame start mark (1 byte) | Data frame length (2 bytes) | Data (m-7 bytes) | Check code (4 bytes) |
Each frame has a fixed value as the first byte, marking the beginning of a frame.
The data frame length next to two bytes is the total number of bytes from the first byte to the last byte of the entire data frame.
Followed by the data of the data frame.
And the last four bytes are check codes, and the check codes check the data of the whole data frame except the check codes. The algorithm of the check code is not constrained by the embodiment.
When the master equipment and the slave equipment send data, data frames to be sent are sequentially filled into the data sending preparation warehouse end to end, each data interaction period sends the data frames according to the length of the data sending preparation warehouse, when the total length of the data frames filled in the current period is larger than the length of the data sending preparation warehouse, the filled data frames are cut off according to the length of the data sending preparation warehouse, and the remaining part after cutting off is filled in the subsequent period.
Specifically, (a0) when a data interaction cycle begins and an empty send data prepares the warehouse for filling:
(A1) if the first data frame length is less than or equal to the length of the transmit data preparation store, the data frame is placed from the location where the first byte of the transmit data preparation store begins.
(A1.1) if the length of the first data frame is larger than the length of the sending data preparation warehouse, cutting the first data frame into a plurality of sections by the length of the sending data preparation warehouse, filling the sending data preparation warehouse with the first section, and finishing the filling of the current period. And filling the second section after the next data interaction period. And sequentially filling the rest data segments in the subsequent period until the last segment is filled.
(a1.2) if the last segment of segmented data does not fill the sending data preparation warehouse, filling in a subsequent data frame per step (a 2).
(A2) After the first data frame is filled into the sending data preparation warehouse, the remaining length is still remained, whether the length of the second data frame is smaller than or equal to the remaining length of the sending data preparation warehouse or not is compared, if the length is smaller than or equal to the remaining length, the second data frame is filled into the next byte after the first frame is ended, and the second data frame is combined into a long data frame; if the length of the second data frame is larger than the remaining length (corresponding to the total length of the filled data frame is larger than the length of the sending data preparation warehouse), the filled second data frame is cut off according to the length of the sending data preparation warehouse (namely, the data with the idle length is cut off from the second data frame), so that the total length of the data frame filled in the current period is the same as the length of the sending data preparation warehouse, and the cut-off remaining part is filled in the subsequent period. Subsequent data frames are filled in such a way that each data interaction period transmits data frames at the length of the transmit data preparation repository.
It should be noted that, from the viewpoint of improving stability, in one period, in this embodiment, except for the first data frame, the subsequent data frames are not truncated, and if the length of the second data frame exceeds the remaining length of the data sending preparation warehouse, the data frame filling in the current period is ended, and the next period is waited to send again. The same is true for subsequent data frames. Therefore, the system is easier to design and develop software, and the operation is more reliable. It should be noted that, in order to keep the length of each interactive data as m bytes, in the case that the data frame is filled but the sending preparation data warehouse still has the remaining length, the embodiment will fill the invalid bytes in the remaining length.
When the master device and the slave device receive data, a step of cutting data frames is required, specifically:
(B0) when the receiving data processing warehouse receives a data frame:
(B1) the check is started from the first byte, and if the first byte is a data frame start flag, the data frame is extracted by the data frame length. If the first byte is not the data frame start flag, it indicates that there is no data in the data warehouse, and the data is not cut and extracted.
(B1.1) if the length of the first data frame is larger than the length of the data warehouse, the data frame is segmented and transmitted, and the data frame is spliced and processed after the complete data frame is received.
(B2) If the position of the end of the data warehouse is not reached after the first data frame is cut out, whether a byte after the end of the first data frame is a data frame start mark is checked. If yes, extracting a second data frame; if not, the data frame is not subsequently found, and no processing is performed.
(B3) After the second data frame is cut, the subsequent data frame is cut and extracted according to the step (B2), or is not processed any more.
It will be appreciated that the data frames are assembled end-to-end, and that if the next byte after the end of a data frame is not the data frame start flag, then a subsequent data-free frame is indicated.
When the n-second data interaction period is reached and data interaction is started, and the master device and the slave device finish filling the data frames (including the truncated data frames or the combined data frames) of the sending data preparation warehouse, the current sending data preparation warehouse and the sending data warehouse carry out function exchange. The sending data preparation warehouse filled with the data frame is converted into a sending data warehouse, and the data is sent to the other side in the data interaction process; the transmitting data warehouse is converted into an empty transmitting data preparation warehouse, and the master device and the slave device continue to fill data frames into the warehouse (if truncation or combination is needed, corresponding processing is carried out).
After the data interaction is completed and before the next data interaction is started, and after the master device and the slave device process the data frames (including the spliced data frames or the cut data frames) of the receiving data processing warehouse, the current receiving data processing warehouse and the receiving data warehouse perform function exchange. The receiving data warehouse is converted into a receiving data processing warehouse, and the master device and the slave device continue to process data frames from the receiving data processing warehouse; the received data processing warehouse is converted into an empty received data processing warehouse and waits for receiving a new data frame in the next data interaction.
The embodiment uses a data warehouse function exchange method instead of a data copying method, so that the calculation efficiency is improved.
If the data frame start flag is a value a, it is necessary to ensure that the value a does not occur in any other byte of a frame data, i.e., if the value a occurs in the data frame, the value a should be changed to another value by using an escape method. And carrying out reverse sense operation on the received data frame. The present invention does not limit the method of data escape.
Corresponding to the first embodiment of the present invention, a second embodiment of the present invention provides a communication method for an SPI-based full-duplex communication apparatus, where the SPI-based full-duplex communication apparatus includes a master device, a slave device, and a master-to-slave-in data line, a slave-to-master-to-slave-in data line, a clock signal line, a chip select signal line, and a slave device status signal line connected between the master device and the slave device, and the master device and the slave device each have a data warehouse for data interaction, and the communication method includes: the master device and the slave device perform data interaction simultaneously in a common period through the master output-slave input data line and the slave output-master input data line respectively, and the slave device transmits the state of whether the slave device can perform data interaction or not to the master device through the slave device state signal line.
Further, data frames to be sent are sequentially filled into the sending data preparation warehouse end to end, each data interaction period sends the data frames according to the length of the sending data preparation warehouse, when the total length of the data frames filled in the current period is larger than the length of the sending data preparation warehouse, the filled data frames are cut off according to the length of the sending data preparation warehouse, and the remaining cut-off data frames are filled in the subsequent period.
Further, if the length of a first data frame is greater than that of the sending data preparation warehouse, the first data frame is cut into a plurality of sections according to the length of the sending data preparation warehouse, the first section is filled in a first period, and the remaining sections are sequentially filled in a subsequent period until the last section is filled in;
if the length of the first data frame is less than the length of the sending data preparation warehouse, comparing the length of the next data frame with the remaining length of the sending data preparation warehouse, and if the length of the next data frame is less than or equal to the remaining length of the sending data preparation warehouse, combining the next data frame and the first data frame into a long data frame;
and if the length of the next data frame is greater than the remaining length of the data sending preparation warehouse, finishing the filling of the current period, and waiting for the next period to send the next data frame and the subsequent data frames.
Further, the received data processing warehouse extracts data frames according to the length of the received data frames, and if the length of the received first data frame is greater than that of the received data processing warehouse, splicing and extracting are carried out after all the segments are received; and if the received data frame is the combined data frame, cutting and extracting according to the length of each data frame.
Further, when the period reaches the period of starting data interaction, the function exchange between a sending data preparation warehouse filled in data frames and a sending data warehouse is completed, the sending data preparation warehouse and the sending data warehouse are converted into a sending data warehouse, and data are sent out in the data interaction process; the sending data warehouse is changed into an empty sending data preparation warehouse to fill in a new data frame;
after the data interaction is completed and before the next data interaction begins, the received data processing warehouse which has completed processing the received data frame and the received data warehouse carry out function exchange, convert into an empty received data warehouse and wait for receiving a new data frame in the next data interaction; the receive data warehouse is then transformed into a receive data processing warehouse to continue processing the received data frames.
Further, the period of each data interaction is set according to the time when the master device and the slave device complete two preconditions, wherein the two preconditions are as follows: completing filling and sending data to prepare a warehouse; and finishing the processing of the received data processing warehouse.
Further, the slave status signal line is connected between the flow control pin S _ CTL of the master and the flow control pin S _ CTL of the slave.
The embodiment of the invention also provides a communication method of the full-duplex communication device based on the SPI, the full-duplex communication device based on the SPI comprises a master device, a slave device, a master-out-slave-in data line, a slave-out-master-in data line, a clock signal line, a chip selection signal line and a slave device state signal line, wherein the master device and the slave device are respectively provided with a data warehouse for data interaction, and the communication method comprises the following steps: the master device and the slave device perform data interaction simultaneously in a common period through the master output-slave input data line and the slave output-master input data line respectively, and the slave device transmits the state of whether the slave device can perform data interaction or not to the master device through the slave device state signal line.
Further, the data warehouse comprises:
a sending data preparation warehouse used for filling in the data frames to be sent and cutting off the data frames or combining a plurality of data frames according to the size relationship between the length of the data frames and the length of the sending data preparation warehouse;
the data sending warehouse is used for storing the cut or combined data frames and sending the data frames to the master outgoing and slave incoming data line or the slave outgoing and master incoming data line when the master device and the slave device carry out data interaction;
a receive data warehouse for receiving data frames from the master-out slave-in data line or the slave-out master-in data line;
and the received data processing warehouse is used for splicing the cut data frames or cutting the combined data frames according to the length of the received data frames.
Further, data frames to be sent are sequentially filled into the sending data preparation warehouse end to end, each data interaction period sends the data frames according to the length of the sending data preparation warehouse, when the total length of the data frames filled in the current period is larger than the length of the sending data preparation warehouse, the filled data frames are cut off according to the length of the sending data preparation warehouse, and the remaining cut-off data frames are filled in the subsequent period.
Further, if the length of a first data frame is greater than that of the sending data preparation warehouse, the first data frame is cut into a plurality of sections according to the length of the sending data preparation warehouse, the first section is filled in a first period, and the remaining sections are sequentially filled in a subsequent period until the last section is filled in;
if the length of the first data frame is less than the length of the sending data preparation warehouse, comparing the length of the next data frame with the remaining length of the sending data preparation warehouse, and if the length of the next data frame is less than or equal to the remaining length of the sending data preparation warehouse, combining the next data frame and the first data frame into a long data frame;
and if the length of the next data frame is greater than the remaining length of the data sending preparation warehouse, finishing the filling of the current period, and waiting for the next period to send the next data frame and the subsequent data frames.
Further, the received data processing warehouse extracts data frames according to the length of the received data frames, and if the length of the received first data frame is greater than that of the received data processing warehouse, splicing and extracting are carried out after all the segments are received; and if the received data frame is the combined data frame, cutting and extracting according to the length of each data frame.
Further, when the period reaches the period of starting data interaction, the function exchange between a sending data preparation warehouse filled in data frames and a sending data warehouse is completed, the sending data preparation warehouse and the sending data warehouse are converted into a sending data warehouse, and data are sent out in the data interaction process; the sending data warehouse is changed into an empty sending data preparation warehouse to fill in a new data frame;
after the data interaction is completed and before the next data interaction begins, the received data processing warehouse which has completed processing the received data frame and the received data warehouse carry out function exchange, convert into an empty received data warehouse and wait for receiving a new data frame in the next data interaction; the receive data warehouse is then transformed into a receive data processing warehouse to continue processing the received data frames.
Further, the period of each data interaction is set according to the time when the master device and the slave device complete two preconditions, wherein the two preconditions are as follows: completing filling and sending data to prepare a warehouse; and finishing the processing of the received data processing warehouse.
The working principle and process of this embodiment refer to the description of the first embodiment of the present invention, and are not described herein again.
The description of the embodiment shows that the invention has the advantages that the full-duplex communication based on the SPI is realized by only using five pins, compared with the existing SPI communication scheme, the invention has higher efficiency and better stability, less interruption, cache and calculation resources of the controller of the device are occupied, and less pin resources are used; the efficiency of memory operation is improved through a more simplified logic and a more efficient memory management method; the method can truly realize that the communication efficiency is doubled under the condition of the same bus baud rate.
The above disclosure is only for the purpose of illustrating the preferred embodiments of the present invention, and it is therefore to be understood that the invention is not limited by the scope of the appended claims.
Claims (15)
1. The full-duplex communication device based on the SPI is characterized by comprising a master device, a slave device, a master-slave-input data line, a slave-output-master-input data line, a clock signal line, a chip selection signal line and a slave device state signal line, wherein the master device, the slave device and the slave device are connected between the master device and the slave device, the master device and the slave device simultaneously carry out data interaction in a common period through the master-output-slave-input data line and the slave-output-master-input data line respectively, the slave device state signal line is used for transmitting the state of whether the slave device can carry out data interaction to the master device, and the master device and the slave device are provided with data interaction warehouses.
2. The SPI-based full duplex communication device according to claim 1, wherein the data repository comprises:
a sending data preparation warehouse used for filling in the data frames to be sent and cutting off the data frames or combining a plurality of data frames according to the size relationship between the length of the data frames and the length of the sending data preparation warehouse;
the data sending warehouse is used for storing the cut or combined data frames and sending the data frames to the master outgoing and slave incoming data line or the slave outgoing and master incoming data line when the master device and the slave device carry out data interaction;
a receive data warehouse for receiving data frames from the master-out slave-in data line or the slave-out master-in data line;
and the received data processing warehouse is used for splicing the cut data frames or cutting the combined data frames according to the length of the received data frames.
3. The SPI-based full-duplex communication device according to claim 2, wherein data frames to be transmitted are sequentially filled end to end in the transmission data preparation repository, each data interaction period transmits a data frame according to the length of the transmission data preparation repository, when the total length of the data frames filled in the current period is greater than the length of the transmission data preparation repository, the filled data frames are truncated according to the length of the transmission data preparation repository, and the remaining part after truncation is filled in a subsequent period.
4. The SPI-based full-duplex communication device according to claim 2, wherein if the length of a first data frame is greater than the length of the sending data preparation repository, the first data frame is truncated into a plurality of segments according to the length of the sending data preparation repository, a first segment is filled in a first period, and the remaining segments are sequentially filled in subsequent periods until the last segment is filled in;
if the length of the first data frame is less than the length of the sending data preparation warehouse, comparing the length of the next data frame with the remaining length of the sending data preparation warehouse, and if the length of the next data frame is less than or equal to the remaining length of the sending data preparation warehouse, combining the next data frame and the first data frame into a long data frame;
and if the length of the next data frame is greater than the remaining length of the data sending preparation warehouse, finishing the filling of the current period, and waiting for the next period to send the next data frame and the subsequent data frames.
5. The SPI-based full-duplex communication device according to claim 3 or 4, wherein the receiving data processing warehouse extracts data frames according to the length of the received data frames, and if the length of the first received data frame is greater than the length of the receiving data processing warehouse, splicing and extracting are performed after all segments are received; and if the received data frame is the combined data frame, cutting and extracting according to the length of each data frame.
6. The SPI-based full-duplex communication device according to claim 2, wherein when the period reaches the start of data interaction, the transmission data ready repository filled with the data frame performs function exchange with the transmission data repository, converts the function exchange into a transmission data repository, and transmits the data during the data interaction; the sending data warehouse is changed into an empty sending data preparation warehouse to fill in a new data frame;
after the data interaction is completed and before the next data interaction begins, the received data processing warehouse which has completed processing the received data frame and the received data warehouse carry out function exchange, convert into an empty received data warehouse and wait for receiving a new data frame in the next data interaction; the receive data warehouse is then transformed into a receive data processing warehouse to continue processing the received data frames.
7. The SPI-based full-duplex communication device according to claim 2, wherein the period of each data interaction is set according to the time when the master and slave complete two preconditions: completing filling and sending data to prepare a warehouse; and finishing the processing of the received data processing warehouse.
8. An SPI-based full duplex communication apparatus according to claim 1, wherein said slave status signal line is connected between the master 'S flow control pin S _ CTL and the slave' S flow control pin S _ CTL.
9. A communication method of an SPI-based full-duplex communication device, which is characterized in that the SPI-based full-duplex communication device comprises a master device, a slave device, a master-out-slave-in data line, a slave-out-master-in data line, a clock signal line, a chip selection signal line and a slave device status signal line, wherein the master device and the slave device are connected between the master device and the slave device, and each of the master device and the slave device is provided with a data warehouse for data interaction, and the communication method comprises the following steps: the master device and the slave device perform data interaction simultaneously in a common period through the master output-slave input data line and the slave output-master input data line respectively, and the slave device transmits the state of whether the slave device can perform data interaction or not to the master device through the slave device state signal line.
10. The communication method according to claim 9, wherein the data repository comprises:
a sending data preparation warehouse used for filling in the data frames to be sent and cutting off the data frames or combining a plurality of data frames according to the size relationship between the length of the data frames and the length of the sending data preparation warehouse;
the data sending warehouse is used for storing the cut or combined data frames and sending the data frames to the master outgoing and slave incoming data line or the slave outgoing and master incoming data line when the master device and the slave device carry out data interaction;
a receive data warehouse for receiving data frames from the master-out slave-in data line or the slave-out master-in data line;
and the received data processing warehouse is used for splicing the cut data frames or cutting the combined data frames according to the length of the received data frames.
11. The SPI-based full-duplex communication device according to claim 10, wherein data frames to be transmitted are sequentially filled end to end in the transmission data preparation repository, each data interaction period transmits a data frame according to the length of the transmission data preparation repository, when the total length of the data frames filled in the current period is greater than the length of the transmission data preparation repository, the filled data frames are truncated according to the length of the transmission data preparation repository, and the remaining part after truncation is filled in a subsequent period.
12. The communication method according to claim 10, wherein if the length of the first data frame is greater than the length of the sending data preparation warehouse, the first data frame is cut into a plurality of segments according to the length of the sending data preparation warehouse, the first segment is filled in a first period, and the remaining segments are sequentially filled in a subsequent period until the last segment is filled in;
if the length of the first data frame is less than the length of the sending data preparation warehouse, comparing the length of the next data frame with the remaining length of the sending data preparation warehouse, and if the length of the next data frame is less than or equal to the remaining length of the sending data preparation warehouse, combining the next data frame and the first data frame into a long data frame;
and if the length of the next data frame is greater than the remaining length of the data sending preparation warehouse, finishing the filling of the current period, and waiting for the next period to send the next data frame and the subsequent data frames.
13. The communication method according to claim 11 or 12, wherein the receiving data processing warehouse extracts data frames according to the length of the received data frames, and if the length of the first received data frame is greater than the length of the receiving data processing warehouse, splicing and extracting are performed after all segments are received; and if the received data frame is the combined data frame, cutting and extracting according to the length of each data frame.
14. The communication method according to claim 10, wherein when the period reaches the beginning of data interaction, the function exchange between the transmission data preparation warehouse filled in the data frame and the transmission data warehouse is completed, the data preparation warehouse is converted into a transmission data warehouse, and the data is transmitted in the data interaction process; the sending data warehouse is changed into an empty sending data preparation warehouse to fill in a new data frame;
after the data interaction is completed and before the next data interaction begins, the received data processing warehouse which has completed processing the received data frame and the received data warehouse carry out function exchange, convert into an empty received data warehouse and wait for receiving a new data frame in the next data interaction; the receive data warehouse is then transformed into a receive data processing warehouse to continue processing the received data frames.
15. The communication method according to claim 10, wherein the period of each data interaction is set according to the time when the master device and the slave device complete two preconditions: completing filling and sending data to prepare a warehouse; and finishing the processing of the received data processing warehouse.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010025972.1A CN113079073A (en) | 2020-01-06 | 2020-01-06 | Full-duplex communication device based on SPI and communication method thereof |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010025972.1A CN113079073A (en) | 2020-01-06 | 2020-01-06 | Full-duplex communication device based on SPI and communication method thereof |
Publications (1)
Publication Number | Publication Date |
---|---|
CN113079073A true CN113079073A (en) | 2021-07-06 |
Family
ID=76608978
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010025972.1A Pending CN113079073A (en) | 2020-01-06 | 2020-01-06 | Full-duplex communication device based on SPI and communication method thereof |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113079073A (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114528235A (en) * | 2022-01-21 | 2022-05-24 | 厦门亿联网络技术股份有限公司 | SPI (Serial peripheral interface) -based communication method, slave equipment and system |
CN115941102A (en) * | 2022-10-31 | 2023-04-07 | 三峡智控科技有限公司 | Method for synchronous communication between controllers by connecting MCU and FPGA through SPI |
CN116962112A (en) * | 2023-09-20 | 2023-10-27 | 中国船舶集团有限公司第七〇七研究所 | Double-machine full duplex data transparent transmission method based on standard SPI bus connection |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20050281283A1 (en) * | 2003-11-03 | 2005-12-22 | Beecher Phillip E | Two way serial communication |
CN102508812A (en) * | 2011-11-30 | 2012-06-20 | 上海大学 | Dual-processor communication method based on SPI (serial peripheral interface) bus |
CN102567261A (en) * | 2010-12-31 | 2012-07-11 | 联芯科技有限公司 | Enhanced SPI (serial peripheral interface) controller, communication system of enhanced SPI and data transmission method |
CN102819512A (en) * | 2012-06-28 | 2012-12-12 | 惠州市德赛西威汽车电子有限公司 | Full-duplex communication device based on SPI and method thereof |
CN109902046A (en) * | 2019-02-01 | 2019-06-18 | 福瑞泰克智能系统有限公司 | A kind of communication means, relevant device and system for Serial Peripheral bus system |
-
2020
- 2020-01-06 CN CN202010025972.1A patent/CN113079073A/en active Pending
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20050281283A1 (en) * | 2003-11-03 | 2005-12-22 | Beecher Phillip E | Two way serial communication |
CN102567261A (en) * | 2010-12-31 | 2012-07-11 | 联芯科技有限公司 | Enhanced SPI (serial peripheral interface) controller, communication system of enhanced SPI and data transmission method |
CN102508812A (en) * | 2011-11-30 | 2012-06-20 | 上海大学 | Dual-processor communication method based on SPI (serial peripheral interface) bus |
CN102819512A (en) * | 2012-06-28 | 2012-12-12 | 惠州市德赛西威汽车电子有限公司 | Full-duplex communication device based on SPI and method thereof |
CN109902046A (en) * | 2019-02-01 | 2019-06-18 | 福瑞泰克智能系统有限公司 | A kind of communication means, relevant device and system for Serial Peripheral bus system |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114528235A (en) * | 2022-01-21 | 2022-05-24 | 厦门亿联网络技术股份有限公司 | SPI (Serial peripheral interface) -based communication method, slave equipment and system |
CN114528235B (en) * | 2022-01-21 | 2024-05-31 | 厦门亿联网络技术股份有限公司 | SPI-based communication method, slave device and system |
CN115941102A (en) * | 2022-10-31 | 2023-04-07 | 三峡智控科技有限公司 | Method for synchronous communication between controllers by connecting MCU and FPGA through SPI |
CN115941102B (en) * | 2022-10-31 | 2023-09-15 | 三峡智控科技有限公司 | Method for synchronous communication between controllers connected with MCU and FPGA by SPI |
CN116962112A (en) * | 2023-09-20 | 2023-10-27 | 中国船舶集团有限公司第七〇七研究所 | Double-machine full duplex data transparent transmission method based on standard SPI bus connection |
CN116962112B (en) * | 2023-09-20 | 2023-12-15 | 中国船舶集团有限公司第七〇七研究所 | Double-machine full duplex data transparent transmission method based on standard SPI bus connection |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
EP2513744B1 (en) | Automatic and controllable system operation | |
CN113079073A (en) | Full-duplex communication device based on SPI and communication method thereof | |
US8989170B2 (en) | Wireless communication system and wireless communication control method, wireless communication device and wireless communication method, and computer program | |
US4510599A (en) | Prioritized unidirectional distributed bus accessing system | |
CN113904762B (en) | Full duplex 485 bus communication system with annular buffer zone and method | |
CN112269749B (en) | I2C communication system | |
CN101052031B (en) | Data interaction method for Apple computer and radio communication terminal | |
JPH0535624A (en) | Data transfer method, data transmitting device and restoring device | |
JP4463471B2 (en) | Protocol for transmission of multiple logical flows for multiple exchange of command / response pairs over a single physical exchange channel between master and slave, and corresponding apparatus for checking and monitoring applet execution | |
CN111008169B (en) | Low-cost high-speed communication bus and transmission control method thereof | |
CN102099765A (en) | Cableless USB connectivity over IEEE 802.11 networks | |
Bankov et al. | Approach to real-time communications in Wi-Fi networks | |
WO2022127448A1 (en) | Message transmission method, terminals and storage medium | |
CN112559422A (en) | Encoding and decoding implementation method, device and equipment based on USB differential signal line | |
CN107786310B (en) | Data packet transmission method and node | |
CN114490465B (en) | Data transmission method and device for direct memory access | |
CN113986808B (en) | Method, system and computer equipment for sending BMC code | |
CN117251392A (en) | SPI data transmission method and system | |
CN116467247A (en) | Multi-core communication implementation method and device | |
CN113467925A (en) | Computing node and method supporting mixed deployment of heterogeneous GPU (graphics processing Unit) instances and general instances | |
CN118964240A (en) | Buffer memory, data transmission method thereof and USB transmission equipment | |
CN115038116A (en) | Data transmission method, device, electronic equipment, storage medium and product | |
CN112584556A (en) | RRC connection management method and device, storage medium and electronic device | |
CN118353833A (en) | Message forwarding method, data communication method and singlechip product | |
CN117729172A (en) | Data transmission method, device and storage medium in isolated network environment |
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 | ||
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20210706 |