CN112506838A - SPI clock synchronization method applied to IR46 electric meter calibrating device - Google Patents
SPI clock synchronization method applied to IR46 electric meter calibrating device Download PDFInfo
- Publication number
- CN112506838A CN112506838A CN202011167230.9A CN202011167230A CN112506838A CN 112506838 A CN112506838 A CN 112506838A CN 202011167230 A CN202011167230 A CN 202011167230A CN 112506838 A CN112506838 A CN 112506838A
- Authority
- CN
- China
- Prior art keywords
- spi
- clock
- timer
- method applied
- clock synchronization
- 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.)
- Withdrawn
Links
Images
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
- G06F13/4295—Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus using an embedded synchronisation
-
- 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/14—Handling requests for interconnection or transfer
- G06F13/20—Handling requests for interconnection or transfer for access to input/output bus
- G06F13/28—Handling requests for interconnection or transfer for access to input/output bus using burst mode transfer, e.g. direct memory access DMA, cycle steal
-
- 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
- G06F13/4291—Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus using a clocked protocol
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Synchronisation In Digital Transmission Systems (AREA)
Abstract
An SPI clock synchronization method applied to an IR46 electric meter calibration device is used for solving the problem of communication abnormity caused by clock synchronization abnormity in SPI slave computer communication. The invention utilizes the time interval between the communication data frames to actively switch the CS signal by carrying out hardware configuration, forbidding CS, setting DMA transmission mode, configuring SPI and enabling, configuring Timer and enabling, detecting the clock signal SCLK and the synchronization sequence for forbidding re-enabling the CS signal, thereby achieving the purpose of clock synchronization. Through the interval synchronous clock, the successful communication between the SPI master and the SPI slave is realized, the clock loss problem is solved, the data dislocation is avoided, and the data integrity and the normal operation of the communication are ensured.
Description
Technical Field
The invention belongs to the technical field of communication, and particularly relates to an SPI clock synchronization method applied to an IR46 electric meter calibrating device.
Background
SPI is a serial synchronous communication means. The system is mainly used for communication between chips on a board, and has a master-slave division, a master machine bears the responsibility provided by a clock, and a slave machine interacts with the master machine according to the clock provided by the master machine. The slave generally has a cs (chip select) signal for clock synchronization with the master to prevent data skew.
If the host does not control the CS signal, the slave cannot determine the start of the clock, and only starts counting from the nearest clock signal, which may cause the clock signal to be misaligned, thereby causing data misalignment and affecting the normal interaction of data. There is currently no mature method of dealing with this situation on the market.
Disclosure of Invention
In order to solve the problems, the invention provides an SPI clock synchronization method applied to an IR46 electric meter verification device, which is used for solving the problem of communication abnormity caused by clock synchronization abnormity during communication of an SPI slave machine.
In order to achieve the purpose, the technical scheme of the invention is as follows:
the CS signals are actively switched by using the time interval between communication data frames and the synchronization sequence for forbidding re-enabling of the CS signals, so as to achieve clock synchronization.
The specific working process is as follows:
step 1: when in wiring, a GPIO (General-purpose input/output) is connected to a signal of a CS (Chip Select) slave of an SPI (Serial Peripheral Interface) so as to control the switching of the CS;
step 2: switching the CS to a forbidden state through GPIO to prevent abnormal receiving of data caused by the initial uncertain state of the CS;
and step 3: configuring a receiving and transmitting mode of the SPI master and slave machine as DMA transmission;
and 4, step 4: configuring a CS signal of the SPI slave machine as hardware control and enabling the SPI;
and 5: a clock signal SCLK (SPI clock) of the SPI is connected to a Timer input and used for detecting the clock signal SCLK and determining a Timer period according to a frame interval to enable the Timer;
step 6: detecting a clock signal SCLK, if a clock edge (rising edge or falling edge) is detected on the Timer input pin, clearing 0 in a counting register of the Timer, and repeating the step 6 until the overflow interruption of the Timer is triggered; if the clock signal SCLK is not received within the designated time, triggering the overflow interruption of the Timer, and entering step 7;
and 7: performing the synchronization sequence of the CS: and forbidding and re-enabling the CS signal, realizing clock synchronization, and returning to the step 6 for repeated operation.
Wherein, the step 1 is hardware configuration, and the steps 2, 3, 4 and 5 are software configuration.
Further, in step 6, the detection clock signal SCLK needs to have a certain time interval, which is greater than the clock period.
Further, the repeated operation in step 7 may also be specified according to actual needs.
Further, the specified time in step 6 is determined according to the frame interval and the clock cycle, and the time is greater than the clock cycle and less than the frame interval, and meanwhile, the CS synchronization sequence can be guaranteed to be completed within the frame interval.
The invention has the beneficial effects that:
through the interval synchronous clock, the successful communication of the SPI master and the SPI slave is realized, the clock loss problem is solved, the data dislocation is avoided, and the data integrity and the normal operation of the communication are ensured.
Drawings
Fig. 1 is a graph of CS signal enable versus clock signal for a general SPI clock synchronization method applied to an IR46 meter verification device.
Fig. 2 is a flow chart of the SPI clock synchronization method applied to the IR46 electric meter verification device according to the present invention.
Fig. 3 is a CS synchronization sequence diagram of the SPI clock synchronization method applied to the IR46 electric meter verification apparatus according to the present invention.
DETAILED DESCRIPTION OF EMBODIMENT (S) OF INVENTION
The technical solution in the embodiments of the present invention is clearly and completely described below with reference to the drawings in the embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The invention actively switches the CS signals by utilizing the time interval between communication data frames and through the synchronization sequence for prohibiting the CS signals from being re-enabled, thereby achieving the clock synchronization.
As shown in fig. 1, the specific working process of the present invention is as follows:
step 1: hardware configuration: when in wiring, a GPIO (General-purpose input/output) is connected to a signal of a CS (Chip Select) slave of an SPI (Serial Peripheral Interface) so as to control the switching of the CS;
step 2: switching the CS to a forbidden state through GPIO to prevent abnormal receiving of data caused by the initial uncertain state of the CS;
and step 3: configuring a receiving and transmitting mode of the SPI master and slave machine as DMA transmission;
and 4, step 4: configuring a CS signal of the SPI slave machine as hardware control and enabling the SPI;
and 5: a clock signal SCLK (SPI clock) of the SPI is connected to a Timer input and used for detecting the clock signal SCLK and determining a Timer period according to a frame interval to enable the Timer;
step 6: detecting a clock signal SCLK, if a clock edge (rising edge or falling edge) is detected on the Timer input pin, clearing 0 in a counting register of the Timer, and repeating the step 6 until the overflow interruption of the Timer is triggered; if the clock signal SCLK is not received within the designated time, triggering the overflow interruption of the Timer, and entering step 7;
and 7: performing the synchronization sequence of the CS: and forbidding and re-enabling the CS signal, realizing clock synchronization, and returning to the step 6 for repeated operation.
Wherein, the step 1 is hardware configuration, and the steps 2, 3, 4 and 5 are software configuration.
Further, in step 6, the detection of the clock signal SCLK requires a time interval greater than the clock period.
Further, the repeated operation in step 7 may also be specified according to actual needs.
Further, the designated time in step 6 is determined by the CPU according to the frame interval and the clock cycle, and the time is greater than the clock cycle and smaller than the frame interval, and meanwhile, the CS synchronization sequence can be guaranteed to be completed within the frame interval.
Finally, it should be noted that: the above embodiments are only intended to illustrate the technical solution of the present invention and not to limit the same, and a person of ordinary skill in the art can make modifications or equivalents to the specific embodiments of the present invention with reference to the above embodiments, and such modifications or equivalents without departing from the spirit and scope of the present invention are within the scope of the claims of the present invention as set forth in the claims.
Claims (5)
1. An SPI clock synchronization method applied to an IR46 electric meter verification device is characterized in that time intervals between communication data frames are utilized, and CS signals are actively switched through a synchronization sequence for inhibiting re-enabling of the CS signals, so that clock synchronization is achieved.
2. The SPI clock synchronization method applied to an IR46 electric meter verification device according to claim 1, comprising the following steps:
step 1: hardware configuration: when in wiring, a GPIO (General-purpose input/output) is connected to a signal of a CS (Chip Select) slave of an SPI (Serial Peripheral Interface) so as to control the switching of the CS;
step 2: switching the CS to a forbidden state through GPIO to prevent abnormal receiving of data caused by the initial uncertain state of the CS;
and step 3: configuring a receiving and transmitting mode of the SPI master and slave machine as DMA transmission;
and 4, step 4: configuring a CS signal of the SPI slave machine as hardware control and enabling the SPI;
and 5: a clock signal SCLK (SPI clock) of the SPI is connected to a Timer input and used for detecting the clock signal SCLK and determining a Timer period according to a frame interval to enable the Timer;
step 6: detecting a clock signal SCLK, if a clock edge (rising edge or falling edge) is detected on the Timer input pin, clearing 0 in a counting register of the Timer, and repeating the step 6 until the overflow interruption of the Timer is triggered; if the clock signal SCLK is not received within the designated time, triggering the overflow interruption of the Timer, and entering step 7;
and 7: performing the synchronization sequence of the CS: and forbidding and re-enabling the CS signal, realizing clock synchronization, and returning to the step 6 for repeated operation.
3. The SPI clock synchronization method applied to the IR46 electric meter verification device according to claim 2, wherein in the step 6, the detection clock signal SCLK needs to have a certain time interval, and the time interval is greater than a clock period.
4. The SPI clock synchronization method applied to the IR46 electric meter verification device is characterized in that the repeated operation in the step 6 can be specified according to actual needs.
5. The SPI clock synchronization method applied to an IR46 meter verification device according to claim 2, wherein the specified time in step 6 is determined according to a frame interval and a clock period, and the time is greater than the clock period and less than the frame interval, and the CS synchronization sequence is guaranteed to be completed within the frame interval.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011167230.9A CN112506838A (en) | 2021-02-03 | 2021-02-03 | SPI clock synchronization method applied to IR46 electric meter calibrating device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011167230.9A CN112506838A (en) | 2021-02-03 | 2021-02-03 | SPI clock synchronization method applied to IR46 electric meter calibrating device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN112506838A true CN112506838A (en) | 2021-03-16 |
Family
ID=74954326
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202011167230.9A Withdrawn CN112506838A (en) | 2021-02-03 | 2021-02-03 | SPI clock synchronization method applied to IR46 electric meter calibrating device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112506838A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113132047A (en) * | 2021-04-16 | 2021-07-16 | 中国电力科学研究院有限公司 | Communication synchronization method and system of protocol consistency testing device of double-core electric energy meter |
Citations (14)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20050172059A1 (en) * | 2004-01-07 | 2005-08-04 | Hitachi, Ltd. | Data communication system and controller |
CN1851682A (en) * | 2006-03-28 | 2006-10-25 | 华为技术有限公司 | Method for realizing serial peripheral unit interface |
CN101610145A (en) * | 2009-07-03 | 2009-12-23 | 中兴通讯股份有限公司 | A kind of method and system of realizing the Synchronization Control of distributed system |
CN102819512A (en) * | 2012-06-28 | 2012-12-12 | 惠州市德赛西威汽车电子有限公司 | Full-duplex communication device based on SPI and method thereof |
JP2013219716A (en) * | 2012-04-12 | 2013-10-24 | Rohm Co Ltd | Communication device and electronic apparatus using the same |
US20140019791A1 (en) * | 2012-07-11 | 2014-01-16 | Infineon Technologies Ag | SPI Interface and Method for Serial Communication via an SPI Interface |
CN105320121A (en) * | 2014-07-16 | 2016-02-10 | 联创汽车电子有限公司 | Electric power steering safety monitoring system |
CN105320635A (en) * | 2015-09-14 | 2016-02-10 | 陈钦碧 | Method for realizing MAX 2769 interface control by adopting universal digital I/O |
US20160148336A1 (en) * | 2014-11-26 | 2016-05-26 | Japan Display Inc. | Data communication device and data communication system |
US9734099B1 (en) * | 2017-04-27 | 2017-08-15 | Micro Lambda Wireless, Inc. | QSPI based methods of simultaneously controlling multiple SPI peripherals |
CN107092568A (en) * | 2016-02-17 | 2017-08-25 | 亚德诺半导体集团 | The data communication interface of processing data in low-power dissipation system |
CN107122282A (en) * | 2017-03-28 | 2017-09-01 | 中国第汽车股份有限公司 | A kind of Functional Safety Communication method based on spi bus |
CN109977041A (en) * | 2017-12-27 | 2019-07-05 | 恩智浦有限公司 | Host apparatus is communicated with embedded multi-media card device |
CN112100100A (en) * | 2020-08-26 | 2020-12-18 | 广州华欣电子科技有限公司 | SPI communication method and SPI equipment |
-
2021
- 2021-02-03 CN CN202011167230.9A patent/CN112506838A/en not_active Withdrawn
Patent Citations (14)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20050172059A1 (en) * | 2004-01-07 | 2005-08-04 | Hitachi, Ltd. | Data communication system and controller |
CN1851682A (en) * | 2006-03-28 | 2006-10-25 | 华为技术有限公司 | Method for realizing serial peripheral unit interface |
CN101610145A (en) * | 2009-07-03 | 2009-12-23 | 中兴通讯股份有限公司 | A kind of method and system of realizing the Synchronization Control of distributed system |
JP2013219716A (en) * | 2012-04-12 | 2013-10-24 | Rohm Co Ltd | Communication device and electronic apparatus using the same |
CN102819512A (en) * | 2012-06-28 | 2012-12-12 | 惠州市德赛西威汽车电子有限公司 | Full-duplex communication device based on SPI and method thereof |
US20140019791A1 (en) * | 2012-07-11 | 2014-01-16 | Infineon Technologies Ag | SPI Interface and Method for Serial Communication via an SPI Interface |
CN105320121A (en) * | 2014-07-16 | 2016-02-10 | 联创汽车电子有限公司 | Electric power steering safety monitoring system |
US20160148336A1 (en) * | 2014-11-26 | 2016-05-26 | Japan Display Inc. | Data communication device and data communication system |
CN105320635A (en) * | 2015-09-14 | 2016-02-10 | 陈钦碧 | Method for realizing MAX 2769 interface control by adopting universal digital I/O |
CN107092568A (en) * | 2016-02-17 | 2017-08-25 | 亚德诺半导体集团 | The data communication interface of processing data in low-power dissipation system |
CN107122282A (en) * | 2017-03-28 | 2017-09-01 | 中国第汽车股份有限公司 | A kind of Functional Safety Communication method based on spi bus |
US9734099B1 (en) * | 2017-04-27 | 2017-08-15 | Micro Lambda Wireless, Inc. | QSPI based methods of simultaneously controlling multiple SPI peripherals |
CN109977041A (en) * | 2017-12-27 | 2019-07-05 | 恩智浦有限公司 | Host apparatus is communicated with embedded multi-media card device |
CN112100100A (en) * | 2020-08-26 | 2020-12-18 | 广州华欣电子科技有限公司 | SPI communication method and SPI equipment |
Non-Patent Citations (1)
Title |
---|
周东: ""车载分布式故障检测系统中通信和存储技术的研究"", 《中国优秀博硕士学位论文全文数据库(硕士) 信息科技辑》 * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113132047A (en) * | 2021-04-16 | 2021-07-16 | 中国电力科学研究院有限公司 | Communication synchronization method and system of protocol consistency testing device of double-core electric energy meter |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN101834715B (en) | Data processing method, data processing system and data processing device | |
KR20150132855A (en) | Multi-wire open-drain link with data symbol transition based clocking | |
CN109062850B (en) | Data sending and receiving method of single chip microcomputer | |
CN112559426A (en) | Data transmission method, interface circuit and device | |
CN113009961B (en) | Cross-clock synchronous circuit and SoC system | |
CN103197139A (en) | Clock frequency test method and clock frequency test circuit | |
CN112506838A (en) | SPI clock synchronization method applied to IR46 electric meter calibrating device | |
EP1237282B1 (en) | Circuit for the detection of clock signal period abnormalities | |
CN109871344B (en) | Communication system, interface circuit and signal transmission method thereof | |
CN113836075B (en) | SPI interface signal burr eliminating method based on FPGA platform | |
CN101826068A (en) | Method for hot-plugging PCI-E device and application thereof | |
CN108369565A (en) | Communication device, communication means, program and communication system | |
CN110535621B (en) | Serial port communication baud rate correction device and correction method thereof | |
CN101645057B (en) | Method and device for preventing CPU local bus from suspension | |
JP5195075B2 (en) | Bidirectional bus control circuit | |
CN113722251B (en) | Two-wire SPI communication system and method for functional safety monitoring | |
CN105406984B (en) | A kind of system and method for realizing masterslave switchover backboard clock | |
CN114968681A (en) | Method and device for monitoring I2C bus communication abnormity and I2C master device | |
CN110795289B (en) | Multi-clock automatic switching method | |
CN210490858U (en) | Wireless access equipment | |
CN102104415B (en) | Frame frequency and frame number abnormal processing method and system | |
CN109725197B (en) | Frequency tracking method and system for multi-processing unit relay protection system | |
CN116860672B (en) | Digital processing SMBus communication system and method | |
CN101627375A (en) | Method and system for I2C clock generation | |
CN113132047A (en) | Communication synchronization method and system of protocol consistency testing device of double-core electric energy meter |
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 | ||
WW01 | Invention patent application withdrawn after publication | ||
WW01 | Invention patent application withdrawn after publication |
Application publication date: 20210316 |