A slave end initiatively output data SPI interaction method and device and electronic equipment
Patent Information
- Application Number
- CN202310304900.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-21
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2043-03-21
AI Technical Summary
[0005]本申请实施例的提供一种Slave端主动输出数据的SPI交互方法、装置及电子设备,解决现有技术中Slave端无法主动上报信息的问题,本方案可以使Slave端主动上报大量业务信息数据,提高了数据传输效率,使交互过程具有极高的鲁棒性
[0043] In this embodiment, if a data transmission trigger event occurs, a first interrupt signal is sent to the Master via the signal line; a first instruction is received from the Master, the data to be sent is framed and transmitted through the MISO channel of the SPI channel, and a second interrupt signal is sent to the Master via the signal line. The Master then sends a second instruction based on the second interrupt signal to receive frame data from the MISO channel of the SPI channel and parse the frame data. Through this SPI interaction method where the Slave actively outputs data, the Slave can proactively report a large amount of business information data, improving data transmission efficiency and making the interaction process highly robust. Furthermore, it reduces hardware resource consumption, saves costs, and has high engineering practical value.
Smart Images

Figure CN116450561B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of electronic information technology, and specifically relates to an SPI interaction method, device and electronic device for the slave end to actively output data. Background Technology
[0002] With the rapid development of technology, the SPI (Serial Peripheral Interface) protocol has been widely used in the field of master-slave device data interaction bus due to its high speed and clock synchronization characteristics.
[0003] SPI consists of a Master and a Slave side. Communication enable and clock signals are controlled by the Master side, so all SPI communication is initiated by the Master. Many ASICs (Application Specific Integrated Circuits) follow a relatively standard SPI read / write communication protocol, with external units performing data writing and result readback. However, the advantage of the SPI bus often lies in the Master's read / write process. For traditional master-slave interactions, since the slave device typically only returns simple data, strictly adhering to the standard SPI timing, the Slave side does not need to actively report data.
[0004] However, with the development of semiconductor technology and the increasing demands of practical engineering, more and more ASICs are integrating processor units internally, forming SoCs (System on Chip) to perform more complex business processing. In this scenario, the Slave side of SPI has a greater need to actively output information. However, since the control of the enable and clock signals lies with the Master side, the original interaction method cannot support the Slave side's proactive information reporting. Therefore, how to design a mechanism and method to support the Slave side to freely, proactively, and efficiently output business information is an urgent problem to be solved in this field. Summary of the Invention
[0005] This application provides an SPI interaction method, apparatus, and electronic device in which the slave end actively outputs data, solving the problem in the prior art that the slave end cannot actively report information. This solution enables the slave end to actively report a large amount of business information data, improving data transmission efficiency and making the interaction process highly robust. Furthermore, it reduces hardware resource consumption, saves costs, and has high engineering practical value.
[0006] In a first aspect, embodiments of this application provide an SPI interaction method in which a slave terminal actively outputs data. The slave terminal is connected to the master terminal via an SPI channel, and the slave terminal is also connected to the master terminal via a signal line. The method is executed by the slave terminal and includes:
[0007] If a data transmission trigger event occurs, a first interrupt signal is sent to the Master terminal via the signal line;
[0008] Upon receiving the first instruction from the Master, the system frames the data to be sent and sends it through the MISO channel of the SPI channel. It also sends a second interrupt signal to the Master via the signal line. The Master then sends a second instruction based on the second interrupt signal to receive the frame data from the MISO channel of the SPI channel and parse the frame data.
[0009] Furthermore, after sending a second interrupt signal to the Master terminal via the signal line, the method further includes:
[0010] If a data frame retransmission command is received from the Master, the data to be sent will be reframed and sent through the MISO channel of the SPI channel, and a second interrupt signal will be sent to the Master again through the signal line.
[0011] Furthermore, after sending a first interrupt signal to the Master terminal via the signal line, the method further includes:
[0012] If the first instruction is not received from the Master within the first waiting period, the first interrupt signal is resent to the Master via the signal line.
[0013] After sending a second interrupt signal to the Master terminal via the signal line, the method further includes:
[0014] If the second instruction is not received from the Master within the second waiting period, a second interrupt signal is sent back to the Master via the signal line.
[0015] Furthermore, after issuing the first interrupt signal or the second interrupt signal, the method further includes:
[0016] The Master terminal is provided with the option to fulfill a silent commitment based on either the first interrupt signal or the second interrupt signal.
[0017] Furthermore, after issuing the first interrupt signal, the method further includes:
[0018] If the Master fails to fulfill its silent commitment, it will be marked as abnormal and the current cycle will be terminated.
[0019] The first interrupt signal is re-sent to the Master terminal via the signal line;
[0020] Alternatively, after issuing the second interrupt signal, the method further includes:
[0021] If the Master fails to fulfill its silent commitment, it will be marked as abnormal and the current cycle will be terminated.
[0022] The data frame to be transmitted is re-transmitted through the MISO channel of the SPI channel, and a second interrupt signal is re-transmitted to the Master terminal through the signal line.
[0023] Furthermore, the method also includes:
[0024] If the first interrupt signal is not sent to the Master terminal through the signal line, and the first instruction is received from the Master terminal, then the empty data frame is sent through the MISO channel of the SPI channel, and a second interrupt signal is sent to the Master terminal through the signal line, so that the Master terminal can release the silent commitment.
[0025] Furthermore, the first feedback instruction includes the Master writing an SPI_INTR1_READ_CMD instruction to the SPI MOSI;
[0026] The second instruction in the feedback includes the Master writing READ_EMPTY_CNT times SPI_DUMMY_DATA data to SPI MOSI.
[0027] Secondly, embodiments of this application provide an SPI interaction method in which the slave terminal actively outputs data. The slave terminal is connected to the master terminal via an SPI channel, and the slave terminal is also connected to the master terminal via a signal line. The method is executed by the master terminal, and the method includes:
[0028] The first interrupt signal sent by the Slave terminal is received through the signal line;
[0029] The first instruction is fed back to the Slave terminal;
[0030] When the second interrupt signal is received from the Slave terminal via the signal line, a second instruction is fed back according to the second interrupt signal to read the frame data sent by the Slave terminal through the MISO channel of the SPI channel and to parse the frame data; wherein, the frame data is obtained by the Slave terminal framing the data to be sent.
[0031] Furthermore, after parsing the frame data, the method further includes:
[0032] If parsing fails, a data frame retransmission command is issued, prompting the Slave to reassemble the data to be sent and transmit it through the MISO channel of the SPI channel, and then send a second interrupt signal to the Master again through the signal line.
[0033] Furthermore, after receiving the first interrupt signal or the second interrupt signal, the method further includes:
[0034] Fulfill the commitment to silence.
[0035] Thirdly, embodiments of this application provide an SPI interaction device for a slave end to actively output data. The slave end is connected to the master end via an SPI channel, and the slave end and the master end are also connected via signal lines. The device is configured on the slave end and includes:
[0036] The first interrupt signal sending module is used to send a first interrupt signal to the Master terminal through the signal line if a data transmission trigger event exists.
[0037] The second interrupt signal transmission module is used to receive the first instruction fed back by the Master terminal, frame the data to be transmitted and send it through the MISO channel of the SPI channel, and send a second interrupt signal to the Master terminal through the signal line, so that the Master terminal can feed back a second instruction according to the second interrupt signal, so as to receive frame data from the MISO channel of the SPI channel and parse the frame data.
[0038] Fourthly, embodiments of this application provide an SPI interaction device where the slave actively outputs data. The slave and master are connected via an SPI channel, and the slave and master are also connected via signal lines. The device is configured on the master and includes:
[0039] The receiving module is used to receive the first interrupt signal sent by the Slave terminal through the signal line;
[0040] The feedback module is used to send the first instruction back to the Slave terminal;
[0041] The parsing module is used to receive a second interrupt signal from the Slave terminal via the signal line, and to feed back a second instruction based on the second interrupt signal to read the frame data sent by the Slave terminal through the MISO channel of the SPI channel and to parse the frame data; wherein the frame data is obtained by the Slave terminal framing the data to be sent.
[0042] Fifthly, embodiments of this application provide an electronic device including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the method described in the first aspect or the method described in the second aspect.
[0043] In this embodiment, if a data transmission trigger event occurs, a first interrupt signal is sent to the Master via the signal line; a first instruction is received from the Master, the data to be sent is framed and transmitted through the MISO channel of the SPI channel, and a second interrupt signal is sent to the Master via the signal line. The Master then sends a second instruction based on the second interrupt signal to receive frame data from the MISO channel of the SPI channel and parse the frame data. Through this SPI interaction method where the Slave actively outputs data, the Slave can proactively report a large amount of business information data, improving data transmission efficiency and making the interaction process highly robust. Furthermore, it reduces hardware resource consumption, saves costs, and has high engineering practical value. Attached Figure Description
[0044] Figure 1 This is a flowchart illustrating the SPI interaction method for Slave-side active data output provided in Embodiment 1 of this application;
[0045] Figure 2 This is a flowchart illustrating the SPI interaction method for Slave-side active data output provided in Embodiment 2 of this application;
[0046] Figure 3 This is a schematic diagram of the SPI interaction device that actively outputs data on the Slave side, as provided in Embodiment 3 of this application;
[0047] Figure 4 This is a schematic diagram of the SPI interaction device for Slave-side active data output provided in Embodiment 4 of this application;
[0048] Figure 5 This is a schematic diagram of the structure of the electronic device provided in Embodiment 5 of this application. Detailed Implementation
[0049] To make the objectives, technical solutions, and advantages of this application clearer, specific embodiments of this application will be described in further detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are merely for explaining this application and not for limiting it. It should also be noted that, for ease of description, only the parts relevant to this application are shown in the drawings, not all of them. Before discussing exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe operations (or steps) as sequential processes, many of these operations can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the operations can be rearranged. The process can be terminated when its operation is completed, but may also have additional steps not included in the drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0050] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0051] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0052] The following description, in conjunction with the accompanying drawings, details an RSMC chip, a multi-stage chip startup method, and a BeiDou communication and navigation device provided in this application, through specific embodiments and application scenarios.
[0053] Example 1
[0054] Figure 1This is a flowchart illustrating the SPI interaction method for Slave-end active data output provided in Embodiment 1 of this application. The Slave end is connected to the Master end via an SPI channel, and the Slave end is also connected to the Master end via signal lines; the method is executed by the Slave end, as follows... Figure 1 As shown, the specific steps include the following:
[0055] S101, if a data transmission trigger event exists, a first interrupt signal is sent to the Master terminal through the signal line.
[0056] First, this solution can be used in scenarios where the Slave-side SoC chip or Slave-side sensor actively senses data transmission trigger events and proactively reports a large amount of business information data to the Master.
[0057] Based on the above usage scenarios, it is understood that the execution subject of this application can be a Slave-side SoC chip or a Slave-side sensor, without further limitations here.
[0058] In this scheme, the Slave end is connected to the Master end via an SPI channel, and the Slave end is also connected to the Master end via a signal line; the method is executed by the Slave end.
[0059] The slave device can be a SoC chip or a sensor that actively collects data and sends it to the master device for processing. For example, when the slave device is a temperature sensor, it can actively collect temperature data and transmit it to the master device for appropriate processing. Because the slave device can actively collect data, the workload of the master device is reduced, improving efficiency.
[0060] The master device can be a primary device that receives data transmitted from secondary devices and performs corresponding processing operations based on this data. The master device can include smart terminal devices or IoT platforms, such as mobile phones, computers, and central control screens. When the master device is a computer and the secondary device is a temperature sensor within the substation, the secondary device actively feeds back the substation's temperature information to the master device. The master device can then monitor the substation's temperature in real time based on this feedback and take appropriate action when abnormalities occur.
[0061] The SPI channel can be used by a communication bus to transmit data. SPI is a high-speed, full-duplex, synchronous communication bus that only occupies four pins on the chip, saving pins and PCB layout space. Due to its ease of use, more and more chips are integrating this communication protocol. It typically consists of a master module and one or more slave modules. The master module selects a slave module for synchronous communication to complete data exchange.
[0062] The signal line can be an interrupt signal line, which is used by the Slave to transmit an interrupt notification signal to the Master.
[0063] The Slave and Master are connected via an SPI channel. After connection, they can exchange data and commands. That is, the Slave can receive commands from the Master, and the Master can receive data transmitted from the Slave.
[0064] The Slave and Master can also be connected via signal lines. After connection, the Slave can transmit interrupt signals to the Master via signal lines.
[0065] A data transmission trigger event can be a signal that the slave can begin transmitting data to the master. For example, a data transmission time interval can be preset on the slave. If the time interval is 3 seconds, the slave will transmit the collected data to the master for processing every 3 seconds. Furthermore, each time interval is reached, it is considered that a data transmission trigger event has occurred.
[0066] The first interrupt signal can be a signal from the slave to notify the master to stop writing data to the slave. Before the first interrupt signal is issued, the master writes data to the slave according to the normal SPI timing. When a data transmission trigger event occurs, the slave begins to send the first interrupt signal to the master via a signal line. Upon receiving the first interrupt signal, the master stops writing data to the slave. Only after the master stops writing data to the slave can the slave transmit data to the master.
[0067] Based on the above technical solutions, optionally, after sending a first interrupt signal to the Master terminal via the signal line, the method further includes:
[0068] If the first instruction is not received from the Master within the first waiting period, the first interrupt signal is resent to the Master via the signal line.
[0069] After sending a second interrupt signal to the Master terminal via the signal line, the method further includes:
[0070] If the second instruction is not received from the Master within the second waiting period, a second interrupt signal is sent back to the Master via the signal line.
[0071] In this scheme, the first waiting time can be the duration for the Master to send the first instruction back to the Slave. If the first instruction is not received from the Master after the first waiting time, it can be considered that a line fault has occurred and the first interrupt signal has not been successfully transmitted to the Master. In this case, the first interrupt signal will be resent to the Master through the signal line. For example, the first waiting time can be set to 5 seconds. If the Slave has not received the first instruction after 5 seconds, it will resent the first interrupt signal to the Master through the signal line.
[0072] The second waiting time can be the time for the Master to send the second instruction back to the Slave. If the second instruction sent by the Master is not received after the second waiting time, it can be considered that the line has failed and the second interrupt signal has not been successfully transmitted to the Master. In this case, the second interrupt signal will be sent back to the Master through the signal line again.
[0073] In this solution, by setting a first waiting time and a second waiting time, anomalies can be detected, and issues such as hardware current interference can be addressed. During interaction, anomalies can be automatically repaired. Furthermore, anomalies will not cause the Slave or Master to stop working; by retransmitting interrupt signals, the Master can resume receiving signals and responding with corresponding instructions, thus improving the working efficiency of both the Master and Slave.
[0074] Based on the above technical solutions, optionally, after issuing the first interrupt signal or the second interrupt signal, the method further includes:
[0075] The Master terminal is provided with the option to fulfill a silent commitment based on either the first interrupt signal or the second interrupt signal.
[0076] In this scheme, a silent commitment can be a promise by the Master to stop writing any data to the Slave and instead wait for the next interrupt signal sent by the Master. When the Master receives the first or second interrupt signal, it will begin to fulfill the silent commitment.
[0077] In this solution, setting a silent commitment can improve the data transmission efficiency between the Master and Slave. Without a silent commitment, data writing may become chaotic due to the Master writing data simultaneously with the Slave, leading to a malfunction in both the Master and Slave systems.
[0078] Based on the above technical solutions, optionally, after issuing the first interrupt signal, the method further includes:
[0079] If the Master fails to fulfill its silent commitment, it will be marked as abnormal and the current cycle will be terminated.
[0080] The first interrupt signal is re-sent to the Master terminal via the signal line;
[0081] Alternatively, after issuing the second interrupt signal, the method further includes:
[0082] If the Master fails to fulfill its silent commitment, it will be marked as abnormal and the current cycle will be terminated.
[0083] The data frame to be transmitted is re-transmitted through the MISO channel of the SPI channel, and a second interrupt signal is re-transmitted to the Master terminal through the signal line.
[0084] In this scheme, when the Slave sends the first interrupt signal, but the Master fails to fulfill its silence commitment, it's possible that the Master received a first interrupt signal from another Slave and mistakenly identified it as originating from this Slave. This leads to the Master fulfilling its silence commitment for other Slaves but not for this particular Slave. Upon detecting the Master's failure to fulfill its silence commitment in real time, the Slave marks it as abnormal, terminates the current cycle, and re-sends the first interrupt signal to the Master via the aforementioned signal line, thus restarting a new round of interaction.
[0085] When the Slave sends a second interrupt signal, but the Master fails to fulfill its silence commitment, it's possible that the Master received a second interrupt signal from another Slave and mistakenly identified it as originating from this particular Slave. This causes the Master to fulfill its silence commitment for other Slaves but not for this one. Upon detecting the Master's failure to fulfill its silence commitment in real time, the Slave marks it as an anomaly, terminates the current cycle, repackages the data frame to be sent, and retransmits it via the MISO channel. In other words, it rewrites the data frame to the MISO channel. After writing, it sends the second interrupt signal to the Master via a signal line.
[0086] This solution enables the slave end to have anomaly detection and frame loss retransmission functions, making the interaction process highly robust and able to cope with various situations such as hardware current interference and software asynchronous blocking, thus having high engineering practical value.
[0087] Based on the above technical solutions, optionally, the method further includes:
[0088] If the first interrupt signal is not sent to the Master terminal through the signal line, and the first instruction is received from the Master terminal, then the empty data frame is sent through the MISO channel of the SPI channel, and a second interrupt signal is sent to the Master terminal through the signal line, so that the Master terminal can release the silent commitment.
[0089] In this scheme, an empty data frame can be a single byte of meaningless data or 128 zeros. After the slave end has packaged the valid data, it fills the packet with 128 zeros and pushes the valid data to the front.
[0090] If the slave device receives the first instruction from the master device without issuing the first interrupt signal, it can be considered that the master device has malfunctioned, mistakenly taking the first interrupt signal sent by another slave device as the first interrupt signal sent by this slave device, and has begun to fulfill its silence commitment. In this case, an empty data frame needs to be sent to the master device for the master device to read. After the empty data frame is sent through the MISO channel, a second interrupt signal is sent to the master device. After the master device reads the empty data frame, it will release its silence commitment.
[0091] In this solution, by setting empty data frames, the Slave can actively detect and repair anomalies when chaos occurs on the Master side, making the interaction process highly robust and able to cope with various situations such as hardware current interference and software asynchronous blocking.
[0092] S102, receive the first instruction fed back by the Master, frame the data to be sent and send it through the MISO channel of the SPI channel, and send a second interrupt signal to the Master through the signal line, so that the Master can feed back a second instruction according to the second interrupt signal, so as to receive frame data from the MISO channel of the SPI channel and parse the frame data.
[0093] The first instruction can be a command sent by the Master to the Slave indicating a commitment to silence. When the Master sends the first instruction back to the Slave, it indicates that the Master has successfully received and responded to the first interrupt signal, and has stopped writing data to the Slave, thus entering a silent state.
[0094] The data frame to be transmitted can be data collected by the Slave. For example, if the Slave is a temperature sensor in a substation, the temperature command sent by the sensor to the Master after collecting the temperature is the data frame to be transmitted. Since each command usually has a format and may occupy a short field, they can be concatenated together. Therefore, it can be transmitted according to the Slave's high-efficiency frame output protocol. The Slave's high-efficiency frame output protocol is designed to fully utilize the channel efficiency of SPI interaction. Before filling the SPI MISO FIFO, the Slave concatenates as many commands as possible together, adding a frame header to form a high-efficiency protocol frame. The frame format is as follows: (1) Data header identifier, at least two different bytes, such as 0xEB 0x09; (2) Data length, determined according to the SPI MISO FIFO depth, ensuring that the corresponding value of the entire depth can be filled, at least 1 byte; (3) Data frame ID identifier, 1 byte, increasing sequentially; (4) Business instruction data, spliced as much as possible while ensuring their integrity, in order to improve the utilization rate of this SPI MISO FIFO and improve the output data transmission efficiency of the Slave end.
[0095] The MISO (Master Input Slave Output) channel can be the Master input / Slave output channel of SPI.
[0096] The second interrupt signal can be a signal from the slave end that the data frame to be sent has been written in the MISO channel, notifying the master end that it can start reading the frame data.
[0097] The second instruction can be a frame-by-frame verification pass instruction within the frame format. Since a data frame may contain multiple service data packets, the Master needs to verify each service data packet sequentially. If all verifications pass, the frame passes; if any packet fails verification, the frame fails. When the Master sends this instruction back to the Slave, it is considered that the verification has passed, and the frame data can be successfully received. This means that the entire process of this highly robust Slave output interaction mechanism has successfully concluded, and subsequent processing only requires handling the data frame.
[0098] When the Master receives the first interrupt signal, it first determines the interrupt sequence number. If the first interrupt signal is detected, the Master responds to the first interrupt signal after completing (if any) the currently executing SPI MOSI write operation, that is, it sends the first instruction to the Slave and then stops writing data to the Slave.
[0099] When the Slave receives the first instruction, it considers the Master to have successfully responded to the first interrupt signal and begins sending the data frame to be sent to the Master through the MISO channel of the SPI channel, i.e., it begins writing the data frame to the MISO channel. Once the data frame is completely written to the MISO, it begins sending a second interrupt signal to the Master via a signal line, notifying the Master that it can begin reading frame data from the MISO channel. Upon receiving the second interrupt signal, the Master first checks the interrupt sequence number. If it detects the second interrupt signal, it performs an internal frame format verification. If the verification passes, it sends a second instruction back to the Slave, indicating successful verification. After receiving the instruction, the Master can receive the frame data written by the Slave through the MISO channel. Once the frame data is received, it can be parsed, restoring the concatenated instructions to their original state.
[0100] Based on the above technical solutions, optionally, after sending a second interrupt signal to the Master terminal via the signal line, the method further includes:
[0101] If a data frame retransmission command is received from the Master, the data to be sent will be reframed and sent through the MISO channel of the SPI channel, and a second interrupt signal will be sent to the Master again through the signal line.
[0102] A data frame retransmission command is issued when a frame re-interpretation check fails, requiring the slave to retransmit the frame data. When the check fails, the master sends a data frame retransmission command to the slave. Upon receiving this command, the slave reassembles the data to be transmitted according to the slave's high-efficiency frame protocol. After reassembly, the reassembled frame data is sent through the MISO channel; that is, the reassembled frame data is written to the MISO channel. Once writing is complete, a second interrupt signal is sent to the master via a signal line to inform the master that data writing is complete and reading can begin.
[0103] In this scheme, the data frame retransmission command can be used to resend the data frame to the Master after the Master fails to verify, thereby reducing the occurrence of abnormal situations and making the interaction between the Master and Slave highly robust.
[0104] Based on the above technical solutions, optionally, the first feedback instruction includes the Master end writing the SPI_INTR1_READ_CMD instruction to the SPIMOSI;
[0105] The second instruction in the feedback includes the Master writing READ_EMPTY_CNT times SPI_DUMMY_DATA data to SPI MOSI.
[0106] In this scheme, SPI MOSI (Master Output Slave Input) can be the channel of SPI Master output / Slave input.
[0107] The SPI_INTR1_READ_CMD instruction can be used to indicate a silent commitment to the slave. It uses a unique byte order that does not conflict with the master protocol, such as 0xAA0x55 0xFF, to avoid errors in business data during data transmission that could lead to misinterpretation of the instruction.
[0108] The SPI_INTR1_RESEND_CMD instruction can be used to indicate a silent commitment to the slave and is responsible for triggering data frame retransmission. It uses a unique byte order that does not conflict with the master protocol, such as 0xBB 0xFF 0x55, to avoid errors in service data during data transmission that could lead to misinterpretation of instructions.
[0109] READ_EMPTY_CNT can be the number of bytes of SPI_DUMMY_DATA data that need to be sent to read an empty SPI MISO FIFO (First In First Out queue), which is equal to the depth of the SPI MISO FIFO, for example, 128 bytes.
[0110] SPI_DUMMY_DATA can be a single byte of meaningless data that does not conflict with the main protocol data, such as 0x00. It is used to write SPI MISO data so that SPI MISO data can be read out through the SPI loopback mechanism.
[0111] When determining the interrupt sequence number, the READ_EMPTY_CNT and SPI_DUMMY_DATA instructions are required. The determination steps are as follows: (1) Perform a FIFO read operation, that is, send READ_EMPTY_CNT SPI_DUMMY_DATA writes and read READ_EMPTY_CNT data; (2) Determine the format of the data frame it constitutes. If the frame header is valid, it means that the data reported by the Slave has been read, the current interrupt is interrupt 2, the interaction process ends smoothly, and the subsequent business processing can continue; (3) If the frame header is invalid, it means that the current interrupt is interrupt 1 and a response is required.
[0112] To fulfill the silent commitment, the SPI_INTR1_READ_CMD instruction must be used. That is, when the Master determines that the current interrupt signal is the first interrupt signal, it responds to the SPI_INTR1_READ_CMD instruction. After this instruction, the Master cannot write any data, but should wait for the next interrupt signal from the Master.
[0113] When the first and second waiting times have elapsed, and a first and second interrupt signal needs to be sent to the Master, the SPI_INTR1_READ_CMD, READ_EMPTY_CNT, and SPI_DUMMY_DATA instructions must be used. That is, for this interrupt, if the Slave does not receive the expected response after a certain time interval following its triggering, an interrupt will be generated again. For example, after the first interrupt signal is generated, the Slave's expected action is for the Master to reply with an SPI_INTR1_READ_CMD instruction, while after the second interrupt signal is generated, the Slave's expected action is for the Master to write READ_EMPTY_CNT SPI_DUMMY_DATA values.
[0114] When the Slave needs to send an empty data frame to the Master, it needs to use the SPI_INTR1_READ_CMD instruction. That is, if the Slave receives the SPI_INTR1_READ_CMD instruction from the Master when there is no data to send, the Slave will construct a special placeholder data frame with empty service content according to the "Slave outputs efficient frame" rule, in order to release the Master's silent commitment and restore the interaction sequence.
[0115] In this solution, each instruction corresponds to a different function. When different exceptions occur, each instruction is used to resolve the corresponding exception, enabling the Slave to have functions such as exception detection and frame loss retransmission. This makes the interaction process highly robust and can cope with various situations such as hardware current interference and software asynchronous blocking, thus having high engineering practical value.
[0116] The technical solution provided in this embodiment, if a data transmission trigger event occurs, sends a first interrupt signal to the Master end via the signal line; receives a first instruction from the Master end, frames the data to be sent and sends it through the MISO channel of the SPI channel, and sends a second interrupt signal to the Master end via the signal line. The Master end then sends a second instruction based on the second interrupt signal to receive frame data from the MISO channel of the SPI channel and parse the frame data. Through the above-described SPI interaction method where the Slave end actively outputs data, the Slave end can proactively report a large amount of business information data, improving data transmission efficiency and making the interaction process highly robust. Furthermore, it reduces hardware resource consumption, saves costs, and has high engineering practical value.
[0117] Example 2
[0118] Figure 2 This is a flowchart illustrating the SPI interaction method for Slave-end active data output provided in Embodiment 2 of this application. The Slave end and the Master end are connected via an SPI channel, and the Slave end and the Master end are also connected via signal lines; the method is executed by the Master end, as follows... Figure 2 As shown, the specific steps include the following:
[0119] S201, receive the first interrupt signal sent by the Slave terminal through the signal line.
[0120] When the Slave sends the first interrupt signal, this signal will be transmitted to the Master through the signal line. After receiving the first interrupt signal, the Master will respond to the first interrupt signal.
[0121] S202, send the first instruction back to the Slave terminal.
[0122] In response to the first interrupt signal, the Master will generate the first instruction and feed this instruction back to the Slave.
[0123] S203, when the second interrupt signal is received from the Slave terminal via the signal line, a second instruction is fed back according to the second interrupt signal to read the frame data sent by the Slave terminal through the MISO channel of the SPI channel and to parse the frame data; wherein, the frame data is obtained by the Slave terminal framing the data to be sent.
[0124] Once the Slave has finished sending the frame data via the MISO channel, it sends a second interrupt signal to the Master. Upon receiving this signal, the Master responds by generating a second command and sending it back to the Slave. Simultaneously, the Master reads the frame data, receiving and parsing it to restore it to its original, unassembled state. For example, if the frame data is an assembled temperature command, the Master, upon receiving this command, first restores it to its original temperature format. The frame data is obtained by assembling the data frames to be sent using the efficient frame protocol output by the Slave.
[0125] Based on the above technical solution, optionally, after parsing the frame data, the method further includes:
[0126] If parsing fails, a data frame retransmission command is issued, prompting the Slave to reassemble the data to be sent and transmit it through the MISO channel of the SPI channel, and then send a second interrupt signal to the Master again through the signal line.
[0127] In this scheme, when the frame re-framing check fails, the Master sends a data frame retransmission command to the Slave, informing the Slave that the frame data needs to be retransmitted. After receiving this command, the Slave sends the re-framed data to be sent to the Master through the MISO channel. After the transmission is completed, it sends a second interrupt signal to the Master again through the signal line.
[0128] In this scheme, by setting a data frame retransmission command, the Master can handle the abnormal situation of frame data parsing failure, making the interaction process highly robust.
[0129] Based on the above technical solution, optionally, after receiving the first interrupt signal or the second interrupt signal, the method further includes:
[0130] Fulfill the commitment to silence.
[0131] In this scheme, after the Master receives the first interrupt signal or the second interrupt signal, it will fulfill its silent commitment and stop writing any data to the Slave. Instead, it should wait for the next interrupt signal from the Master.
[0132] In this scheme, by setting a silent commitment, the occurrence of data corruption can be reduced to a certain extent, and the efficiency of data transmission between the Master and Slave ends can be improved.
[0133] In this embodiment, a first interrupt signal from the Slave terminal is received via the signal line; a first instruction is fed back to the Slave terminal; and upon receiving a second interrupt signal from the Slave terminal via the signal line, a second instruction is fed back based on the second interrupt signal to read the frame data sent by the Slave terminal through the MISO channel of the SPI channel and to parse the frame data. The frame data is obtained by the Slave terminal framing the data to be sent. This SPI interaction method, where the Slave terminal actively outputs data, is compatible with the original write process of the Master terminal, optimizes the read process of the Master terminal, and improves data transmission efficiency, making the interaction process highly robust. Furthermore, it reduces hardware resource consumption, saves costs, and has high engineering practical value.
[0134] The SPI interaction method for Slave active data output provided in this application embodiment is similar to... Figure 1 The various processes in the method embodiments correspond to each other, and have corresponding execution processes and beneficial effects. To avoid repetition, they will not be described again here.
[0135] Example 3
[0136] Figure 3 This is a schematic diagram of the SPI interaction device that actively outputs data on the Slave side according to Embodiment 3 of this application. The Slave side is connected to the Master side via an SPI channel, and the Slave side is also connected to the Master side via a signal line; the device is configured on the Slave side, as shown below. Figure 3 As shown, it specifically includes:
[0137] The first interrupt signal sending module 301 is used to send a first interrupt signal to the Master terminal through the signal line if a data transmission trigger event exists.
[0138] The second interrupt signal sending module 302 is used to receive the first instruction fed back by the Master terminal, frame the data to be sent and send it through the MISO channel of the SPI channel, and send a second interrupt signal to the Master terminal through the signal line, so that the Master terminal can feed back a second instruction according to the second interrupt signal, so as to receive frame data from the MISO channel of the SPI channel and parse the frame data.
[0139] In this embodiment, the first interrupt signal sending module is used to send a first interrupt signal to the Master terminal via the signal line if a data transmission trigger event occurs; the second interrupt signal sending module is used to receive a first instruction from the Master terminal, frame the data to be transmitted and send it through the MISO channel of the SPI channel, and send a second interrupt signal to the Master terminal via the signal line, so that the Master terminal can send a second instruction based on the second interrupt signal to receive frame data from the MISO channel of the SPI channel and parse the frame data. Through the above-mentioned SPI interaction device where the Slave terminal actively outputs data, the Slave terminal can actively report a large amount of business information data, improving data transmission efficiency and making the interaction process highly robust. Furthermore, it reduces hardware resource consumption, saves costs, and has high engineering practical value.
[0140] The SPI interaction device for active data output by the slave end provided in this application embodiment can achieve… Figure 1 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.
[0141] Example 4
[0142] Figure 4 This is a schematic diagram of the SPI interaction device for Slave-end active data output provided in Embodiment 4 of this application. The Slave end is connected to the Master end via an SPI channel, and the Slave end is also connected to the Master end via a signal line; the device is configured on the Master end, as shown below. Figure 4 As shown, it specifically includes:
[0143] The receiving module 401 is used to receive the first interrupt signal sent by the Slave terminal through the signal line;
[0144] Feedback module 402 is used to feed back a first instruction to the Slave terminal;
[0145] The parsing module 403 is used to receive a second interrupt signal from the Slave terminal via the signal line, and to feed back a second instruction based on the second interrupt signal to read the frame data sent by the Slave terminal through the MISO channel of the SPI channel and to parse the frame data; wherein the frame data is obtained by the Slave terminal framing the data to be sent.
[0146] In this embodiment, the receiving module is used to receive a first interrupt signal from the Slave terminal via the signal line; the feedback module is used to feed back a first instruction to the Slave terminal; and the parsing module is used to, upon receiving a second interrupt signal from the Slave terminal via the signal line, feed back a second instruction based on the second interrupt signal to read frame data sent by the Slave terminal through the MISO channel of the SPI channel and parse the frame data; wherein the frame data is obtained by the Slave terminal framing the data to be sent. Through the above-described SPI interaction device where the Slave terminal actively outputs data, the original write process of the Master terminal can be maintained, the read process of the Master terminal can be optimized, and the data transmission efficiency can be improved, making the interaction process highly robust. Furthermore, it reduces hardware resource consumption, saves costs, and has high engineering practical value.
[0147] The SPI interaction device for active data output by the slave end provided in this application embodiment can achieve… Figure 2 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.
[0148] Example 5
[0149] like Figure 5 As shown, this application embodiment also provides an electronic device 500, including a processor 501, a memory 502, and a program or instructions stored in the memory 502 and executable on the processor 501. When the program or instructions are executed by the processor 501, they implement the various processes of the above-described SPI interaction method embodiment for Slave active data output and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0150] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.
[0151] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0152] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0153] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
[0154] The above description is merely a preferred embodiment and the technical principles employed in this application. This application is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions that can be made by those skilled in the art will not depart from the scope of protection of this application. Therefore, although this application has been described in detail through the above embodiments, this application is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of this application, the scope of which is determined by the scope of the claims.
Claims
1. A method for SPI interaction where the slave actively outputs data, characterized in that, The Slave terminal is connected to the Master terminal via an SPI channel, and the Slave terminal is also connected to the Master terminal via a signal line; the method is executed by the Slave terminal, and the method includes: If a data transmission trigger event occurs, a first interrupt signal is sent to the Master terminal via the signal line. The data transmission trigger event is a signal that begins transmitting data to the Master terminal. The first interrupt signal is used by the Master terminal to respond after completing the currently executing SPI MOSI write operation. Upon receiving the first instruction from the Master, the slave sends the data frame to be transmitted through the MISO channel of the SPI channel and sends a second interrupt signal to the Master via the signal line. This allows the Master to perform internal frame format verification. After successful verification, the slave sends a second instruction to receive frame data from the MISO channel of the SPI channel and parse the frame data. The first instruction is a silent commitment instruction sent by the Master to the Slave. The data frame to be transmitted is an efficient protocol frame generated by splicing multiple transmission instructions with added frame header information. The second interrupt signal is a signal from the Slave that it has finished writing the data frame to be transmitted in the MISO channel and notifies the Master to start reading the frame data. After issuing the first interrupt signal or the second interrupt signal, the process further includes: allowing the Master to fulfill a silence commitment based on the first interrupt signal or the second interrupt signal, wherein the silence commitment is that the Master will no longer write any data to the Slave and will wait for the next interrupt signal sent by the Master; if the Master fails to fulfill the silence commitment when the first interrupt signal is issued, it is marked as abnormal, the current cycle is terminated, and the first interrupt signal is re-issued to the Master via the signal line; if the Master fails to fulfill the silence commitment when the second interrupt signal is issued, it is marked as abnormal, the current cycle is terminated, the data to be sent is re-framed and sent through the MISO channel of the SPI channel, and the second interrupt signal is re-issued to the Master via the signal line. If the first interrupt signal is not sent to the Master terminal through the signal line, and the first instruction is received from the Master terminal, then an empty data frame is sent through the MISO channel of the SPI channel, and a second interrupt signal is sent to the Master terminal through the signal line, so that the Master terminal can release the silent commitment. The empty data frame is a special placeholder data frame with empty service content.
2. The method according to claim 1, characterized in that, After sending a second interrupt signal to the Master terminal via the signal line, the method further includes: If a data frame retransmission command is received from the Master, the data to be sent will be reframed and sent through the MISO channel of the SPI channel, and a second interrupt signal will be sent to the Master again through the signal line.
3. The method according to claim 1, characterized in that, After sending a first interrupt signal to the Master terminal via the signal line, the method further includes: If the first instruction is not received from the Master within the first waiting period, the first interrupt signal is resent to the Master via the signal line. After sending a second interrupt signal to the Master terminal via the signal line, the method further includes: If the second instruction is not received from the Master within the second waiting period, a second interrupt signal is sent back to the Master via the signal line.
4. The method according to claim 1, characterized in that, The first feedback instruction includes the Master end writing the SPI_INTR1_READ_CMD instruction to the SPI MOSI; The second instruction in the feedback includes the Master writing READ_EMPTY_CNT times SPI_DUMMY_DATA data to SPI MOSI.
5. An SPI interaction method in which the slave actively outputs data, characterized in that, The Slave terminal and the Master terminal are connected via an SPI channel, and the Slave terminal and the Master terminal are also connected via signal lines; the method is executed by the Master terminal, and the method includes: The first interrupt signal is received from the Slave terminal via the signal line; the first interrupt signal is used by the Master terminal to respond after completing the currently executing SPI MOSI write operation. The first instruction is fed back to the Slave terminal after the Master terminal responds, indicating a silent commitment. When the second interrupt signal is received from the Slave terminal via the signal line, an internal frame format check is performed, and a second instruction is fed back after the check passes, to read the frame data sent by the Slave terminal through the MISO channel of the SPI channel and to parse the frame data; wherein, the frame data is obtained by the Slave terminal assembling the data to be sent; the data to be sent is a high-efficiency protocol frame generated by splicing multiple data to be sent instructions with added frame header information, and the second interrupt signal is the signal that the Slave terminal has finished writing the data to be sent into the MISO channel and notifies the Master terminal to start reading the frame data; The Master receives either a first interrupt signal or a second interrupt signal from the Slave. Based on the first or second interrupt signal, the Master fulfills a silence commitment, which means that it will no longer write any data to the Slave and will wait for the next interrupt signal sent by the Master. Specifically, if the Master fails to fulfill the silence commitment upon receiving the first interrupt signal, the Slave is marked as abnormal, the current cycle is terminated, and the first interrupt signal is resent to the Master via the signal line. If the Master fails to fulfill the silence commitment upon receiving the second interrupt signal, the Slave is marked as abnormal, the current cycle is terminated, the data to be sent is re-framed and sent through the MISO channel of the SPI channel, and the second interrupt signal is resent to the Master via the signal line. If the Slave terminal does not send a first interrupt signal to the Master terminal through the signal line, and receives a first instruction from the Master terminal, it sends an empty data frame through the MISO channel of the SPI channel and sends a second interrupt signal to the Master terminal through the signal line, so that the Master terminal can release the silent commitment. The empty data frame is a special placeholder data frame with empty service content.
6. The method according to claim 5, characterized in that, After parsing the frame data, the method further includes: If parsing fails, a data frame retransmission command is issued, prompting the Slave to reassemble the data to be sent and transmit it through the MISO channel of the SPI channel, and then send a second interrupt signal to the Master again through the signal line.
7. An SPI interaction device in which the slave actively outputs data, characterized in that, The Slave terminal is connected to the Master terminal via an SPI channel, and the Slave terminal is also connected to the Master terminal via a signal line; the device is configured on the Slave terminal, and the device includes: The first interrupt signal sending module is used to send a first interrupt signal to the Master terminal via the signal line if a data transmission trigger event exists. The data transmission trigger event is a signal that starts transmitting data to the Master terminal. The first interrupt signal is used by the Master terminal to respond after completing the currently executing SPI MOSI write operation. The second interrupt signal transmission module is used to receive the first instruction fed back by the Master, send the data frame to be sent through the MISO channel of the SPI channel, and send a second interrupt signal to the Master through the signal line, so that the Master can perform frame format internal framing verification, and after the verification is successful, feed back the second instruction to receive frame data from the MISO channel of the SPI channel and parse the frame data. The first instruction is an instruction sent by the Master to the Slave indicating a silent commitment. The data frame to be sent is an efficient protocol frame generated by splicing multiple instructions to be sent with frame header information. The second interrupt signal is a signal from the Slave to the Master to start reading the frame data after writing the data frame to be sent in the MISO channel. The device is further configured to, after issuing a first interrupt signal or a second interrupt signal, enable the Master to fulfill a quiz commitment based on the first interrupt signal or the second interrupt signal, wherein the quiz commitment is that the Master will no longer write any data to the Slave and wait for the next interrupt signal sent by the Master; if the Master fails to fulfill the quiz commitment when issuing the first interrupt signal, it is marked as abnormal, the current cycle is terminated, and the first interrupt signal is re-sent to the Master via the signal line; if the Master fails to fulfill the quiz commitment when issuing the second interrupt signal, it is marked as abnormal, the current cycle is terminated, the data to be sent is re-framed and sent through the MISO channel of the SPI channel, and the second interrupt signal is re-sent to the Master via the signal line. If the first interrupt signal is not sent to the Master terminal through the signal line, and the first instruction is received from the Master terminal, then an empty data frame is sent through the MISO channel of the SPI channel, and a second interrupt signal is sent to the Master terminal through the signal line, so that the Master terminal can release the silent commitment. The empty data frame is a special placeholder data frame with empty service content.
8. An SPI interaction device in which the slave actively outputs data, characterized in that, The Slave terminal is connected to the Master terminal via an SPI channel, and the Slave terminal is also connected to the Master terminal via a signal line; the device is configured on the Master terminal, and the device includes: The receiving module is used to receive a first interrupt signal sent by the Slave terminal through the signal line; the first interrupt signal is used to transmit to the Master terminal, and the Master responds after completing the currently executing SPI MOSI write operation upon receiving it. The feedback module is used to send a first instruction to the Slave terminal; the first instruction is an instruction indicating a silent commitment sent back to the Slave terminal after the Master terminal responds. The parsing module is used to perform frame format internal segmentation verification when receiving a second interrupt signal from the Slave end via the signal line, and to perform frame format internal segmentation verification after the verification passes, and to feed back a second instruction after the verification passes, so as to read the frame data sent by the Slave end through the MISO channel of the SPI channel and parse the frame data; wherein, the frame data is obtained by the Slave end from assembling the data to be sent; the data to be sent is a high-efficiency protocol frame generated by splicing multiple instructions to be sent with frame header information added, and the second interrupt signal is the signal that the Slave end has finished writing the data to be sent into the MISO channel and notifies the Master end to start reading the frame data; The device is further configured to receive a first interrupt signal or a second interrupt signal from the Slave, and fulfill a silence commitment based on the first interrupt signal or the second interrupt signal. The silence commitment is that the Master will no longer write any data to the Slave and will wait for the next interrupt signal sent by the Master. Specifically, if the Master fails to fulfill the silence commitment upon receiving the first interrupt signal, the Slave is marked as abnormal, and the current cycle is terminated. The Slave then re-sends the first interrupt signal to the Master via the signal line. If the Master fails to fulfill the silence commitment upon receiving the second interrupt signal, the Slave is marked as abnormal, and the current cycle is terminated. The Slave then re-frames the data to be sent and re-sends it via the MISO channel of the SPI channel, and re-sends the second interrupt signal to the Master via the signal line. If the Slave terminal does not send a first interrupt signal to the Master terminal through the signal line, and receives a first instruction from the Master terminal, it sends an empty data frame through the MISO channel of the SPI channel and sends a second interrupt signal to the Master terminal through the signal line, so that the Master terminal can release the silent commitment. The empty data frame is a special placeholder data frame with empty service content.
9. An electronic device, characterized in that, The electronic device includes a Master end and a Slave end connected via an SPI channel. The Slave end can run programs or instructions, and when the programs or instructions are executed by the Slave end, they implement the steps of the SPI interaction method as described in claims 1-4 or as described in any one of claims 5-6, whereby the Slave end actively outputs data.
Citation Information
Patent Citations
SPI bus master-slave device communication system, method and apparatus based on Linux
CN111984581A
Communication method based on SPI communication
CN112214440A