Method for realizing active application transmission of SPI slave equipment
1. A method for realizing active application transmission of an SPI slave device is characterized by comprising the following steps:
the method comprises the steps that a slave device sends a first query request to an SPI master device, wherein the first query request is used for querying whether the SPI master device is in an SPI data transmission idle state or not, and when the slave device determines that the SPI master device is in the SPI data transmission idle state according to the returned first query request, the slave device is ready to transmit data or actively pulls down a chip selection signal to request SPI data transmission after being ready to receive the data;
the SPI master device receives a first query response from a slave device, wherein the first query response is used for detecting whether the slave device actively sends an SPI data transmission request, and when the SPI master device detects that the slave device actively sends an SPI data transmission request signal through the first query response, the SPI master device starts to prepare for transmission;
the slave device sends a second query request to the SPI master device, wherein the second query request is used for querying whether the SPI master device sends a serial clock signal or not, when the slave device detects that the SPI master device sends the clock signal through the returned second query request and starts to prepare for transmission, the slave device releases a chip selection signal, and the drive of the chip selection signal is switched from the slave device to the SPI master device to start data transmission;
and the SPI master device receives a second inquiry response from a slave device, the second inquiry response is used for detecting whether the slave device completes data transmission, when the SPI master device detects that the slave device completes data transmission through the second inquiry response, the SPI master device does not drive a chip selection signal any more, and the chip selection signal is pulled up to a high level by a pull-up resistor.
2. The method of claim 1, wherein the method comprises: when the slave device determines that the SPI master device is in a non-SPI data transmission idle state according to the returned first query request, the slave device does not initiate a data transmission request any more.
3. The method of claim 1, wherein the method comprises: when the SPI master device detects that the slave device actively sends an SPI data transmission request signal through a first query response, if the SPI master device is in a low power consumption state, the SPI master device is firstly awakened and then starts to prepare for transmission.
4. The method of claim 1, wherein the method comprises: the SPI master device is in an SPI transmission idle state period, and low-power output is achieved through dormancy of the SPI master device.
5. The method of claim 1, wherein the method comprises: the chip selection signal is a bidirectional signal SS, and no additional processing is needed in the switching process of the chip selection signal from the slave device to the SPI master device.
6. The method of claim 5, wherein the method further comprises the following steps: the chip select signal is converted into a bidirectional signal SS through an open-drain circuit.
Background
The SPI interface has the defects that all transmission requests are initiated by the SPI master device, the SPI slave device is periodically inquired through the SPI master device to realize data transmission, the SPI slave device cannot initiate any transmission request, and when the SPI slave device is required to process data or the SPI master device passively acquires the data, frequent interaction is required between the SPI master device and the SPI slave device, so that the system performance is reduced, and the practical application is greatly limited.
The invention patent with publication number CN108475241A discloses a data transmission method and device based on SPI, in which a first device sends a query and connection establishment request to a second device through a UART interface, and the UART interface needs to be additionally added as an auxiliary communication interface, so that the structure is complex and the cost is increased.
The patent application with publication number CN112214440A discloses a communication method based on SPI communication, in which an SPI master device and an SPI slave device are electrically connected through a READY pulse line, the SPI slave device processes data, then buffers the data, and sends a 500HZ pulse signal through the READY pulse line, and the SPI master device listens to the signal and reads the data. The scheme needs to additionally add a READY signal as a request signal, and the cost is additionally increased.
Patent application with publication number CN107832250A discloses a master-slave communication system and a reliable transmission method based on SPI. This scheme is through increasing the handshake line from SPI equipment to need to close the SPI module from SPI equipment in order to solve the problem of SPI interface communication both sides chronogenesis matching difficulty, independent SPI module can not realize the data request to SPI main equipment, and the cost is higher and realize comparatively troublesome.
Research shows that when the current slave device sends a data transmission request to the SPI master device through the SPI, an additional data interface or an additional control line is required, which greatly increases the data transmission cost, for example, a UART interface is additionally added to the above-mentioned publication No. CN 108475241A; a READY pulse line is additionally designed in a patent with publication number CN112214440A, and a handshake line is added to SPI equipment in a patent with publication number CN 107832250A; the prior art can not meet the requirements of people at the present stage, and the prior art is urgently needed to be reformed based on the current situation.
Disclosure of Invention
The embodiment of the invention provides a method for realizing active application transmission of SPI slave equipment, which is used for solving the defects of complex structure and high cost in the background technology.
The invention provides the following technical scheme: a method for realizing active application transmission of an SPI slave device comprises the following steps:
s101: when the SPI master device is in an SPI data transmission idle state, the slave device is ready to transmit data or actively pulls down a chip selection signal to request SPI data transmission after being ready to receive the data, and when the SPI master device is in a non-SPI data transmission idle state, the slave device does not actively apply for data transmission;
s102: when the SPI master device detects that the slave device actively sends an SPI data transmission request signal through a first query response, the SPI master device starts to prepare for transmission;
s103: when the SPI master device sends a clock signal and starts to prepare for transmission, the slave device releases a chip selection signal, and the drive of the chip selection signal is switched from the slave device to the SPI master device to start data transmission;
s104: when the SPI master device detects that the slave device completes data transmission, the SPI master device does not drive a chip selection signal any more, and the chip selection signal is pulled up to a high level by a pull-up resistor.
Has the advantages that:
(1) under the condition of not needing to use additional other communication protocols and peripheral interfaces, the SPI slave equipment can actively initiate a data transmission request or a data acquisition request, the number, the area and the power consumption of the added interfaces are reduced, and the cost is reduced.
(2) The SPI master device can reduce power consumption in a sleep mode and the like during an idle period, and periodic inquiry is avoided.
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, and it is obvious that the drawings in the following description are some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a schematic diagram of a transmission structure of an SPI master device and an SPI slave device based on an SPI protocol according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of an overall method according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, are within the scope of the present invention.
The invention is described in detail below with reference to the figures and the embodiments.
Referring to fig. 2, the present invention provides a method for implementing active application transmission of an SPI slave device, according to the following technical solution, and the implementation steps of the method include:
s101: the method comprises the steps that a slave device sends a first query request to an SPI master device, wherein the first query request is used for querying whether the SPI master device is in an SPI data transmission idle state or not, and when the slave device determines that the SPI master device is in a non-SPI data transmission idle state according to the returned first query request, the slave device does not actively apply for data transmission any more;
when the slave device determines that the SPI master device is in an SPI data transmission idle state according to a returned first query request, the slave device is ready to transmit data or actively pulls down a chip selection signal after being ready to receive the data to request SPI data transmission, wherein the chip selection signal is a bidirectional signal SS, and the chip selection signal is converted into the bidirectional signal SS through an open-drain circuit;
referring to fig. 1, the open-drain circuit is a circuit that takes the drain of the MOSFET as an output, and the complete open-drain circuit is composed of a MOSFET transistor and a pull-up resistor, and the open-drain circuit utilizes the driving capability of an external circuit to reduce the requirement on the driving capability of a chip and drive a load higher than the power supply voltage of the chip.
S102: the SPI master device receives a first query response from a slave device, wherein the first query response is used for detecting whether the slave device actively sends an SPI data transmission request, and when the SPI master device detects that the slave device actively sends an SPI data transmission request signal through the first query response, the SPI master device starts to prepare for transmission; and when the SPI master device detects that the slave device actively sends an SPI data transmission request signal through a first query response, if the SPI master device is in a low power consumption state, the SPI master device is firstly awakened and then starts to prepare for transmission, and if the SPI master device is in a non-sleep state, the SPI master device starts to prepare for transmission at any time.
S103: the slave device sends a second query request to the SPI master device, wherein the second query request is used for querying whether the SPI master device sends a serial clock signal or not, when the slave device detects that the SPI master device sends the clock signal through the returned second query request and starts to prepare for transmission, the slave device releases a chip selection signal, and the drive of the chip selection signal is switched from the slave device to the SPI master device to start data transmission; the chip selection signal is a bidirectional signal SS, and no additional processing is needed in the switching process of the chip selection signal from the slave device to the SPI master device.
S104: and the SPI master device receives a second inquiry response from a slave device, the second inquiry response is used for detecting whether the slave device completes data transmission, when the SPI master device detects that the slave device completes data transmission through the second inquiry response, the SPI master device does not drive a chip selection signal any more, and the chip selection signal is pulled up to a high level by a pull-up resistor.
Referring to fig. 1, as an alternative embodiment of the present invention, the SPI master device and the SPI slave device have an SPI protocol therebetween, and follow the SPI protocol while adopting an open drain (open drain) technology, so that the SPI master device and the SPI slave device have the following relationship:
(1) the SPI master device is provided with a clock signal SCK sent to the slave device, and in the invention, if the SPI master device sends the clock signal to the slave device, the SPI master device indicates that data transmission is ready;
(2) the SPI master device sends an inquiry request to the slave device through an MOSI signal, and the slave device sends an inquiry corresponding to the SPI master device through an MISO signal; and the SPI communication connection between the SPI master device and the slave device has been established before the SPI master device sends the inquiry request to the slave device or before the slave device sends the inquiry response to the SPI master device.
(3) The SPI main equipment and the slave equipment can drive and release chip selection signals, and in the invention, the chip selection signals are converted into bidirectional Signals SS (SS) through an open-drain circuit; the slave device requests SPI data transmission by actively pulling down the bidirectional signal ss (ss), and the SPI master device starts data transmission by driving the bidirectional signal ss (ss).
It should be particularly noted that when the current slave device sends a data transmission request to the SPI master device through the SPI, an additional data interface or an additional control line is required, which greatly increases the data transmission cost, and a UART interface is additionally added to the device with publication number CN 108475241A; according to the invention, the READY pulse line is additionally designed in the patent with publication number CN112214440A, and the handshake line is added in the patent with publication number CN107832250A from the SPI equipment.
Although the present invention has been described in detail with reference to the foregoing embodiments, it will be apparent to those skilled in the art that various changes in the embodiments and/or modifications of the invention can be made, and equivalents and modifications of some features of the invention can be made without departing from the spirit and scope of the invention.