Method and system for SPI (Serial Peripheral Interface) data transmission, slave equipment and master equipment
By setting up the receiving DMA and sending DMA in the slave device, independent control of the received data and sent data is solved, and the existing SPI communication method is not suitable for one-question interactive scenarios, achieving efficient data transmission.
Patent Information
- Application Number
- CN202411766366.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-03-25
AI Technical Summary
The existing SPI communication method is not suitable for data transmission between master and slave in a Q&A interactive scenario.
By setting the receiving DMA and sending DMA in the slave device, independent control of the received data and sending data is achieved. The receiving DMA is used to receive data sent by the master device, and the sending DMA is used to send data to the master device to be returned.
The data transmission between the master and slave devices in a Q&A interactive scenario is realized, and the efficiency and accuracy of data transmission are improved.
Smart Images

Figure CN119690896A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data transmission, for example, to a method and system for SPI data transmission, a slave device, and a master device. Background Art
[0002] SPI (Serial Peripheral Interface) is a high-speed, full-duplex, synchronous communication bus. It uses a master-slave architecture and supports one master device to control one or more slave devices. The SPI interface generally uses 4 lines: serial clock line (SCK), master input / slave output data line (MISO), master output / slave input data line (MOSI), and low-level effective slave select line (CS). SPI can transmit data simultaneously in both sending and receiving directions. Therefore, it is mainly used for synchronous serial data transmission between CPU (Central Processing Unit) and various peripheral devices.
[0003] However, for the one-question-one-answer interaction scenario between the SE (Secure Element) smart card and external devices (such as readers and writers), there is no data that needs to be transmitted synchronously between the smart card and the external device. Therefore, the existing SPI communication method is not suitable for the one-question-one-answer interaction scenario between the master device and the slave device. Therefore, how to realize the data transmission between the master device and the slave device in the one-question-one-answer interaction scenario is an urgent problem to be solved.
[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0005] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical components or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.
[0006] The embodiments of the present disclosure provide a method and system for SPI data transmission, a slave device, and a master device, so as to realize data transmission in a question-and-answer interaction scenario between the master device and the slave device.
[0007] In some embodiments, the method for SPI data transmission is applied to a slave device, and the slave device is provided with a receiving direct memory access DMA (Direct Memory Access) and a sending DMA, the receiving DMA is used to receive data sent by a master device, and the sending DMA is used to send data to the master device. The method includes: using the receiving DMA to receive data sent by the master device; parsing and processing the data sent by the master device and obtaining the data to be returned; and using the sending DMA to send the data to be returned to the master device.
[0008] In some embodiments, using the receiving DMA to receive data sent by the master device includes: configuring parameters of the receiving DMA; using the configured receiving DMA to receive data sent by the master device; determining whether a first preset signal sent by the master device is received, and if the first preset signal is received, determining that the reception of the data sent by the master device is completed.
[0009] In some embodiments, using the sending DMA to send the data to be returned to the master device includes: configuring parameters of the sending DMA; using the configured sending DMA to send the data to be returned to the master device; determining whether a second preset signal sent by the master device is received, and when the second preset signal is received, determining that sending the data to be returned to the master device is completed based on the remaining number of data to be returned.
[0010] In some embodiments, before using the sending DMA to send the data to be returned to the master device, it also includes: configuring parameters for the receiving DMA for the next data reception.
[0011] In some embodiments, after using the sending DMA to send the data to be returned to the master device, the method further includes: using the configured receiving DMA to receive the data sent by the master device next time.
[0012] In some embodiments, the data to be returned is sent to the master device using a configured send DMA, including: sending a preset notification signal to the master device and triggering the master device to return a preset clock signal; upon receiving the clock signal returned by the master device, sending the data to be returned to the master device using the configured send DMA.
[0013] In some embodiments, the method for SPI data transmission is applied to a master device, and the method includes: sending data to a slave device, triggering the slave device to use a receive DMA to receive data sent by the master device, wherein the receive DMA is set in the slave device, and the receive DMA is used to receive data sent by the master device; receiving data returned by the slave device using a send DMA, wherein the send DMA is set in the slave device, and the send DMA is used to send data to the master device.
[0014] In some embodiments, the slave device includes a first processor and a first memory storing program instructions, and the first processor is configured to execute the above-mentioned method for SPI data transmission when running the program instructions.
[0015] In some embodiments, the master device includes a second processor and a second memory storing program instructions, and the second processor is configured to execute the above-mentioned method for SPI data transmission when running the program instructions.
[0016] In some embodiments, the system for SPI data transmission includes: a master device, configured to send data to a slave device, and receive data returned by the slave device after completing the data sending to the slave device; a slave device, provided with a receive DMA and a transmit DMA, the receive DMA being used to receive data sent by the master device, the transmit DMA being used to send data to the master device, the slave device being configured to receive data sent by the master device using the receive DMA, parse and process the data sent by the master device, obtain data to be returned, and send the data to be returned to the master device using the transmit DMA.
[0017] The method and system, slave device, and master device for SPI data transmission provided by the embodiments of the present disclosure can achieve the following technical effects: the slave device sets the receiving DMA and the sending DMA so that the slave device can independently control the receiving data and the sending data according to the receiving DMA channel and the sending DMA channel respectively. After receiving the data through the receiving DMA, the sending DMA is used to send the data to be returned to the master device. That is, the return data is sent only after the data reception is completed. Thereby, data transmission between the master device and the slave device in a question-and-answer interaction scenario is realized.
[0018] The above general description and the following description are exemplary and explanatory only and are not intended to limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] One or more embodiments are exemplarily described by corresponding drawings, which do not limit the embodiments. Elements with the same reference numerals in the drawings are shown as similar elements, and the drawings do not constitute a scale limitation, and wherein:
[0020] Figure 1 is a schematic diagram of a system environment for SPI data transmission provided by an embodiment of the present disclosure;
[0021] Figure 2 is a schematic diagram of a method for SPI data transmission provided by an embodiment of the present disclosure;
[0022] Figure 3 is a schematic diagram of another method for SPI data transmission provided by an embodiment of the present disclosure;
[0023] Figure 4 is a schematic diagram of another method for SPI data transmission provided by an embodiment of the present disclosure;
[0024] Figure 5 is a schematic diagram of another method for SPI data transmission provided by an embodiment of the present disclosure;
[0025] Figure 6 is a schematic diagram of the structure of a slave device provided by an embodiment of the present disclosure;
[0026] Figure 7 It is a structural diagram of a main device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0027] In order to be able to understand the features and technical contents of the embodiments of the present disclosure in more detail, the implementation of the embodiments of the present disclosure is described in detail below in conjunction with the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present disclosure. In the following technical description, for the convenience of explanation, a full understanding of the disclosed embodiments is provided through multiple details. However, one or more embodiments can still be implemented without these details. In other cases, to simplify the drawings, well-known structures and devices can be simplified for display.
[0028] The terms "first", "second", etc. in the specification and claims of the embodiments of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so that the embodiments of the embodiments of the present disclosure described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.
[0029] Unless otherwise stated, the term "plurality" means two or more.
[0030] In the embodiment of the present disclosure, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B indicates: A or B.
[0031] The term "and / or" is a description of the association relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or, A and B.
[0032] The term "correspondence" may refer to an association relationship or a binding relationship. The correspondence between A and B means that there is an association relationship or a binding relationship between A and B.
[0033] Take the SE smart card as the slave device and the external device (such as the reader) as the master device. In the scenario of a question-and-answer interaction between the SE smart card and the reader. The reader sends a query or command to the smart card. After receiving the query or command from the reader, the smart card processes the query or command according to its own functions and stored data, and sends the processing results or related data back to the reader. It can be seen that there is no data that needs to be transmitted synchronously between the smart card and the reader. The smart card receives data separately and then sends data separately. In the embodiment of the present disclosure, by setting the receive DMA and the send DMA from the slave device, the slave device can independently control the receive data and the send data according to the receive DMA channel and the send DMA channel. And after receiving the data through the receive DMA, the send DMA is used to send the data to be returned to the master device. After receiving the data separately, the data is sent separately. Thereby, the data transmission between the master device and the slave device in the question-and-answer interaction scenario is realized.
[0034] Combination Figure 1 The embodiment of the present disclosure provides a system for SPI data transmission, including a master device 101 and a slave device 102. The slave device is provided with a receiving DMA and a sending DMA, the receiving DMA is used to receive data sent by the master device, and the sending DMA is used to send data to the master device. The master device 101 is configured to send data to the slave device. And after sending the completed data to the slave device, the slave device receives the data returned by the slave device. The slave device 102 is configured to receive the data sent by the master device using the receiving DMA. The data sent by the master device is parsed and processed, and the data to be returned is obtained. Then, the data to be returned is sent to the master device using the sending DMA.
[0035] By using the system for SPI data transmission provided by the embodiment of the present disclosure, the slave device sets the receiving DMA and the sending DMA so that the slave device can independently control the receiving data and the sending data according to the receiving DMA channel and the sending DMA channel respectively. After receiving the data through the receiving DMA, the sending DMA is used to send the data to be returned to the master device. That is, the return data is sent only after the data reception is completed. Thus, data transmission between the master device and the slave device in a question-and-answer interaction scenario is realized.
[0036] Combination Figure 2 As shown, an embodiment of the present disclosure provides a method for SPI data transmission, which is applied to a slave device. The method includes:
[0037] Step S201, the slave device receives data sent by the master device using the receive DMA.
[0038] Step S202: The slave device parses and processes the data sent by the master device and obtains the data to be returned.
[0039] Step S203: The slave device sends the data to be returned to the master device by using the send DMA.
[0040] By adopting the method for SPI data transmission provided by the embodiment of the present disclosure, the slave device sets the receiving DMA and the sending DMA so that the slave device can independently control the receiving data and the sending data according to the receiving DMA channel and the sending DMA channel respectively. After receiving the data through the receiving DMA, the sending DMA is used to send the data to be returned to the master device. That is, the return data is sent only after the data reception is completed. Thus, data transmission between the master device and the slave device in a question-and-answer interaction scenario is realized.
[0041] Furthermore, receiving data sent by the master device using the receiving DMA includes: configuring parameters for the receiving DMA. Using the configured receiving DMA to receive data sent by the master device. Determining whether a first preset signal sent by the master device is received, and determining that the data sent by the master device is received when the first preset signal is received. In this way, data reception is individually controlled through an independent receiving DMA channel, so that the slave device can receive data individually. And receiving data through the receiving DMA hardware can improve the efficiency of receiving data from the slave device without the intervention of the processor.
[0042] The parameter configuration of the receiving DMA includes: configuring one or more of the source address, the destination address, the data length and the receiving buffer. For example, the receiving buffer and the data length of the receiving DMA are configured to be a first preset value. The first preset value is a maximum value agreed upon by both parties in advance. For example, 261 bytes. Because the SPI slave device does not know the length of the data to be sent by the master device, the receiving buffer and the data length are configured to be larger so that the frame data of any length of the master device can be fully received.
[0043] Further, using the configured receiving DMA to receive the data sent by the master device includes: when a falling edge of CS (Chip Select) sent by the master device is received, using the configured receiving DMA to receive the data sent by the master device.
[0044] Among them, when the CS falling edge is received, the receiving DMA is started by the preset first enabling start signal, so that the slave device is in a data receiving state, that is, the configured receiving DMA is used to receive data. In this way, data is received by receiving DMA hardware without the intervention of the processor, which can improve the efficiency of receiving data from the slave device, thereby improving the efficiency of SPI communication. In addition, the receiving DMA is started for data reception only when the CS falling edge is received, ensuring the alignment of the received data frame.
[0045] The slave device determines that it has received the CS falling edge sent by the master device by detecting that the CS pin changes from a high level to a low level.
[0046] The first preset signal is a CS rising edge. The slave device determines that a CS rising edge sent by the master device is received by detecting that the CS pin changes from a low level to a high level.
[0047] In one embodiment, during the process of receiving data sent by the master device using the configured receiving DMA from the slave device, the slave device is in a state of receiving data. When the slave device is in the data receiving state, when the slave device receives the CS rising edge sent by the master device, it is determined that the data sent by the master device is received. The CS rising edge is determined as a data reception completion mark. Then the processor of the slave device parses and processes the received data to obtain the data to be returned. The data to be returned is placed in the sending buffer.
[0048] Furthermore, using the sending DMA to send the data to be returned to the master device includes: configuring the parameters of the sending DMA. Using the configured sending DMA to send the data to be returned to the master device. Determining whether a second preset signal sent by the master device is received, and in the case of receiving the second preset signal, determining that the sending of the data to be returned to the master device is completed according to the remaining number of data to be returned. In this way, the sending data is individually controlled through an independent sending DMA channel, so that the slave device can send data independently. And by sending data through the sending DMA hardware, the processor does not need to be intervened, which can improve the efficiency of receiving and sending from the slave device.
[0049] The parameter configuration of the sending DMA includes: configuring one or more of the source address, the destination address, the data length and the sending buffer. For example, the buffer and the data length of the sending DMA are configured to the second preset value. The second preset value is the length of the sending data.
[0050] Further, using the configured sending DMA to send the data to be returned to the master device includes: when receiving the CS falling edge sent by the master device, using the configured sending DMA to send the data to be returned to the master device.
[0051] Among them, after the slave device receives the data sent by the master device using the receiving DMA, the data is parsed and processed, and the data to be returned is obtained. After the data to be returned is placed in the sending buffer, when the CS falling edge is received, the sending DMA is started by the preset second enable start signal, so that the slave device is in a state of data sending, that is, the configured sending DMA is used to send data. In this way, data is sent by sending DMA hardware without the intervention of the processor, which can improve the efficiency of sending data from the slave device, thereby improving the efficiency of SPI communication. In addition, the sending DMA is started to send data only when the CS falling edge is received to ensure the alignment of the sent data frame.
[0052] When a second preset signal is received, determining that sending the data to be returned to the main device is completed according to the remaining number of data to be returned includes: when a second preset signal is received and the remaining number of data to be returned is 0, determining that sending the data to be returned to the main device is completed.
[0053] The second preset signal is a CS rising edge. The slave device determines that a CS rising edge sent by the master device is received by detecting that the CS pin changes from a low level to a high level.
[0054] In one embodiment, when the slave device is sending data to the master device using the configured send DMA, the slave device is in a data sending state. When the slave device is in the data sending state, when the slave device receives a CS rising edge sent by the master device and the remaining amount of data to be returned is 0, it is determined that the data sending to the master device is completed. The CS rising edge is determined as a data sending completion mark.
[0055] Optionally, the configured send DMA is used to send the data to be returned to the master device, including: sending a preset notification signal to the master device and triggering the master device to return a preset clock signal; when the clock signal returned by the master device is received, the configured send DMA is used to send the data to be returned to the master device.
[0056] The SPI interface is also provided with a Notify line. The slave device pulls up the Notify pin to send a preset notification signal to the master device, and triggers the master device to generate a clock signal.
[0057] In some embodiments, after configuring the send DMA parameters, the slave device sends a preset notification signal to the master device by pulling up the Notify pin when receiving the CS falling edge sent by the master device, and triggers the master device to generate a clock signal. When the slave device receives the clock signal sent by the master device, it uses the configured send DMA to send the data to be returned to the master device.
[0058] Optionally, the data to be returned includes a preset frame header and target return data. Using the configured send DMA to send the data to be returned to the master device includes: using the configured send DMA to send the preset frame header to the master device, and when the preset frame header is received by the master device, using the configured send DMA to send the target return data to the master device. The preset frame header includes the length of the target return data.
[0059] In some embodiments, after the slave device configures the transmit DMA parameters, upon receiving the falling edge of CS sent by the master device, the slave device uses the configured transmit DMA to send a preset frame header to the master device. The master device reads the data sent by the slave device at a preset frequency to receive the preset frame header sent by the slave device. When the preset frame header sent by the slave device is received by the master device, the configured transmit DMA is used to send the target return data to the master device. The preset frame header includes a frame length.
[0060] In this embodiment, the slave device supports the master device to poll and read the data to be returned multiple times. For example, the slave device supports the master device to first read the frame header to obtain the frame length, and then read the subsequent target return data. This can ensure the accuracy of the data returned by the slave device.
[0061] Optionally, the slave device is provided with a bit counter. The bit counter is used to track the number of data bits currently transmitted. The method for SPI data transmission also includes: the slave device resets the bit counter when receiving the CS rising edge sent by the master device. In this way, at the end of each data transmission, the bit counter is reset, so that the byte misalignment and frame misalignment can be limited to a certain communication, rather than errors after errors. Thereby, the accuracy of data transmission can be improved.
[0062] Optionally, the method for SPI data transmission further includes: when the slave device receives the falling edge of CS sent by the master device, resetting the bit counter. In this way, the bit counter is reset each time data transmission starts, which can ensure the byte alignment and frame alignment of the current communication. Thus, the accuracy of data transmission can be improved.
[0063] In some embodiments, when the slave device is dormant and awakened by the SPI interface, the slave device clock starts and starts to receive data, but the master device may have sent several CLKs (Clock, clock signal), resulting in byte misalignment and frame misalignment of the data received by the slave device. In addition, the CLK pin may cause the slave device to parse out more bits due to jitter, resulting in the data being unable to be byte-aligned. In addition, when the slave device enables SPI reception or transmission, the SPI may be in communication, then the number of CLKs is uncertain, resulting in byte misalignment and frame misalignment of the slave device receiving or sending. Therefore, in the disclosed embodiment, when the slave device receives the CS rising edge and / or CS falling edge sent by the master device, the bit counter is reset. Thereby increasing the probability of byte alignment and frame alignment during data transmission, and further improving the accuracy of SPI communication data transmission.
[0064] Furthermore, before using the sending DMA to send the data to be returned to the master device, the method further includes: configuring parameters for the receiving DMA for receiving data next time.
[0065] Furthermore, after sending the data to be returned to the master device by using the sending DMA, the method further includes: using the configured receiving DMA to receive the data sent by the master device next time.
[0066] Since the master device may immediately send the next data after the slave device sends the data to be returned. In this embodiment, after the slave device parses the data sent by the master device and obtains the data to be returned, and before sending the data to be returned, the receiving DMA is configured with parameters for the next data reception. And after sending the data to be returned to the master device, the configured receiving DMA is used in time to receive the next data. After the slave device returns the data to be returned, it enters the data receiving mode in time, ensuring the timeliness and integrity of the data reception. It avoids the situation where the slave device cannot receive the data in time after sending the data to be returned, resulting in incomplete data reception.
[0067] Further, using the configured receiving DMA to receive the data sent by the master device next time includes: after determining that the sending of the to-be-returned data to the master device is completed, when receiving the CS falling edge sent by the master device, using the configured receiving DMA to receive the data sent by the master device next time. In this way, data is received by receiving DMA hardware without the intervention of the processor, which can improve the efficiency of receiving data from the slave device.
[0068] Combination Figure 3 As shown, the embodiment of the present disclosure provides another method for SPI data transmission, including:
[0069] Step S301, the slave device configures parameters for the receiving DMA. For example, when the slave device is powered on for the first time, the receiving DMA is configured with parameters.
[0070] Step S302: When the slave device receives the falling edge of CS sent by the master device, the slave device uses the configured receiving DMA to receive the data sent by the master device.
[0071] Step S303, when the slave device receives the CS rising edge sent by the master device, it determines that the data reception is completed. The reception completion state is clarified. Among them, the SPI generates an interrupt through the CS rising edge so that the processor can parse and process the received data.
[0072] Step S304, the slave device parses and processes the received data, obtains the data to be returned, and places the data to be returned in a sending buffer.
[0073] Step S305: the slave device configures the receiving DMA parameters again to prepare for the next data reception.
[0074] Step S306: The slave device configures parameters for sending DMA.
[0075] Step S307, when the slave device receives the CS falling edge sent by the master device, it uses the configured send DMA to send the data to be returned to the master device.
[0076] Step S308: When the slave device receives the CS rising edge sent by the master device and the remaining amount of data to be returned is 0, it determines that the data transmission to the master device is completed, thus clarifying the transmission completion status.
[0077] Step S309: When the slave device receives the falling edge of CS sent by the master device, it uses the reconfigured receiving DMA to receive the data sent by the master device next time, and then returns to step S303.
[0078] The slave device receives data through an independent receiving DMA channel, and after receiving the data sent by the master device, it sends the data to be returned to the master device through an independent sending DMA channel. And after sending the data to be returned, data is received. This realizes a question-and-answer communication method in which the slave device and the master device receive data separately and then send data separately. In addition, data is received through receiving DMA, and an interrupt is generated by receiving the rising edge of CS to let the MCU (Micro Controller Unit) perceive the completion of receiving a frame of data. Then the data is sent, and after the sending is completed, the hardware automatically switches to the receiving data mode, which greatly reduces the time occupied by the MCU, avoids the problem of missing data and byte misalignment of the slave device, and greatly improves the efficiency of parallel processing of multiple communication interfaces of the slave device, such as SE chip.
[0079] Combination Figure 4 As shown, an embodiment of the present disclosure provides a method for SPI data transmission, which is applied to a master device, and the method includes:
[0080] Step S401, the master device sends data to the slave device, triggering the slave device to use the receiving DMA to receive the data sent by the master device, wherein the receiving DMA is set in the slave device, and the receiving DMA is used to receive the data sent by the master device;
[0081] Step S402, the master device receives data returned by the slave device using a send DMA, wherein the send DMA is set in the slave device and is used to send data to the master device.
[0082] By using the method for SPI data transmission provided by the embodiment of the present disclosure, the slave device can independently control the receiving data and the sending data according to the receiving DMA channel and the sending DMA channel. In this way, the master device can receive the returned data after sending the data. Thus, data transmission between the master device and the slave device in a question-and-answer interaction scenario is realized.
[0083] Further, the master device sends data to the slave device, including: when the master device sends a CS falling edge to the slave device, the master device sends data to the slave device. When the data transmission is completed, the master device sends a CS rising edge to the slave device. The master device notifies the slave device that the data transmission is completed by sending a rising edge to the slave device. The master device sends a CS falling edge to the slave device by pulling the CS pin low. The master device sends a CS rising edge to the slave device by pulling the CS pin high.
[0084] Optionally, the master device receives the data returned by the slave device by sending DMA, including: receiving the data returned by the slave device by sending DMA when the master device receives a preset notification signal sent by the slave device.
[0085] Optionally, the data returned from the slave device includes a preset frame header and target return data. The master device receives the data returned by the slave device using the send DMA, including: the master device reads the preset frame header sent by the slave device according to a preset frequency, and when the preset frame header is read, receives the target return data sent by the slave device using the send DMA. In this way, the master device continuously polls and reads the return data from the slave device until the frame header agreed by both parties is received, and then it is considered that the slave device has started to send data, and then receives other data.
[0086] Combination Figure 5 As shown, the embodiment of the present disclosure provides another method for SPI data transmission, including:
[0087] Step S501, the slave device configures parameters for the receiving DMA. For example, when the slave device is powered on for the first time, the slave device configures parameters for the receiving DMA.
[0088] Step S502: The master device sends a CS falling edge to the slave device.
[0089] Step S503: The slave device receives the CS falling edge sent by the master device.
[0090] Step S504: the master device sends data to the slave device.
[0091] Step S505: The slave device receives the data sent by the master device using the configured receiving DMA.
[0092] Step S506: The master device sends a CS rising edge to the slave device.
[0093] Step S507, the slave device receives the CS rising edge sent by the master device and determines that the data has been received.
[0094] Step S508, the slave device parses and processes the received data, obtains the data to be returned, and places the data to be returned in a sending buffer.
[0095] Step S509: the slave device configures the receiving DMA parameters again to prepare for the next data reception.
[0096] Step S510: The slave device configures parameters for sending DMA.
[0097] Step S511: the master device sends a CS falling edge to the slave device.
[0098] Step S512: The slave device receives the CS falling edge sent by the master device.
[0099] Step S513: The slave device sends the data to be returned to the master device using the configured send DMA.
[0100] Step S514: the master device receives the to-be-returned data returned by the slave device.
[0101] Step S515: the master device sends a CS rising edge to the slave device.
[0102] Step S516: When the slave device receives the CS rising edge sent by the master device and the remaining amount of data to be returned is 0, it determines that the data transmission to the master device is completed.
[0103] Step S517: the master device sends a CS falling edge to the slave device.
[0104] Step S518: the master device sends data to the slave device again.
[0105] Step S519: The slave device uses the reconfigured receiving DMA to receive the data sent again by the master device.
[0106] The slave device receives data through an independent receive DMA channel, and after receiving the data sent by the master device, it sends the data to be returned to the master device through an independent send DMA channel. And after sending the data to be returned, data is received. This realizes a question-and-answer communication method in which the slave device and the master device receive data separately and then send data separately. In addition, data is received through the receive DMA, and the rising edge of CS is received, and then an interrupt is generated to let the processor sense the completion of a frame of data reception. Then the data is sent, and after the sending is completed, the hardware automatically switches to the receive data mode, which greatly reduces the time occupied by the processor, avoids the problem of missed data and byte misalignment of the slave device, and greatly improves the efficiency of parallel processing of multiple communication interfaces of the slave device.
[0107] Combination Figure 6As shown, an embodiment of the present disclosure provides a slave device 600, including a first processor (processor) 604 and a first memory (memory) 601 storing program instructions. Optionally, the slave device may also include a first communication interface (Communication Interface) 602 and a first bus 603. Among them, the first processor 604, the first communication interface 602, and the first memory 601 can communicate with each other through the first bus 603. The first communication interface 602 can be used for information transmission. The first processor 604 can call the program instructions in the first memory 601 to execute the method for SPI data transmission of the above embodiment.
[0108] In addition, the logic instructions in the first memory 601 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
[0109] The first memory 601 is a computer-readable storage medium that can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the method in the embodiment of the present disclosure. The first processor 604 executes the function application and data processing by running the program instructions / modules stored in the first memory 601, that is, implementing the method for SPI data transmission in the above embodiment.
[0110] The first memory 601 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the first memory 601 may include a high-speed random access memory and may also include a non-volatile memory.
[0111] Combination Figure 7 As shown, an embodiment of the present disclosure provides a master device 700, including a second processor (processor) 704 and a second memory (memory) 701 storing program instructions. Optionally, the slave device may also include a second communication interface (Communication Interface) 702 and a second bus 703. Among them, the second processor 704, the second communication interface 702, and the second memory 701 can communicate with each other through the second bus 703. The second communication interface 702 can be used for information transmission. The second processor 704 can call the program instructions in the second memory 701 to execute the method for SPI data transmission of the above embodiment.
[0112] In addition, the logic instructions in the second memory 701 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
[0113] The second memory 701 is a computer-readable storage medium that can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the method in the embodiment of the present disclosure. The second processor 704 executes the function application and data processing by running the program instructions / modules stored in the second memory 701, that is, implementing the method for SPI data transmission in the above embodiment.
[0114] The second memory 701 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the second memory 701 may include a high-speed random access memory and may also include a non-volatile memory.
[0115] The technical solution of the embodiment of the present disclosure can be embodied in the form of a software product, which is stored in a storage medium and includes one or more instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the embodiment of the present disclosure. The aforementioned storage medium may be a non-transient storage medium, including: a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk, and other media that can store program codes, or a transient storage medium.
[0116] The above description and the accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent only possible changes. Unless explicitly required, separate components and functions are optional, and the order of operation may vary. The parts and features of some embodiments may be included in or replace the parts and features of other embodiments. Moreover, the words used in this application are only used to describe the embodiments and are not used to limit the claims. As used in the description of the embodiments and the claims, unless the context clearly indicates, the singular forms of "a", "an" and "the" are intended to include plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of listings containing one or more associated ones. In addition, when used in the present application, the term "comprise" and its variants "comprises" and / or comprising refer to the presence of stated features, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the presence of other identical elements in the process, method or device comprising the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same and similar parts between the various embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.
[0117] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software may depend on the specific application and design constraints of the technical solution. The technicians may use different methods for each specific application to implement the described functions, but such implementations should not be considered to exceed the scope of the embodiments of the present disclosure. The technicians may clearly understand that, for the convenience and simplicity of description, the specific working processes of the systems, devices and units described above may refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.
[0118] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units can be only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to implement this embodiment. In addition, each functional unit in the embodiment of the present disclosure may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.
[0119] The flowchart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and the block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.
Claims
1. A method for SPI data transmission, characterized in that, Applied to a slave device, the slave device is provided with a receiving DMA and a sending DMA, the receiving DMA is used to receive data sent by a master device, and the sending DMA is used to send data to the master device, the method comprises: Utilize the receiving DMA to receive data sent by the master device; Parsing and processing the data sent by the master device, and obtaining the data to be returned; The data to be returned is sent to the master device using the sending DMA.
2. The method according to claim 1, characterized in that Receiving data sent by the master device using the receiving DMA includes: Performing parameter configuration on the receiving DMA; Use the configured receive DMA to receive the data sent by the master device; It is determined whether a first preset signal sent by the master device is received, and if the first preset signal is received, it is determined that the reception of the data sent by the master device is completed.
3. The method according to claim 1, characterized in that Using the sending DMA to send the to-be-returned data to the master device includes: Performing parameter configuration on the sending DMA; Send the data to be returned to the master device using the configured send DMA; Determine whether a second preset signal sent by the master device is received, and if the second preset signal is received, determine that sending the data to be returned to the master device is completed according to the remaining amount of the data to be returned.
4. The method according to claim 1, characterized in that Before using the sending DMA to send the data to be returned to the master device, the method further includes: configuring parameters for the receiving DMA for receiving data next time.
5. The method according to claim 4, characterized in that After using the sending DMA to send the data to be returned to the master device, the method further includes: using the configured receiving DMA to receive the data sent by the master device next time.
6. The method according to claim 3, characterized in that: Using the configured transmit DMA to send the data to be returned to the master device includes: Send a preset notification signal to the master device and trigger the master device to return a preset clock signal; When the clock signal returned by the master device is received, the data to be returned is sent to the master device using the configured sending DMA.
7. A method for SPI data transmission, characterized in that: Applicable to main equipment, including: Sending data to the slave device, triggering the slave device to receive the data sent by the master device using a receiving DMA, wherein the receiving DMA is set in the slave device, and the receiving DMA is used to receive the data sent by the master device; The data returned by the slave device using a sending DMA is received, wherein the sending DMA is set in the slave device, and the sending DMA is used to send data to the master device.
8. A slave device, comprising a first processor and a first memory storing program instructions, characterized in that: The first processor is configured to execute the method for SPI data transmission according to any one of claims 1 to 6 when running the program instructions.
9. A host device, comprising a second processor and a second memory storing program instructions, characterized in that: The second processor is configured to execute the method for SPI data transmission according to claim 7 when running the program instructions.
10. A system for SPI data transmission, characterized in that: include: The master device is configured to send data to the slave device and receive data returned by the slave device after sending the data to the slave device. The slave device is provided with a receiving DMA and a sending DMA, wherein the receiving DMA is used to receive data sent by the master device, and the sending DMA is used to send data to the master device. The slave device is configured to receive data sent by the master device using the receiving DMA, parse and process the data sent by the master device, obtain data to be returned, and send the data to be returned to the master device using the sending DMA.