CN114726482B - SPI data transmission method - Google Patents

SPI data transmission method Download PDF

Info

Publication number
CN114726482B
CN114726482B CN202210403772.4A CN202210403772A CN114726482B CN 114726482 B CN114726482 B CN 114726482B CN 202210403772 A CN202210403772 A CN 202210403772A CN 114726482 B CN114726482 B CN 114726482B
Authority
CN
China
Prior art keywords
data
spi
received value
master device
slave device
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
Application number
CN202210403772.4A
Other languages
Chinese (zh)
Other versions
CN114726482A (en
Inventor
古秋翔
徐飞飞
何丹
邱玺
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chengdu Chuangkesheng Electronic Technology Co ltd
Original Assignee
Chengdu Chuangkesheng Electronic Technology Co ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Chengdu Chuangkesheng Electronic Technology Co ltd filed Critical Chengdu Chuangkesheng Electronic Technology Co ltd
Priority to CN202210403772.4A priority Critical patent/CN114726482B/en
Publication of CN114726482A publication Critical patent/CN114726482A/en
Application granted granted Critical
Publication of CN114726482B publication Critical patent/CN114726482B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • H04L1/0078Avoidance of errors by organising the transmitted data in a format specifically designed to deal with errors, e.g. location
    • H04L1/009Avoidance of errors by organising the transmitted data in a format specifically designed to deal with errors, e.g. location arrangements specific to transmitters
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/40Bus structure
    • G06F13/4063Device-to-bus coupling
    • G06F13/4068Electrical coupling
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • H04L1/0078Avoidance of errors by organising the transmitted data in a format specifically designed to deal with errors, e.g. location
    • H04L1/0091Avoidance of errors by organising the transmitted data in a format specifically designed to deal with errors, e.g. location arrangements specific to receivers, e.g. format detection
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • H04L1/12Arrangements for detecting or preventing errors in the information received by using return channel
    • H04L1/16Arrangements for detecting or preventing errors in the information received by using return channel in which the return channel carries supervisory signals, e.g. repetition request signals
    • H04L1/1607Details of the supervisory signal
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • H04L1/12Arrangements for detecting or preventing errors in the information received by using return channel
    • H04L1/16Arrangements for detecting or preventing errors in the information received by using return channel in which the return channel carries supervisory signals, e.g. repetition request signals
    • H04L1/18Automatic repetition systems, e.g. Van Duuren systems
    • H04L1/1867Arrangements specially adapted for the transmitter end

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Detection And Prevention Of Errors In Transmission (AREA)

Abstract

The invention discloses an SPI data transmission method, which is used for communication between a master device and a slave device through SPI, and comprises the following steps: a. transmitting data; b. generating a slave device side checksum; c. generating a master device end checksum; d. and comparing the master equipment end checksum with the equipment end checksum and judging the correctness of the transmission according to the comparison result. The invention can effectively detect the error of data transmission, solve the problem of data packet loss in the conventional SPI communication and improve the accuracy and stability of the communication.

Description

SPI data transmission method
Technical Field
The invention relates to a communication technology, in particular to an SPI data transmission checking method.
Background
SPI (Serial Peripheral Interfacer serial peripheral interface) is a synchronous serial communication interface developed by Motorola, inc. for serial connection between a microprocessor and a controller and peripheral expansion chip.
SPI is a high-speed, full duplex, synchronous communication bus, and only occupies four wires on the pin of chip, has practiced thrift the pin of chip, saves space on the overall arrangement of PCB simultaneously, provides the convenience, just because of this kind of simple easy-to-use characteristic, and this kind of communication protocol has been integrated to the chip of increasing now.
The SPI interface is used for synchronous serial data transmission between the CPU and the peripheral low-speed device, under the shift pulse of the main device, the data is transmitted according to the bit, the high bit is in front, the low bit is in back, and the full duplex communication is performed, so that the data transmission speed is generally faster than that of the I2C bus, and the speed can reach several Mbps.
The prior art has the defects that SPI communication is directly carried out between the processors through a digital isolation chip, and the following defects are caused: in the case of too fast data transmission or other interference, the data may be lost, resulting in communication data errors and software BUG.
Disclosure of Invention
In order to overcome the defects, the invention aims to provide an SPI data transmission method which is used for master equipment and slave equipment to realize SPI communication, so that the problem of data packet loss in the conventional SPI communication can be solved, and the accuracy and stability of the communication are improved.
In order to achieve the above purpose, the invention is realized by adopting the following technical scheme:
the SPI data transmission method disclosed by the invention is used for the communication between the master equipment and the slave equipment through the SPI, and comprises the following steps:
a. transmitting data: the method comprises the steps that a master device sends first data to a slave device and the first data are stored locally in the master device;
b. generating a slave device side checksum: after receiving the received value of the first data, the slave device sends second data related to the received value of the first data to the master device; calculating to generate third data according to a preset operation rule through the received value of the first data and the second data, and sending the third data to the main equipment;
c. generating a master device side checksum: after receiving the received value of the second data and the received value of the third data, the main equipment calculates the received values of the first data and the second data according to the preset operation rule to generate fourth data;
d. comparing the master device side checksum with the device side checksum: and comparing the received value of the third data with the fourth data, and judging that the transmitted data is correct when the received value of the third data is the same as the fourth data.
The third data is the check sum of the slave equipment end, and the fourth data is the check sum of the master equipment end.
Further, in step d, the method further comprises:
and c, when the received value of the third data is different from the fourth data, judging that the transmitted data is incorrect, and re-executing the step a.
Of course, after detecting the error of data transmission, the data can be retransmitted until the data is detected to be correct, and then the next group of data is transmitted.
Preferably, the receiving values of the first data and the first data are both 8-bit data, and the receiving values of the second data and the second data are both 16-bit data.
For a 16-bit microprocessor, the data transferred is typically in bytes or words.
Further preferably, the received value of the first data is address information of a register, and the second data is data information of the register. For accomplishing the master to read the register data in the slave, the data is typically buffered for transmission through the registers.
Preferably, the predetermined operation rule is as follows:
and exclusive-or the 8bit data with the high 8 bits of the 16bit data and exclusive-or the low 8 bits of the 16bit data. By adopting the operation rule, when the received value of the first data and/or the received value of the second data and/or the received value of the third data are incorrect, the received value of the third data is inconsistent with the received value of the fourth data, and errors in data transmission can be effectively detected.
Further preferably, the predetermined operation rule is enhanced as follows:
and performing AND operation on the result generated after the 8bit data is exclusive-or and the upper 8 bits of the 16bit data are exclusive-or and the lower 8 bits of the 16bit data and 0x 400.
The AND operation can effectively avoid the situation that the data at the two ends of the master equipment and the slave equipment are simultaneously misplaced to cause verification to pass, and further ensures the correctness of communication.
Preferably, clocks of the master device and the slave device are synchronized.
Further preferably, the master device and the slave device use the same clock.
The invention can effectively detect the error of data transmission, solve the problem of data packet loss in the prior SPI communication, and improve the accuracy and stability of the communication; and software BUG can be avoided.
Drawings
FIG. 1 is a flow chart of the present invention.
Fig. 2 is a schematic diagram of a data format of embodiment 3.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings, in order to make the objects, technical solutions and advantages of the present invention more apparent.
Example 1
As shown in fig. 1, this embodiment discloses an SPI data transmission method, which is used for communicating between a master device and a slave device through an SPI, and includes the following steps:
a. the method comprises the steps that a master device sends first data to a slave device and the first data are stored locally in the master device;
b. after receiving the received value of the first data, the slave device sends second data related to the received value of the first data to the master device; calculating to generate third data according to a preset operation rule through the received value of the first data and the second data, and sending the third data to the main equipment;
c. after receiving the received value of the second data and the received value of the third data, the main equipment calculates the received values of the first data and the second data according to the preset operation rule to generate fourth data;
d. and comparing the received value of the third data with the fourth data, and judging that the transmitted data is correct when the received value of the third data is the same as the fourth data.
And c, when the received value of the third data is different from the fourth data, judging that the transmitted data is incorrect, and re-executing the step a.
The clocks of the master device and the slave device are synchronous, and preferably the same clock is adopted by the master device and the slave device. The receiving values of the first data and the first data are both 8-bit data, and the receiving values of the second data and the second data are both 16-bit data.
The predetermined operation rule is as follows:
and performing exclusive OR operation on the 8-bit data and the upper 8 bits and the lower 8 bits of the 16-bit data respectively.
Example 2
The present embodiment differs from embodiment 1 in that a predetermined operation rule is adopted as follows:
and performing exclusive OR operation on the 8-bit data and the upper 8 bits and the lower 8 bits of the 16-bit data respectively, and performing AND operation on the result generated after the exclusive OR operation and the 0x 400.
Example 3
As shown in fig. 2, on the basis of embodiment 2, this embodiment discloses an example of SPI data transmission, specifically as follows:
the host A and the slave B communicate through SPI and use the same clock, the host A sends the register information reg_num needed by 8 bits to the slave B, meanwhile, the host A stores the sending information locally, after the slave B receives the 8bit information reg_num, the register information needed by the host A is sent to the host 16bit-value, and then a checksum_sum is automatically calculated and sent to the host A, and the specific calculation method is as follows:
8bit information reg_num received from the slave B is exclusive or the upper 8 bits of the upper value, exclusive or the lower 8 bits of the upper value, and finally, the upper 0x400 is used as a tag bit, and the following formula is adopted:
check_sum=(reg_num~⊕valueH8⊕valueL8)&0x400
in the above formula: value H8 is the upper 8 bits of value and value L8 is the lower 8 bits of value.
After receiving the 16bit_value, the host calculates whether the checksum of the local reg_sum and the received value is consistent with the checksum sent by the slave B through the same algorithm. If so, the set of data is deemed correct, otherwise, the set of data is retransmitted.
The purpose of the above 0x400 is to prevent the data on both sides from being misplaced at the same time, which results in verification passing, but the actual data has problems.
The invention can effectively detect the error of data transmission, solve the problem of data packet loss in the prior SPI communication, and improve the accuracy and stability of the communication; and software BUG can be avoided.
Of course, the present invention is capable of other various embodiments and its several details are capable of modification and variation in light of the present invention by one skilled in the art without departing from the spirit and scope of the invention as defined in the appended claims.

Claims (4)

1. The SPI data transmission method is used for the communication between the master device and the slave device through the SPI and is characterized by comprising the following steps:
a. transmitting data: the method comprises the steps that a master device sends first data to a slave device and the first data are stored locally in the master device;
b. generating a slave device side checksum: after receiving the received value of the first data, the slave device sends second data related to the received value of the first data to the master device; calculating to generate third data according to a preset operation rule through the received value of the first data and the second data, and sending the third data to the main equipment;
c. generating a master device side checksum: after receiving the received value of the second data and the received value of the third data, the main equipment calculates the received values of the first data and the second data according to the preset operation rule to generate fourth data;
d. comparing the master device side checksum with the device side checksum: comparing the received value of the third data with the fourth data, and judging that the transmitted data is correct when the received value of the third data is the same as the fourth data;
the receiving values of the first data and the first data are 8-bit data, and the receiving values of the second data and the second data are 16-bit data;
the receiving value of the first data is the address information of a register, and the second data is the data information of the register;
the predetermined operation rule is as follows:
exclusive-or the 8bit data with the high 8bit of the 16bit data and exclusive-or the low 8bit of the 16bit data;
alternatively, the predetermined operation rule is as follows:
and performing AND operation on the result generated after the 8bit data is exclusive-or and the upper 8 bits of the 16bit data are exclusive-or and the lower 8 bits of the 16bit data and 0x 400.
2. The SPI data transmission method according to claim 1, characterized in that: in step d, further comprising:
and c, when the received value of the third data is different from the fourth data, judging that the transmitted data is incorrect, and re-executing the step a.
3. The SPI data transmission method according to claim 1, characterized in that: the clocks of the master device and the slave device are synchronous.
4. A SPI data transmission method according to claim 3, characterized in that: the master device and the slave device adopt the same clock.
CN202210403772.4A 2022-04-18 2022-04-18 SPI data transmission method Active CN114726482B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210403772.4A CN114726482B (en) 2022-04-18 2022-04-18 SPI data transmission method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210403772.4A CN114726482B (en) 2022-04-18 2022-04-18 SPI data transmission method

Publications (2)

Publication Number Publication Date
CN114726482A CN114726482A (en) 2022-07-08
CN114726482B true CN114726482B (en) 2024-03-22

Family

ID=82244164

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210403772.4A Active CN114726482B (en) 2022-04-18 2022-04-18 SPI data transmission method

Country Status (1)

Country Link
CN (1) CN114726482B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1930814A (en) * 2004-01-16 2007-03-14 Zih公司 Method and system for calculating and verifying the integrity of data in a data transmission system
CN105183690A (en) * 2015-09-02 2015-12-23 北京航天控制仪器研究所 Double buffering data transmission method based on serial peripheral interface (SPI) bus communication protocol
CN113176966A (en) * 2021-03-12 2021-07-27 青芯半导体科技(上海)有限公司 System and method for checking validity of SPI (Serial peripheral interface) received data
CN114128180A (en) * 2019-06-27 2022-03-01 奥斯兰姆奥普托半导体股份有限两合公司 Electronic device with CRC generator and method for transmitting data from electronic device to control unit

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TWI310638B (en) * 2004-04-09 2009-06-01 Hon Hai Prec Ind Co Ltd System and method for checking validity of data transmission

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1930814A (en) * 2004-01-16 2007-03-14 Zih公司 Method and system for calculating and verifying the integrity of data in a data transmission system
CN105183690A (en) * 2015-09-02 2015-12-23 北京航天控制仪器研究所 Double buffering data transmission method based on serial peripheral interface (SPI) bus communication protocol
CN114128180A (en) * 2019-06-27 2022-03-01 奥斯兰姆奥普托半导体股份有限两合公司 Electronic device with CRC generator and method for transmitting data from electronic device to control unit
CN113176966A (en) * 2021-03-12 2021-07-27 青芯半导体科技(上海)有限公司 System and method for checking validity of SPI (Serial peripheral interface) received data

Also Published As

Publication number Publication date
CN114726482A (en) 2022-07-08

Similar Documents

Publication Publication Date Title
US7243173B2 (en) Low protocol, high speed serial transfer for intra-board or inter-board data communication
CN114328316B (en) DMA controller, SOC system and data carrying method based on DMA controller
CN113032319B (en) FPGA-based vehicle-mounted system data transmission method and synchronous high-speed serial bus structure
CN101227263B (en) On-line malfunction detecting system, device and method
EP3065323B1 (en) Transmission method and device based on management data input/output multi-source agreements
CN112612638A (en) Hardware implementation method based on USB3.2 protocol 16-bit cyclic redundancy check
KR101001074B1 (en) Method for transmittng data on a bus
US20230261795A1 (en) Method for Retransmitting Data and Apparatus
CN113176966B (en) System and method for checking SPI received data validity
KR102535563B1 (en) Method for multiple uart communications using can bus, recording medium and device for performing the method
US10771364B2 (en) Network interface controller
CN114726482B (en) SPI data transmission method
CN101764669A (en) CRC code check method in data receiving process
CN113986600B (en) Test method and device for chip serial interface and chip
JPH10126463A (en) Method for checking completeness of full duplex serial transmission
KR101271660B1 (en) Error detection method of image data for camera test system by using error correction and crc codes
CN111930582B (en) System management bus detection platform, processor and system management bus detection method
US9621339B1 (en) Host devices and data transmission methods
CN115701595A (en) Serial data communication with intra-frame response
CN112596944A (en) Hardware implementation method based on USB3.0 protocol 16-bit cyclic redundancy check
CN113074595B (en) Data writing method and system of electronic detonator, electronic detonator and initiator
CN108599907B (en) Network interface controller
JP3516998B2 (en) Address information reading device
CN118158300B (en) HDLC protocol-based communication method and electronic equipment
CN113835940B (en) Method, system, equipment and storage medium for setting serial interrupt mode

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
CB02 Change of applicant information
CB02 Change of applicant information

Address after: Unit 1, Building 9, No. 176 Checheng West Second Road, Economic and Technological Development Zone (Longquanyi District), Chengdu City, Sichuan Province, 610000

Applicant after: CHENGDU CHUANGKESHENG ELECTRONIC TECHNOLOGY CO.,LTD.

Address before: No.301, 3 / F, building 11, 309 Nan'er Road, Chengdu Economic and Technological Development Zone (Longquanyi District), 610000

Applicant before: CHENGDU CHUANGKESHENG ELECTRONIC TECHNOLOGY CO.,LTD.

GR01 Patent grant
GR01 Patent grant