CN102495818A - Method for improving communication speed rate of software-mode serial peripheral interface (SPI) - Google Patents
Method for improving communication speed rate of software-mode serial peripheral interface (SPI) Download PDFInfo
- Publication number
- CN102495818A CN102495818A CN2011104071591A CN201110407159A CN102495818A CN 102495818 A CN102495818 A CN 102495818A CN 2011104071591 A CN2011104071591 A CN 2011104071591A CN 201110407159 A CN201110407159 A CN 201110407159A CN 102495818 A CN102495818 A CN 102495818A
- Authority
- CN
- China
- Prior art keywords
- spi
- data
- dma
- sent
- traffic rate
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Landscapes
- Information Transfer Systems (AREA)
Abstract
The invention discloses a method for improving the communication speed rate of a software-mode serial peripheral interface (SPI). Based on the operation of a direct memory access (DMA), data are directly input from a memory to a general purpose input output (GPIO) data register in a mode of non-interference of a central processing unit (CPU). The communication speed rate depends on the data transportation data of the DMA and the overturning speed of the GPIO instead of the performance of the CPU. Therefore, the communication speed rate of the software-mode SPI can be greatly improved, and the working efficiency of a system is improved.
Description
Technical field
The present invention relates to a kind of method that improves software mode SPI traffic rate, being particularly useful for clock rate has the upper limit or product chips selected, and circuit structure is the system of malleable not.
Background technology
The full name of SPI interface is " Serial Peripheral Interface ", means SPI, be a kind of high speed, full duplex, synchronous communication bus, and line is simple, saves circuit space, has obtained in recent years using very widely.
In the SPI communication at present, it is that mode (promptly producing high-low level through GPIO (general input and output) port) simulation SPI communication protocol and the slave unit that main frame adopts software communicates that application is greatly arranged.Especially some usually not integrated SPI modules among the general single chip controller chip MCU of low sides relatively, main frame is just more general with the application mode of software mode simulation SPI port.
Fig. 1 is the synoptic diagram of the present software mode SPI method that generally adopts; The software mode SPI communication of generally adopting at present is that the mode that at first SPI communication data to be sent is compared through CPU by turn converts serial data (0/1) to; Drive and data-driven (upset of GPIO port) at the clock that the GPIO port produces SPI communication needs according to serial data then; This whole process need is accomplished under CPU control, has taken a large amount of cpu resources.
This method is convenient feasible, and the requirement of having saved the integrated SPI module of controller has also reduced hardware cost, has shortened the construction cycle.But need a large amount of CPU processing time of cost owing on the GPIO port, produce upset through software mode simulation SPI communication; The fastest traffic rate of system is subject to system works frequency and CPU handling property; Communication speed is difficult to improve, and becomes the bottleneck of this application mode.
Summary of the invention
The invention provides a kind of method that improves software mode SPI traffic rate, improved the work efficiency of software mode SPI traffic rate and system greatly.
In order to achieve the above object, the present invention provides a kind of method that improves software mode SPI traffic rate, comprises following steps:
Step 1, the single-chip microprocessor MCU system is carried out initialization;
Step 2, setting SPI communications protocol;
Step 3, foundation are used for SPI data parsing to be sent is become the parsing array [0-f] of GPIO port driver data;
Step 4, SPI data to be sent are resolved to the driving array that is used to drive the GPIO port through the parsing array in the step 3;
Step 5, be that the DMA transmission creates continuous memory block;
Step 6, dma module is correctly disposed, for the SPI data are sent ready;
Step 7, startup DMA transmission, the SPI data communication waveform of generation software simulation on the GPIO port;
Whether step 8, inspection data to be sent have all been sent and have been accomplished, and accomplish then program withdraws from if send, and begin data transmission next time otherwise return step 4 preparation.
In the described step 1, initialization comprises configuration preloading, configurable clock generator frequency, interrupts being provided with, disposing Peripheral Interface GPIO and dma module.
In the described step 2, the rising edge or the negative edge that are set at system clock CLK read the data on the SPI data line MOSI line, the data of set sending be the LSB low level formerly or the MSB uimsbf unsigned integer most significant bit first.
In the described step 3, resolve array [0-f] and be specifically designed to a mapping method that SPI data conversion to be sent is become GPIO port driver data.
In the described step 5, the memory block is created among the SRAM SRAM.
In the described step 6, enable dma module and DMA and interrupt, byte of every transmission can produce one and accomplish interruption, and then sends another byte through the parsing array list of looking in the step 3.
The present invention has improved the work efficiency of software mode SPI traffic rate and system greatly.
Description of drawings
Fig. 1 is the synoptic diagram of software mode SPI method in the background technology;
Fig. 2 is the module frame chart of general single chip controller chip MCU;
Fig. 3 is a functional schematic of the present invention;
Fig. 4 is a process flow diagram of the present invention;
Fig. 5 is the oscillogram that the present invention is verified.
Embodiment
Following according to Fig. 2~Fig. 5, specify preferred embodiment of the present invention.Wherein Fig. 2 has provided the module frame chart of a general MCU, comprises CPU, read only memory ROM, SRAM SRAM, flash memory Flash, universal input/output interface GPIO, UART Universal Asynchronous Receiver Transmitter UART, SPI SPI, DASD DMA, timer TIMER and watchdog circuit Watchdog etc.In plurality of applications, except the SPI interface module of using single-chip microprocessor MCU to carry, also can simulate other universal serial bus through GPIO, realize some function like the SPI interface.
Simulation universal serial bus among the common MCU; Like SPI, adopt CPU control GPIO mode, efficient and performance are lower; The present invention proposes a kind of method that improves software mode SPI traffic rate; Based on dma operation, under the mode of not intervening through CPU, with data directly from memory write to the GPIO data register.
Direct Memory Access (DASD) is a kind of high-speed data transmission operation; Allow direct read data between external apparatus and the storer; Neither pass through CPU; Also do not need CPU to intervene, whole data transfer operation carries out under a module controls that is called " dma controller ".CPU is except doing some work of treatment when data transmission begins and finish, CPU can proceed other work in communication process.Like this, in the most of the time, CPU and DMA, GPIO module are in parallel work-flow, and traffic rate no longer depends on the system works frequency, but by the speed of DMA carrying data and the reversal rate decision of GPIO.Therefore, the traffic rate of software SPI can improve greatly, and system works efficient also is improved.
Fig. 3 is the present invention residing position in the SPI communications applications; Be that the present invention is the improvement to software mode simulation SPI method; Can replace the SPI sending module to realize that the high speed SPI data send, and can under the constant situation of system clock, improve the traffic rate that software mode SPI sends.
As shown in Figure 4, the present invention provides a kind of method that improves software mode SPI traffic rate, comprises following steps:
Step 1, the single-chip microprocessor MCU system is carried out initialization;
Usually the MCU system initialization comprises configuration preloading, configurable clock generator frequency (like 48MHz), interrupts being provided with, and the initialization of part Peripheral Interface;
Among the present invention, Peripheral Interface has used GPIO and DMA, so need GP configuring IO and dma module;
Step 2, setting SPI communications protocol;
The rising edge of system clock CLK reads the data on the SPI data line MOSI line, and low level formerly;
The present invention is modeled as example with SPI; The SPI interface has 4 signal: MOSI (master goes out from going into); MISO (master goes into from going out), CLK (SPI clock), SS (slave unit selection); May be prescribed as in the SPI agreement at CLK rising edge or negative edge and read the data on the MOSI line, the data that also can select to send be LSB (low level) formerly or MSB (high position) formerly;
Step 3, foundation are used for SPI data parsing to be sent is become the parsing array [0-f] of GPIO port driver data;
This is resolved array [0-f] and is specifically designed to a mapping method that SPI data conversion to be sent is become GPIO port driver data, is that the DMA carrying is carried out a pretreated committed step to data to be sent before, and the step of setting up this array is following:
Simulation SPI sends 4bit data 0000b, and the GPIO data register (is supposed GPIO totally 8 pins, used the 3rd, No. 4 pin of GPIO in the embodiments of the invention, be respectively clock line CCK, data line MOSI; If 0x00 representes 8 pins outputs of GPIO, can see and have only the 3rd, No. 4 signal in the present embodiment in upset) data that should write in proper order are: 0x00,0x04; 0x00,0x04,0x00; 0x04,0x00,0x04; For small end MCU, the source data that DMA source data district store when using the word mode to visit is 0x04000400,0x04000400; And for big end MCU, the source data that DMA source data district store when using the word mode to visit is 0x00040004,0x00040004.Sending 1-f can analogize, and creates parsing array that DMA simulation SPI sends 4bit (0-f) table look-up as follows (0x00-0xff can be combined by following table, and following table is an example with small end MCU):
DMA transmits data | The SPI output data |
0x04000400,0x04000400 | 0x0 |
0x04000400,0x0c080400 | 0x1 |
0x04000400,0x04000c08 | 0x2 |
0x04000400,0x0c080c08 | 0x3 |
0x0c080400,0x04000400 | 0x4 |
0x0c080400,0x0c080400 | 0x5 |
0x0c080400,0x04000c08 | 0x6 |
0x0c080400,0x0c080c08 | 0x7 |
0x04000c08,0x04000400 | 0x8 |
0x04000c08,0x0c080400 | 0x9 |
0x04000c08,0x04000c08 | 0xa |
0x04000c08,0x0c080c08 | 0xb |
0x0c080c08,0x04000400 | 0xc |
0x0c080c08,0x0c080400 | 0xd |
0x0c080c08,0x04000c08 | 0xe |
0x0c080c08,0x0c080c08 | 0xf |
Step 4, SPI data to be sent are resolved to the driving array that is used to drive the GPIO port through the parsing array in the step 3;
Utilize the parsing array in the step 3; The resolution table that data to be sent (0x00-0xff) are obtained with step 3 converts the data (can adopt lookup table mode) of actual transmission to, is exactly [0x0c080400,0x0c080c08 such as the driving data of sending 0x78; 0x7; 0x04000c08,0x04000400,0x8].0x00-0xff is splitted into the combination of 0x0-0xf, and purpose is the size for the parsing array that reduces storage.
Step 5, be that the DMA transmission creates continuous memory block;
This memory block is created among the SRAM SRAM (memory module that MCU has), and data (being the form in the step 3) after the storing and resolving continuously in SRAM SRAM are for the DMA carrying is prepared;
Step 6, dma module is correctly disposed, for the SPI data are sent ready:
Enable dma module and DMA and interrupt, byte of every transmission can produce one and accomplish interruption, and then sends another byte through the table of looking in the step 3;
Step 7, startup DMA transmission, the SPI data communication waveform of generation software simulation on the GPIO port;
Whether step 8, inspection data to be sent have all been sent and have been accomplished, and accomplish then program withdraws from if send, and begin data transmission next time otherwise return step 4 preparation.
The technical scheme that the present invention adopts is based on built-in DMA controller (DMAC) and the GPIO module that general MCU provides, under not through the mode of CPU intervention with data directly from memory write to the GPIO data register.Pass through analysis protocol efficiently simultaneously, the assurance communication data can be simulated SPI communication protocol thereby can produce correct port driver through dma mode by fast resolving and correct tissue.
Fig. 5 is the GPIO port upset waveform that this method is verified, can know that by waveform the drive waveforms that the GPIO port produces meets the requirement of SPI communication protocol fully, can realize software SPI communication function.
By A-T in Fig. 5 frame; The A-B chronometric data can be known; The byte transmission speed that produces software simulation SPI waveform through hardware resource combination in the chip of this paper proposition is about 1us/byte; Be 8M bps, and the transmission speed that produces software simulation SPI waveform by MCU under the identical systems clock condition is about 1M bps, traffic rate improves more than 8 times.
The invention solves the technological difficulties that run in software simulation SPI communication at present, provide and utilize in the chip hardware resource combination under the constant condition of system clock and then realize more high-performance and more the SPI delivery plan of rapid rate.Can solve the application bottleneck of software simulation SPI mode.Through above technology, can under the constant situation of system clock, promote more than 8 times the transmission rate of software simulation SPI.
Although content of the present invention has been done detailed introduction through above-mentioned preferred embodiment, will be appreciated that above-mentioned description should not be considered to limitation of the present invention.After those skilled in the art have read foregoing, for multiple modification of the present invention with to substitute all will be conspicuous.Therefore, protection scope of the present invention should be limited appended claim.
Claims (6)
1. method that improves software mode SPI traffic rate is characterized in that the method includes the steps of:
Step 1, the single-chip microprocessor MCU system is carried out initialization;
Step 2, setting SPI communications protocol;
Step 3, foundation are used for SPI data parsing to be sent is become the parsing array [0-f] of GPIO port driver data;
Step 4, SPI data to be sent are resolved to the driving array that is used to drive the GPIO port through the parsing array in the step 3;
Step 5, be that the DMA transmission creates continuous memory block;
Step 6, dma module is correctly disposed, for the SPI data are sent ready;
Step 7, startup DMA transmission, the SPI data communication waveform of generation software simulation on the GPIO port;
Whether step 8, inspection data to be sent have all been sent and have been accomplished, and accomplish then program withdraws from if send, and begin data transmission next time otherwise return step 4 preparation.
2. the method for raising software mode SPI traffic rate as claimed in claim 1 is characterized in that, in the described step 1, initialization comprises configuration preloading, configurable clock generator frequency, interrupts being provided with, disposing Peripheral Interface GPIO and dma module.
3. the method for raising software mode SPI traffic rate as claimed in claim 1; It is characterized in that; In the described step 2; The rising edge or the negative edge that are set at system clock CLK read the data on the SPI data line MOSI line, the data of set sending be the LSB low level formerly or the MSB uimsbf unsigned integer most significant bit first.
4. the method for raising software mode SPI traffic rate as claimed in claim 1 is characterized in that, in the described step 3, resolves array [0-f] and is specifically designed to a mapping method that SPI data conversion to be sent is become GPIO port driver data.
5. the method for raising software mode SPI traffic rate as claimed in claim 1 is characterized in that in the described step 5, the memory block is created among the SRAM SRAM.
6. the method for raising software mode SPI traffic rate as claimed in claim 1; It is characterized in that, in the described step 6, enable dma module and DMA and interrupt; Byte of every transmission can produce one and accomplish interruption, and then sends another byte through the parsing array list of looking in the step 3.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2011104071591A CN102495818A (en) | 2011-12-09 | 2011-12-09 | Method for improving communication speed rate of software-mode serial peripheral interface (SPI) |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2011104071591A CN102495818A (en) | 2011-12-09 | 2011-12-09 | Method for improving communication speed rate of software-mode serial peripheral interface (SPI) |
Publications (1)
Publication Number | Publication Date |
---|---|
CN102495818A true CN102495818A (en) | 2012-06-13 |
Family
ID=46187643
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN2011104071591A Pending CN102495818A (en) | 2011-12-09 | 2011-12-09 | Method for improving communication speed rate of software-mode serial peripheral interface (SPI) |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102495818A (en) |
Cited By (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103036567A (en) * | 2012-12-24 | 2013-04-10 | 长沙威胜能源产业技术有限公司 | Sampling method for analog-digital conversion chip |
CN103176931A (en) * | 2011-12-26 | 2013-06-26 | 安凯(广州)微电子技术有限公司 | Improved DMA communication method and improved DMA communication device |
CN103345455A (en) * | 2013-06-28 | 2013-10-09 | 深圳市科曼医疗设备有限公司 | Monitor and multi-MCU stored data exchanging device thereof |
CN104331385A (en) * | 2014-11-26 | 2015-02-04 | 上海爱信诺航芯电子科技有限公司 | High-speed semi-hardware realization method for serial peripheral interface |
CN108959136A (en) * | 2018-06-26 | 2018-12-07 | 豪威科技(上海)有限公司 | Data delivery acceleration device, system and data transmission method based on SPI |
CN109344098A (en) * | 2018-09-04 | 2019-02-15 | 广州视源电子科技股份有限公司 | Data manipulation method and device between master-slave equipment |
CN109857686A (en) * | 2019-03-26 | 2019-06-07 | 北京简约纳电子有限公司 | A kind of method that DMA data synchronous transfer becomes asynchronous transmission |
CN109933293A (en) * | 2019-03-25 | 2019-06-25 | 深圳忆联信息系统有限公司 | Method for writing data, device and computer equipment based on SpiFlash |
CN112069103A (en) * | 2020-09-07 | 2020-12-11 | 歌尔科技有限公司 | Method and system for communication between multiple modules and host |
CN117312221A (en) * | 2023-11-28 | 2023-12-29 | 西安现代控制技术研究所 | Triggering type SPI data communication method |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101382927A (en) * | 2008-09-25 | 2009-03-11 | 杭州爱威芯科技有限公司 | High speed serial peripheral interface circuit integrated in chip |
CN201336032Y (en) * | 2009-01-22 | 2009-10-28 | 天津理工大学 | Software simulation serial data transmission device |
-
2011
- 2011-12-09 CN CN2011104071591A patent/CN102495818A/en active Pending
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101382927A (en) * | 2008-09-25 | 2009-03-11 | 杭州爱威芯科技有限公司 | High speed serial peripheral interface circuit integrated in chip |
CN201336032Y (en) * | 2009-01-22 | 2009-10-28 | 天津理工大学 | Software simulation serial data transmission device |
Cited By (17)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103176931A (en) * | 2011-12-26 | 2013-06-26 | 安凯(广州)微电子技术有限公司 | Improved DMA communication method and improved DMA communication device |
CN103176931B (en) * | 2011-12-26 | 2016-03-09 | 安凯(广州)微电子技术有限公司 | A kind of DMA communication means of improvement and device |
CN103036567A (en) * | 2012-12-24 | 2013-04-10 | 长沙威胜能源产业技术有限公司 | Sampling method for analog-digital conversion chip |
CN103036567B (en) * | 2012-12-24 | 2015-11-11 | 威胜能源产业技术有限公司 | For the method for sampling of modulus conversion chip |
CN103345455A (en) * | 2013-06-28 | 2013-10-09 | 深圳市科曼医疗设备有限公司 | Monitor and multi-MCU stored data exchanging device thereof |
CN103345455B (en) * | 2013-06-28 | 2016-03-30 | 深圳市科曼医疗设备有限公司 | Patient monitor and many MCU internal storage data switch thereof |
CN104331385A (en) * | 2014-11-26 | 2015-02-04 | 上海爱信诺航芯电子科技有限公司 | High-speed semi-hardware realization method for serial peripheral interface |
CN108959136B (en) * | 2018-06-26 | 2020-12-25 | 豪威科技(上海)有限公司 | SPI-based data transmission accelerating device and system and data transmission method |
CN108959136A (en) * | 2018-06-26 | 2018-12-07 | 豪威科技(上海)有限公司 | Data delivery acceleration device, system and data transmission method based on SPI |
CN109344098A (en) * | 2018-09-04 | 2019-02-15 | 广州视源电子科技股份有限公司 | Data manipulation method and device between master-slave equipment |
CN109933293A (en) * | 2019-03-25 | 2019-06-25 | 深圳忆联信息系统有限公司 | Method for writing data, device and computer equipment based on SpiFlash |
CN109933293B (en) * | 2019-03-25 | 2022-06-07 | 深圳忆联信息系统有限公司 | Data writing method and device based on SpiFlash and computer equipment |
CN109857686A (en) * | 2019-03-26 | 2019-06-07 | 北京简约纳电子有限公司 | A kind of method that DMA data synchronous transfer becomes asynchronous transmission |
CN109857686B (en) * | 2019-03-26 | 2020-12-29 | 北京简约纳电子有限公司 | Method for converting synchronous transmission of DMA data into asynchronous transmission |
CN112069103A (en) * | 2020-09-07 | 2020-12-11 | 歌尔科技有限公司 | Method and system for communication between multiple modules and host |
CN117312221A (en) * | 2023-11-28 | 2023-12-29 | 西安现代控制技术研究所 | Triggering type SPI data communication method |
CN117312221B (en) * | 2023-11-28 | 2024-03-15 | 西安现代控制技术研究所 | Triggering type SPI data communication method |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102495818A (en) | Method for improving communication speed rate of software-mode serial peripheral interface (SPI) | |
US10055376B1 (en) | Serial peripheral interface system with slave expander | |
CN104809094A (en) | SPI (Serial Peripheral Interface) controller and communication method for SPI controller | |
TW201710921A (en) | Dynamic data-link selection over common physical interface | |
CN101599053A (en) | Support the serial interface controller and the control method of multiple transport protocols | |
US9710422B2 (en) | Low cost low overhead serial interface for power management and other ICs | |
CN103559156A (en) | Communication system between FPGA (field programmable gate array) and computer | |
CN103034602B (en) | A kind of content search chip based on peripheral component interconnect bus and system | |
CN104901859A (en) | AXI/PCIE bus converting device | |
CN106970894A (en) | A kind of FPGA isomery accelerator cards based on Arria10 | |
CN113760748A (en) | FPGA prototype verification device and method | |
CN1928576A (en) | Chip testing system and method | |
CN114817114B (en) | MIPI interface, control method, device and medium thereof | |
CN104090519A (en) | System for being in communication with PLC extended module and implementation method thereof | |
CN102082577B (en) | High-speed cyclic redundancy check (CRC) device and implementation method thereof | |
Kim et al. | Low power FPGA-SoC design techniques for CNN-based object detection accelerator | |
WO2017071429A1 (en) | Data access method and bus | |
CN112256331B (en) | Virtual machine instruction analysis acceleration method and device and computer storage medium | |
Kavianipour et al. | High performance FPGA-based scatter/gather DMA interface for PCIe | |
CN105224359A (en) | Program loading method | |
US8659318B1 (en) | Systems and methods for implementing tristate signaling by using encapsulated unidirectional signals | |
CN104836639A (en) | Data transmission method capable of transmitting multiple algorithm parameters | |
CN104331385A (en) | High-speed semi-hardware realization method for serial peripheral interface | |
CN105512072A (en) | Conversion device based on APB (advanced peripheral bus) and OPB (on-chip peripheral bus) | |
US20150127865A1 (en) | Method and apparatus use with interrupts |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C12 | Rejection of a patent application after its publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20120613 |