CN114443549B - SPI communication method based on characteristic code stream identification - Google Patents
SPI communication method based on characteristic code stream identification Download PDFInfo
- Publication number
- CN114443549B CN114443549B CN202111395929.5A CN202111395929A CN114443549B CN 114443549 B CN114443549 B CN 114443549B CN 202111395929 A CN202111395929 A CN 202111395929A CN 114443549 B CN114443549 B CN 114443549B
- Authority
- CN
- China
- Prior art keywords
- interference
- code stream
- spi
- identification
- characteristic code
- 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.)
- Active
Links
- 238000004891 communication Methods 0.000 title claims abstract description 44
- 238000000034 method Methods 0.000 title claims abstract description 16
- 230000005540 biological transmission Effects 0.000 claims abstract description 25
- 238000001514 detection method Methods 0.000 claims abstract description 7
- 235000015429 Mirabilis expansa Nutrition 0.000 claims description 6
- 244000294411 Mirabilis expansa Species 0.000 claims description 6
- 235000013536 miso Nutrition 0.000 claims description 6
- 230000000977 initiatory effect Effects 0.000 claims description 4
- 230000004044 response Effects 0.000 claims description 4
- 230000002093 peripheral effect Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000002457 bidirectional effect Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000001360 synchronised effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/38—Information transfer, e.g. on bus
- G06F13/42—Bus transfer protocol, e.g. handshake; Synchronisation
- G06F13/4282—Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/38—Information transfer, e.g. on bus
- G06F13/382—Information transfer, e.g. on bus using universal interface adapter
- G06F13/385—Information transfer, e.g. on bus using universal interface adapter for adaptation of a particular data processing system to different peripheral devices
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Small-Scale Networks (AREA)
- Mobile Radio Communication Systems (AREA)
Abstract
The invention provides an SPI communication method based on characteristic code stream identification, a main device adopts a communication interference avoidance detection mechanism, corresponding characteristic code streams are firstly configured for the main device and a slave device of communication, and when the main device reads and writes data, a characteristic code stream identification request is firstly initiated to detect whether an SPI bus has interference; if interference exists, the master device calculates SPI bus interference backoff time delay and executes the SPI bus interference backoff time delay, and after the backoff time delay is completed, the master device initiates a characteristic code stream identification request again to detect whether the SPI bus has interference or not, so that the master device reciprocates until the interference does not exist, and the master device executes data reading and writing. The invention adopts the communication interference avoidance detection mechanism, effectively reduces the influence of interference on SPI communication in the application scene of the industrial embedded system, and improves the reliability and stability of data transmission between the master device and the slave device.
Description
Technical Field
The invention relates to the technical field of communication, in particular to a method for realizing reliable communication between SPI master and slave devices by adopting a feature code identification mode.
Background
SPI (Serial Peripheral Interface ) is a high-speed, full duplex, synchronous communication bus, with CS, SCLK, MOSI and MISO signal lines connected in sequence between master and slave devices. The bus supports full duplex communication, is simple and easy to use, has high data transmission rate, and is widely applied to communication of embedded processors and peripheral devices thereof.
The SPI communication consists of a master device and a slave device. The SPI communication is initiated by the master device, a CS chip selection signal is initiated on the SCLK signal line, and the master and slave devices complete data bidirectional transmission on the MOSI signal line (master device output slave device input) and the MISO signal line (master device input slave device output) according to the SCLK signal.
However, there is no flow control specified in the existing SPI communication scheme, and there is no reply mechanism to confirm whether data is received. In an application scene of an industrial embedded system, when SPI executes serial high-rate transmission of data content according to BIT BITs, transmission failure is often caused by influence of interference signals, and the reliability of data is greatly reduced.
The reliability of SPI communication in an embedded system is crucial, and besides adopting hardware protection measures to eliminate interference, how to improve and improve the reliability of SPI communication by using a software mode is a technical problem to be solved in the field.
Disclosure of Invention
The invention aims to solve the problem of SPI communication reliability and provides an SPI communication method based on characteristic code stream identification. The influence of interference on SPI communication in the application scene of the industrial embedded system is reduced, and the reliability and stability of data transmission between the master device and the slave device are improved.
The technical scheme of the invention is as follows:
the invention provides an SPI communication method based on characteristic code stream identification, a main device adopts a communication interference avoidance detection mechanism, namely: the method comprises the steps that corresponding characteristic code streams are configured for a master device and a slave device of communication, and when the master device reads and writes data, a characteristic code stream identification request is initiated to detect whether an SPI bus has interference or not; if interference exists, the master device calculates SPI bus interference backoff time delay and executes the SPI bus interference backoff time delay, and after the backoff time delay is completed, the master device initiates a characteristic code stream identification request again to detect whether the SPI bus has interference or not, so that the master device reciprocates until the interference does not exist, and the master device executes data reading and writing.
Further, the feature code is a BIT string sequence of continuous 0 and 1 combinations, and the BIT width N of the feature code stream is an integer multiple of 8.
Further, the feature code stream identification specifically includes:
the SPI master device initiates a characteristic code stream identification request, and sends SCLK time sequence to the slave device to read a characteristic code stream signal responded by the slave device on the MISO signal line so as to identify whether interference exists on an SPI bus or not:
if the SPI bus is not interfered, executing effective data reading sent by the follow-up slave equipment;
if the SPI bus is interfered, the main equipment calculates the interference back-off delay of the current turn and executes the interference back-off delay, and after the back-off delay is completed, the main equipment initiates a characteristic code stream identification request again to detect whether the SPI bus is interfered or not, and meanwhile, judges whether the current identification turn n is smaller than the preset maximum identification turn n or not max ;
When the identification turn n is less than or equal to n max The main equipment executes data reading and writing after the round of identification is finished without interference;
when the identification round n=n max And if interference exists, ending the SPI communication.
Further, the identifying whether the SPI bus has interference specifically includes: the SPI master device reads the characteristic code stream signals responded by the slave devices, judges whether the characteristic code stream is consistent with the preset characteristic code stream configured between the master device and the slave devices, if so, no interference exists, and if not, the interference exists.
Further, the interference back-off delay Tn of the current identification round n is obtained by adopting the following formula:
T n =2 n-1 ×T
wherein: f represents the bus rate, T represents the base slot, and n represents the current identification round.
Further, before the master device performs the identification of the feature code stream, when the SPI master device needs to communicate with the slave device, setting a CS chip select signal to be low level, and initiating a data transmission request to the slave device through an MOSI signal line; after the SPI slave device receives the data transmission request, starting the DMA to receive the buffer data; meanwhile, judging whether valid frame data sent by the main equipment are synchronously received or not; if the data is valid, filling the leading data and the response data into a DMA (direct memory access) transmission buffer area of the slave device, and starting DMA transmission; if not, no processing is performed.
Further, the preamble data is characterized by the code stream according to the maximum recognitionNumber of rounds n max A repeating BIT string; the BIT total width M of the preamble data BIT is larger than the BIT width N multiplied by the maximum identification round N of the feature code stream max Is a product of (a) and (b).
Further, the slave device data adopts a DMA transmission mode.
The invention has the beneficial effects that:
the invention adopts the communication interference avoidance detection mechanism, effectively reduces the influence of interference on SPI communication in the application scene of the industrial embedded system, and improves the reliability and stability of data transmission between the master device and the slave device.
The invention combines the characteristic code stream identification flow, effectively evades SPI bus interference, is simple and practical, saves hardware cost and improves SPI communication reliability in an embedded system.
Additional features and advantages of the invention will be set forth in the detailed description which follows.
Drawings
The foregoing and other objects, features and advantages of the invention will be apparent from the following more particular descriptions of exemplary embodiments of the invention as illustrated in the accompanying drawings wherein like reference numbers generally represent like parts throughout the exemplary embodiments of the invention.
Fig. 1 shows a flow chart of the present invention.
Detailed Description
Preferred embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While the preferred embodiments of the present invention are shown in the drawings, it should be understood that the present invention may be embodied in various forms and should not be limited to the embodiments set forth herein.
The invention provides an SPI communication method based on characteristic code stream identification, a main device adopts a communication interference avoidance detection mechanism, namely: the method comprises the steps that corresponding characteristic code streams are configured for a master device and a slave device of communication, and when the master device reads and writes data, a characteristic code stream identification request is initiated to detect whether an SPI bus has interference or not; if interference exists, the master device calculates SPI bus interference backoff time delay and executes the SPI bus interference backoff time delay, and after the backoff time delay is completed, the master device initiates a characteristic code stream identification request again to detect whether the SPI bus has interference or not, so that the master device reciprocates until the interference does not exist, and the master device executes data reading and writing;
specifically, the feature code stream identification specifically includes:
the SPI master device initiates a characteristic code stream identification request, sends SCLK time sequence to the slave device to read a characteristic code stream signal responded by the slave device on the MISO signal line, reads the characteristic code stream signal responded by the slave device, judges whether the characteristic code stream is consistent with a preset characteristic code stream configured between the master device and the slave device, if so, no interference exists, otherwise, the interference exists;
if the SPI bus is not interfered, executing effective data reading sent by the follow-up slave equipment;
if the SPI bus is interfered, the master device calculates and executes the interference back-off delay of the current turn, and the interference back-off delay Tn of the current identification turn n is obtained by adopting the following formula:
T n =2 n-1 ×T
wherein: f represents the bus rate, T represents the basic time slot, and n represents the current identification round;
after the backoff delay is completed, a characteristic code stream identification request is initiated again to detect whether the SPI bus is interfered or not, and meanwhile, whether the current identification round n is smaller than the preset maximum identification round n or not is judged max ;
When the identification turn n is less than or equal to n max The main equipment executes data reading and writing after the round of identification is finished without interference;
when the identification round n=n max And if interference exists, ending the SPI communication.
Further, before the master device performs the identification of the feature code stream, when the SPI master device needs to communicate with the slave device, setting a CS chip select signal to be low level, and initiating a data transmission request to the slave device through an MOSI signal line; after SPI slave device receives data transmission request, DMA receiving buffer is startedData; meanwhile, judging whether valid frame data sent by the main equipment are synchronously received or not; if the data is valid, filling the leading data and the response data into a DMA (direct memory access) transmission buffer area of the slave device, and starting DMA transmission; if not, not processing; the preamble data is characterized by a code stream according to the maximum identification round n max A repeating BIT string; the BIT total width M of the preamble data BIT is larger than the BIT width N multiplied by the maximum identification round N of the feature code stream max Is a product of (a) and (b).
The invention adopts the communication interference avoidance detection mechanism, effectively reduces the influence of interference on SPI communication in the application scene of the industrial embedded system, and improves the reliability and stability of data transmission between the master device and the slave device.
The specific implementation method comprises the following steps:
1) The SPI communication rate is 2Mb/s, and when the master device needs to communicate with the slave device, the CS chip select signal is set to be low level;
2) The SPI slave device starts DMA receive data.
3) The SPI master initiates a complete application protocol data frame to the slave device through the MOSI signal line.
4) The SPI reads the DMA receiving buffer from the device, and judges the validity of the application protocol.
5) And after the SPI slave device completes the judgment of the validity of the data frame, filling the lead data and the response data into the DMA transmission buffer of the slave device, and starting the DMA transmission.
The feature code stream configured between the master device and the slave device is: 0xFE, maximum identification round n max Take 5 as an example; the preamble data is: 0xFE0xFE0xFE0xFE0xFE;
6) The SPI master initiates the characteristic code stream identification, and sends SCLK time sequence to the slave to read the characteristic code stream signal responded by the slave on the MISO signal line so as to identify whether the SPI bus has interference.
7) And if the SPI master device receives the code stream identification correctly, executing effective data reading sent by the follow-up slave device. Otherwise, the main equipment repeatedly executes the characteristic code stream identification flow according to the backoff algorithm until the maximum identification round n max And (5) ending.
Wherein: the SPI master device backoff time is based on 1024BIT data transmission time T (488.2 us), the current identification round n of the characteristic code stream is combined, and the backoff time Tn of each round is determined by adopting the technology of a binary index backoff algorithm.
8) SPI master completes prescribed round n max If the characteristic code stream is identified, the subsequent effective data communication is completed, and if the effective characteristic code stream is not identified in all the used turns, the SPI communication is ended.
9) The SPI master sets the CS chip select signal high.
The foregoing description of embodiments of the invention has been presented for purposes of illustration and description, and is not intended to be exhaustive or limited to the embodiments disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the various embodiments described.
Claims (5)
1. The SPI communication method based on the characteristic code stream identification is characterized in that a main device adopts a communication interference avoidance detection mechanism, namely: the method comprises the steps that corresponding characteristic code streams are configured for a master device and a slave device of communication, and when the master device reads and writes data, a characteristic code stream identification request is initiated to detect whether an SPI bus has interference or not; if interference exists, the master device calculates SPI bus interference backoff time delay and executes the SPI bus interference backoff time delay, and after the backoff time delay is completed, the master device initiates a characteristic code stream identification request again to detect whether the SPI bus has interference or not, so that the master device reciprocates until the interference does not exist, and the master device executes data reading and writing;
the feature code is a BIT string sequence of continuous 0 and 1 combinations, and the BIT width N of the feature code stream is an integer multiple of 8;
the characteristic code stream identification specifically comprises the following steps:
the SPI master device initiates a characteristic code stream identification request, and sends SCLK time sequence to the slave device to read a characteristic code stream signal responded by the slave device on the MISO signal line so as to identify whether interference exists on an SPI bus or not: if the SPI bus is not interfered, executing effective data reading sent by the follow-up slave equipment;
if the SPI bus is interfered, the main equipment calculates the current round trunkScrambling the back-off delay and executing, after finishing the back-off delay, initiating the characteristic code stream identification request again to detect whether the SPI bus is interfered or not, and judging whether the current identification round n is smaller than the preset maximum identification round n or not max ;
When the identification turn n is less than or equal to n max The main equipment executes data reading and writing after the round of identification is finished without interference;
when the identification round n=n max If interference exists, ending the SPI communication;
the interference back-off delay Tn of the current identification round n is obtained by adopting the following formula:
T n =2 n-1 ×T
wherein: f represents the bus rate, T represents the basic time slot, and n represents the current identification round;
the feature code stream configured between the master device and the slave device is: 0xFE, and the maximum recognition round nmax is 5; the preamble data is: 0xFE0xFE0xFE.
2. The SPI communication method based on the identification of the feature code stream according to claim 1, wherein the identification of whether the SPI bus has interference specifically includes: the SPI master device reads the characteristic code stream signals responded by the slave devices, judges whether the characteristic code stream is consistent with the preset characteristic code stream configured between the master device and the slave devices, if so, no interference exists, and if not, the interference exists.
3. The SPI communication method based on the characteristic code stream identification as claimed in claim 1, wherein before the main device performs the characteristic code stream identification, when the SPI main device needs to communicate with the slave device, setting a CS chip select signal to be low level, and initiating a data transmission request to the slave device through an MOSI signal line; after the SPI slave device receives the data transmission request, starting the DMA to receive the buffer data; meanwhile, judging whether valid frame data sent by the main equipment are synchronously received or not; if the data is valid, filling the leading data and the response data into a DMA (direct memory access) transmission buffer area of the slave device, and starting DMA transmission; if not, no processing is performed.
4. A method for SPI communication based on signature stream identification as recited in claim 3, wherein the preamble data is the signature stream according to a maximum identification round n max A repeating BIT string; the BIT total width M of the preamble data BIT is larger than the BIT width N multiplied by the maximum identification round N of the feature code stream max Is a product of (a) and (b).
5. The SPI communication method based on characteristic code stream identification as recited in claim 1, wherein the slave device data adopts a DMA transmission mode.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111395929.5A CN114443549B (en) | 2021-11-23 | 2021-11-23 | SPI communication method based on characteristic code stream identification |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111395929.5A CN114443549B (en) | 2021-11-23 | 2021-11-23 | SPI communication method based on characteristic code stream identification |
Publications (2)
Publication Number | Publication Date |
---|---|
CN114443549A CN114443549A (en) | 2022-05-06 |
CN114443549B true CN114443549B (en) | 2024-03-12 |
Family
ID=81363464
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111395929.5A Active CN114443549B (en) | 2021-11-23 | 2021-11-23 | SPI communication method based on characteristic code stream identification |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114443549B (en) |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101145942A (en) * | 2007-01-04 | 2008-03-19 | 中兴通讯股份有限公司 | A serial bus failure detection method for single bus master-slave protection device |
CN102752145A (en) * | 2012-07-13 | 2012-10-24 | 临沂市拓普网络有限公司 | Novel detecting and isolating system for fault of RS-485 port and method thereof |
CN103731329A (en) * | 2012-10-12 | 2014-04-16 | 苏州工业园区新宏博通讯科技有限公司 | Anti-interference method of I2C bus communication system |
CN103778090A (en) * | 2012-10-23 | 2014-05-07 | 精工爱普生株式会社 | Serial communication circuit, integrated circuit device, physical quantity measuring device, and serial communication method |
CN107967227A (en) * | 2017-12-22 | 2018-04-27 | 苏州国芯科技有限公司 | A kind of communication means and SPI hosts, SPI slaves based on SPI |
CN108132896A (en) * | 2018-01-17 | 2018-06-08 | 西安闻泰电子科技有限公司 | Data transmission method and device |
CN109088677A (en) * | 2018-08-23 | 2018-12-25 | 国网江苏省电力有限公司盐城供电分公司 | A kind of anti-interference automatic checkout system of communication equipment |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108475241B (en) * | 2016-09-29 | 2021-01-05 | 华为技术有限公司 | SPI-based data transmission method and device |
-
2021
- 2021-11-23 CN CN202111395929.5A patent/CN114443549B/en active Active
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101145942A (en) * | 2007-01-04 | 2008-03-19 | 中兴通讯股份有限公司 | A serial bus failure detection method for single bus master-slave protection device |
CN102752145A (en) * | 2012-07-13 | 2012-10-24 | 临沂市拓普网络有限公司 | Novel detecting and isolating system for fault of RS-485 port and method thereof |
CN103731329A (en) * | 2012-10-12 | 2014-04-16 | 苏州工业园区新宏博通讯科技有限公司 | Anti-interference method of I2C bus communication system |
CN103778090A (en) * | 2012-10-23 | 2014-05-07 | 精工爱普生株式会社 | Serial communication circuit, integrated circuit device, physical quantity measuring device, and serial communication method |
CN107967227A (en) * | 2017-12-22 | 2018-04-27 | 苏州国芯科技有限公司 | A kind of communication means and SPI hosts, SPI slaves based on SPI |
CN108132896A (en) * | 2018-01-17 | 2018-06-08 | 西安闻泰电子科技有限公司 | Data transmission method and device |
CN109088677A (en) * | 2018-08-23 | 2018-12-25 | 国网江苏省电力有限公司盐城供电分公司 | A kind of anti-interference automatic checkout system of communication equipment |
Also Published As
Publication number | Publication date |
---|---|
CN114443549A (en) | 2022-05-06 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
KR101921357B1 (en) | Method and device for increasing the data transmission capacity in a serial bus system | |
US7019664B2 (en) | Reading protocol for transponders of electronic identification system | |
US7308516B2 (en) | Bi-directional serial interface for communication control | |
US7619984B2 (en) | Mechanism for error handling of corrupted repeating primitives during frame reception | |
CA2632560A1 (en) | Universal serial bus (usb) extension | |
EP3129893A1 (en) | Single-wire interface bus transceiver system based on i2c-bus, and associated method for communication of single-wire interface bus | |
US7634692B2 (en) | SATA primitive prediction and correction | |
US8553717B2 (en) | Information processing device, communication method, and program product | |
US20050063458A1 (en) | Communication control method and system | |
US20090323723A1 (en) | Wireless communication apparatus and packet transfer method thereof | |
US8654377B2 (en) | Data communication device, communication control method, and program | |
WO1995014276A2 (en) | Method and apparatus for achieving high speed data transfer from a parallel port | |
JPH05122282A (en) | Data transmission system | |
CN111694776B (en) | Method and device for identifying communication interface in chip | |
CN114443549B (en) | SPI communication method based on characteristic code stream identification | |
CN113220607B (en) | Data processing method based on FIFO | |
CN108072779A (en) | A kind of digital oscilloscope CAN bus baud rate automatic identifying method | |
US5175750A (en) | Application specific integrated circuit for a serial data bus | |
CN101894005A (en) | Asynchronous FIFO transmission method from high-speed interfaces to low-speed interfaces | |
US5721891A (en) | Detection of N length bit serial communication stream | |
CN107786309B (en) | Chip data transmission method and system free of clock synchronization and electronic equipment | |
JP3914398B2 (en) | IC card reader / writer communication method | |
JPH0918461A (en) | Data receiver | |
US20050083836A1 (en) | Flow control for interfaces providing retransmission | |
CN116192998B (en) | Method, device and equipment for decoding power transmission protocol information packet |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |