CN108092746A - A kind of serial port communication method and system - Google Patents

A kind of serial port communication method and system Download PDF

Info

Publication number
CN108092746A
CN108092746A CN201711427439.2A CN201711427439A CN108092746A CN 108092746 A CN108092746 A CN 108092746A CN 201711427439 A CN201711427439 A CN 201711427439A CN 108092746 A CN108092746 A CN 108092746A
Authority
CN
China
Prior art keywords
message
processor
character string
baud rate
difference information
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
Application number
CN201711427439.2A
Other languages
Chinese (zh)
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.)
Taizhou Jiji Intellectual Property Operation Co.,Ltd.
Original Assignee
Shanghai Feixun Data Communication 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 Shanghai Feixun Data Communication Technology Co Ltd filed Critical Shanghai Feixun Data Communication Technology Co Ltd
Priority to CN201711427439.2A priority Critical patent/CN108092746A/en
Publication of CN108092746A publication Critical patent/CN108092746A/en
Withdrawn legal-status Critical Current

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/0001Systems modifying transmission characteristics according to link quality, e.g. power backoff
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • H04L1/0001Systems modifying transmission characteristics according to link quality, e.g. power backoff
    • H04L1/0002Systems modifying transmission characteristics according to link quality, e.g. power backoff by adapting the transmission rate
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L27/00Modulated-carrier systems
    • H04L27/0014Carrier regulation
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L27/00Modulated-carrier systems
    • H04L27/0014Carrier regulation
    • H04L2027/0024Carrier regulation at the receiver end
    • H04L2027/0026Correction of carrier offset

Abstract

The invention discloses a kind of serial port communication method, the described method includes:The first processor sends a sync message to the second processor respectively with identical message character string and follows message;The message character string of the sync message received is recorded as T1 by the second processor, will receive described in the message character string of message is followed to be recorded as T2;Judge whether the T1 and T2 is identical;If it is different, adjusting the frequency ratio of the baud rate of the first processor, and step S1 S3 are repeated, until T1 and T2 identical, on the premise of serial communication baud rate is not changed, the error free transmission of the big data flow of serial communication between realization MCU.

Description

A kind of serial port communication method and system
Technical field
The invention belongs to fields of communication technology, more particularly to serial port communication method and system.
Background technology
The features such as communication line possessed by serial ports is simple, can usually be used for MCU(Microcontroller Unit, micro-control unit)Between communication.In order to ensure the reliable and stable transmission of the mass data between MCU, using standard Serial communication protocol carries out data transmission.The baud rate of serial communication protocol of the prior art be by frequency dividing inside MCU and Realize, the timing differential of different MCU causes the frequency deviation of baud rate, all can strong influence big data quantity transmitting.
In the prior art, when serial communication is unstable between MCU, passed by reducing the technical solution of baud rate to reduce The probability of defeated error code.But the program can not evade the loss and mistake of Serial Port Transmission data, also reduce baud rate also shadow Traffic rate is rung, is not suitable for the communication requirement of big data transmission between two MCU.
Therefore, how on the premise of serial communication baud rate is not changed, the big number of serial communication between two MCU is realized According to the error free transmission of flow, become urgent problem to be solved.
The content of the invention
In consideration of it, it is an object of the invention to provide a kind of serial port communication method and systems, do not changing serial communication ripple On the premise of special rate, the error free transmission of the big data flow of serial communication between realization MCU.
According to foregoing invention purpose, the present invention provides a kind of serial port communication method, the described method includes:
S1, the first processor with identical message character string respectively to the second processor send a sync message and with With message;
The message character string of the sync message received is recorded as T1 by S2, the second processor, the institute that will be received It states and the message character string of message is followed to be recorded as T2;
S3, judge whether the T1 and T2 is identical;
S4, if it is different, adjust the frequency ratio of the baud rate of the first processor, and step S1-S3 is repeated, until T1 and T2 It is identical.
Preferably, further included before step S1:First processor and second processor set identical baud rate.
Preferably, the step S1 is further included:
The message character string is hexadecimal ASCII check codes;
The sync message and follow message include data head, word length, the message character string and data tail, wherein, the number According to head identifying type of message.
Preferably, the step S1 and S2 is specifically included:
The first processor sends sync message to second processor, and the sync message includes message character string, described same The type of message of step message is arranged to wheel synchronization type;
The second processor obtains according to the type of message of the sync message of acquisition and records the message in the sync message Character string is T1;
First processor transmission follows message to second processor, it is described follow message include in the sync message Identical message character string, it is described that the type of message of message is followed to be arranged to follow type;
The second processor follows the type of message of message according to acquisition, obtains and records described follow in message Message character string be T2.
Preferably, step S4 is specifically included:
The second processor calculates the difference information of the T1 and T2;
The second processor sends a latency request message to the first processor, and the latency request message includes described Difference information;
The first processor obtains the difference information in the latency request message, and states the according to difference information adjustment The frequency ratio of the baud rate of one processor.
Preferably, step S4 is specifically further included:
If the difference information is more than 0, the first processor baud rate is divided and carries out positive frequencies compensation;
If the difference information is less than 0, the first processor baud rate is divided and carries out negative sense frequency compensation;
If the difference information is equal to 0, to first processor baud rate frequency dividing without compensation.
According to foregoing invention purpose, the present invention provides a kind of serial communication system, and the system comprises first processor, the Two processors and adjustment module:
The first processor, for identical message character string respectively to the second processor send a sync message and Follow message;
The second processor, will be described in acquisition for the message character string of the sync message obtained to be recorded as T1 The message character string of message is followed to be recorded as T2;
The adjustment module, for judging whether the T1 and T2 is identical, if it is different, adjusting the baud rate of the first processor Frequency ratio, and the function of the first processor and second processor is repeated, until T1 and T2 identical.
Preferably, the system also includes a setup module, for setting phase to the first processor and second processing Same baud rate.
Preferably, the adjustment module is specifically used for, and the second processor calculates the difference information of the T1 and T2, and A latency request message is sent to the first processor, the latency request message includes the difference information;Described first Processor obtains the difference information in the latency request message, and the ripple of first processor is stated according to difference information adjustment The frequency ratio of special rate.
Preferably, adjust module also particularly useful for:
If the difference information is more than 0, the first processor baud rate is divided and carries out positive frequencies compensation;
If the difference information is less than 0, the first processor baud rate is divided and carries out negative sense frequency compensation;
If the difference information is equal to 0, to first processor baud rate frequency dividing without compensation.
Compared with prior art, the present invention provides serial port communication method and system, has the advantages that:It solves existing There is the problem of in technology, by adjusting the baud rate precision of MCU serial communications, do not changing the premise of serial communication baud rate Under, the error free transmission of the big data flow of serial communication between MCU is realized, is provided effectively for the reliability of data transmission It ensures.
Description of the drawings
Below by a manner of clearly understandable, preferred embodiment is described with reference to the drawings, to a kind of serial port communication method and Above-mentioned characteristic, technical characteristic, advantage and its realization method of system are further described.
Fig. 1 is a kind of flow diagram of serial port communication method of the present invention;
Fig. 2 is a kind of composition structure diagram of serial communication system of the present invention.
Specific embodiment
In order to illustrate more clearly about the embodiment of the present invention or technical scheme of the prior art, control is illustrated below The specific embodiment of the present invention.It should be evident that the accompanying drawings in the following description is only some embodiments of the present invention, for For those of ordinary skill in the art, without creative efforts, other are can also be obtained according to these attached drawings Attached drawing, and obtain other embodiments.
To make simplified form, part related to the present invention is only schematically shown in each figure, they are not represented Its practical structures as product.In addition, so that simplified form readily appreciates, there is identical structure or function in some figures Component only symbolically depicts one of those or has only marked one of those.Herein, "one" is not only represented " only this " can also represent the situation of " more than one ".
As shown in Figure 1, according to one embodiment of present invention, a kind of serial port communication method, the described method includes:
S1, the first processor with identical message character string respectively to the second processor send a sync message and with With message;
The message character string of the sync message received is recorded as T1 by S2, the second processor, the institute that will be received It states and the message character string of message is followed to be recorded as T2;
S3, judge whether the T1 and T2 is identical;
S4, if it is different, adjust the frequency ratio of the baud rate of the first processor, and step S1-S3 is repeated, until T1 and T2 It is identical.
Preferably, further included before step S1:First processor and second processor set identical baud rate.
It is communicated by serial ports between two processors, it is necessary to set identical baud rate, serial communication could be established. First processor and second processor set identical baud rate, establish serial communication.
The specific embodiment of the present invention, the message character string are hexadecimal ASCII check codes.The synchronous report Text and follow message include data head, word length, the message character string and data tail, wherein, the data head to identify report Literary type, to distinguish the data format of normal serial communication.Data head is two 16 system words, for the identification class of this message Type, to verify the beginning of exclusive data.Word length is used to represent the byte quantity of 16 binary digits of this hardwood data.Data check with Machine code is for a series of big data flow in simulative serial port communication.Data tail is similar with the function of data head and two 16 System word is the end of verification exclusive data for this message identification types.
The first processor sends sync message to second processor, and the sync message includes message character string, institute The type of message for stating the data head of sync message is arranged to wheel synchronization type.The wheel synchronization type is representing when the second processing After device receives the message of the type, obtain the message character string in the message and stored.The first processor is deposited Store up the synchronizing information synchronization character string.
After the second processor receives the sync message, according to the type of message of the sync message of acquisition, carry out The sync message is parsed, obtain and records the message character string in the sync message as T1.
After the first processor sends sync message to second processor, the first processor transmission follows message To second processor.It is described that message is followed to include the message character string identical with the sync message.It is described to follow Data head in message sets the type of message to follow type.It is described to follow type to represent that the second processor receives To after the message, obtain the message character string information in the message, and and obtain message character string in the sync message into Row compares, and whether the two is consistent.
After following message described in the second processor reception, according to the type of message followed in message, solved Message is followed described in analysis, it is T2 to obtain and record the message character string followed in message.
The T1 and T2 are compared by the second processor, judge whether the T1 is consistent with T2.If the T1 and T2 is inconsistent, then shows the serial communication between the first processor and second processor, loss of data or error code occurs. The second processor calculates the difference information of the T1 and T2, i.e., described T1 and T2 carry out bit difference operations, it is poor to obtain one Value information.The second processor generates latency request message, is sent to the first processor, the latency request message bag Include the difference information.The specific embodiment of the present invention, the latency request message use consistent with the sync message Data message form.It is latency request type that data head in the latency request message, which sets the type of message,.The delay After request type is to represent that the first processor receives the message, the difference information in the message is obtained, to described The frequency ratio of the baud rate of one processor is adjusted.If the T1 is consistent with T2, show at first processor and second The serial communication between device is managed, loss of data or error code does not occur, serial communication is normal, need not handle described first The frequency ratio of the baud rate of device is adjusted and compensates
The first processor receives the latency request message, obtains the difference information in the latency request message, and According to the difference information, the frequency ratio of the baud rate of the first processor is adjusted.Specifically, if the difference information is big In 0, then the first processor baud rate is divided and carry out positive frequencies compensation;If the difference information is less than 0, to described First processor baud rate frequency dividing carries out negative sense frequency compensation;If if the difference information is equal to 0, to the first processor Baud rate frequency dividing is without compensation.
When the difference information is not for 0, step S1-S3 is repeated, constantly to the first processor baud rate point Frequency is compensated and adjusted, and optimization baud rate precision is 0 until the difference information.
According to the technical solution, by adjusting the frequency dividing precision of the baud rate of serial communication between MCU, do not changing serial ports On the premise of communication baud rate, the error free transmission of the big data flow of serial communication between MCU is realized, is data transmission Reliability provides powerful guarantee.
Fig. 2 is one embodiment of the invention, a kind of serial communication system, and the system comprises first processors 20, second Processor 21 and adjustment module 22:
The first processor 20, for sending a sync message to the second processor respectively with identical message character string With follow message;
The second processor 21, for the message character string of the sync message obtained to be recorded as T1, by the institute of acquisition It states and the message character string of message is followed to be recorded as T2;
The adjustment module 22, for judging whether the T1 and T2 is identical, if it is different, adjusting the baud of the first processor The frequency ratio of rate, and the function of the first processor and second processor is repeated, until T1 and T2 identical.
Preferably, the system also includes a setup module, for setting phase to the first processor and second processing Same baud rate.It is communicated by serial ports between two processors, it is necessary to set identical baud rate, serial ports could be established and led to Letter.First processor and second processor set identical baud rate, establish serial communication.
The message character string is hexadecimal ASCII check codes.The sync message and follow message include data Head, word length, the message character string and data tail, wherein, the data head is to identify type of message, to distinguish normal serial ports The data format of communication.
The first processor 20 sends sync message to second processor, and the sync message includes message character string, The type of message of the data head of the sync message is arranged to wheel synchronization type.
After the second processor 21 receives the sync message, according to the type of message of the sync message of acquisition, into Row parses the sync message, obtains and records the message character string in the sync message as T1.
When the first processor 20 transmission follows message to second processor.It is described that message is followed to include and institute State message character string identical in sync message.The data head followed in message sets the type of message to follow type.
The second processor 21 receives described after following message, according to the type of message followed in message, carries out Message is followed described in parsing, it is T2 to obtain and record the message character string followed in message.
In the adjustment module 22, the T1 and T2 are compared by the second processor, judge the T1 and T2 It is whether consistent.If the T1 and T2 are inconsistent, show the serial communication between the first processor and second processor, go out Existing loss of data or error code.The second processor calculates the difference information of the T1 and T2, i.e., described T1 and T2 carry out bit Position difference operation, obtains a difference information.The second processor generates latency request message, is sent to first processing Device, the latency request message include the difference information.If the T1 is consistent with T2, show at first processor and second The serial communication between device is managed, loss of data or error code does not occur, serial communication is normal, need not handle described first The frequency ratio of the baud rate of device is adjusted and compensates
The first processor receives the latency request message, obtains the difference information in the latency request message, and According to the difference information, the frequency ratio of the baud rate of the first processor is adjusted.Specifically, if the difference information is big In 0, then the first processor baud rate is divided and carry out positive frequencies compensation;If the difference information is less than 0, to described First processor baud rate frequency dividing carries out negative sense frequency compensation;If if the difference information is equal to 0, to the first processor Baud rate frequency dividing is without compensation.
When the difference information is not for 0, above-mentioned steps are repeated, constantly the first processor baud rate is divided It compensates and adjusts, optimization baud rate precision is 0 until the difference information.
According to the technical solution, by adjusting the frequency dividing precision of the baud rate of serial communication between MCU, realize MCU it Between serial communication big data flow error free transmission, provide powerful guarantee for the reliability of data transmission.
In conclusion the present invention on the premise of serial communication baud rate is not changed, realizes serial communication between MCU The error free transmission of big data flow.
It should be noted that above-described embodiment can be freely combined as needed.The above is only the preferred of the present invention Embodiment, it is noted that for those skilled in the art, do not departing from the premise of the principle of the invention Under, several improvements and modifications can also be made, these improvements and modifications also should be regarded as protection scope of the present invention.

Claims (10)

1. a kind of serial port communication method, which is characterized in that the described method includes:
S1, the first processor with identical message character string respectively to the second processor send a sync message and with With message;
The message character string of the sync message received is recorded as T1 by S2, the second processor, the institute that will be received It states and the message character string of message is followed to be recorded as T2;
S3, judge whether the T1 and T2 is identical;
S4, if it is different, adjust the frequency ratio of the baud rate of the first processor, and step S1-S3 is repeated, until T1 and T2 It is identical.
2. serial port communication method as described in claim 1, which is characterized in that further included before step S1:First processor and Second processor sets identical baud rate.
3. serial port communication method as described in claim 1, which is characterized in that the step S1 is further included:
The message character string is hexadecimal ASCII check codes;
The sync message and follow message include data head, word length, the message character string and data tail, wherein, the number According to head identifying type of message.
4. serial port communication method as claimed in claim 3, which is characterized in that the step S1 and S2 is specifically included:
The first processor sends sync message to second processor, and the sync message includes message character string, described same The type of message of step message is arranged to wheel synchronization type;
The second processor obtains according to the type of message of the sync message of acquisition and records the message in the sync message Character string is T1;
First processor transmission follows message to second processor, it is described follow message include in the sync message Identical message character string, it is described that the type of message of message is followed to be arranged to follow type;
The second processor follows the type of message of message according to acquisition, obtains and records described follow in message Message character string be T2.
5. serial port communication method as described in claim 1, which is characterized in that step S4 is specifically included:
The second processor calculates the difference information of the T1 and T2;
The second processor sends a latency request message to the first processor, and the latency request message includes described Difference information;
The first processor obtains the difference information in the latency request message, and states the according to difference information adjustment The frequency ratio of the baud rate of one processor.
6. serial port communication method as claimed in claim 5, which is characterized in that step S4 is specifically further included:
If the difference information is more than 0, the first processor baud rate is divided and carries out positive frequencies compensation;
If the difference information is less than 0, the first processor baud rate is divided and carries out negative sense frequency compensation;
If the difference information is equal to 0, to first processor baud rate frequency dividing without compensation.
7. a kind of serial communication system, which is characterized in that the system comprises first processor, second processor and adjustment moulds Block:
The first processor, for identical message character string respectively to the second processor send a sync message and Follow message;
The second processor, will be described in acquisition for the message character string of the sync message obtained to be recorded as T1 The message character string of message is followed to be recorded as T2;
The adjustment module, for judging whether the T1 and T2 is identical, if it is different, adjusting the baud rate of the first processor Frequency ratio, and the function of the first processor and second processor is repeated, until T1 and T2 identical.
8. serial communication system as claimed in claim 7, which is characterized in that the system also includes a setup modules, are used for Identical baud rate is set to the first processor and second processing.
9. serial communication system as claimed in claim 7, which is characterized in that the adjustment module is specifically used for, and described second Processor calculates the difference information of the T1 and T2, and sends a latency request message to the first processor, the delay Request message includes the difference information;The first processor obtains the difference information in the latency request message, and root The frequency ratio of the baud rate of first processor is stated according to difference information adjustment.
10. serial communication system as claimed in claim 9, which is characterized in that adjustment module also particularly useful for:
If the difference information is more than 0, the first processor baud rate is divided and carries out positive frequencies compensation;
If the difference information is less than 0, the first processor baud rate is divided and carries out negative sense frequency compensation;
If the difference information is equal to 0, to first processor baud rate frequency dividing without compensation.
CN201711427439.2A 2017-12-26 2017-12-26 A kind of serial port communication method and system Withdrawn CN108092746A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711427439.2A CN108092746A (en) 2017-12-26 2017-12-26 A kind of serial port communication method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711427439.2A CN108092746A (en) 2017-12-26 2017-12-26 A kind of serial port communication method and system

Publications (1)

Publication Number Publication Date
CN108092746A true CN108092746A (en) 2018-05-29

Family

ID=62179421

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711427439.2A Withdrawn CN108092746A (en) 2017-12-26 2017-12-26 A kind of serial port communication method and system

Country Status (1)

Country Link
CN (1) CN108092746A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109510689A (en) * 2018-12-25 2019-03-22 迈普通信技术股份有限公司 Serial port communication method, apparatus and system
CN110032536A (en) * 2019-03-28 2019-07-19 北京龙鼎源科技股份有限公司 Two be MCU method of data synchronization, apparatus and system

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109510689A (en) * 2018-12-25 2019-03-22 迈普通信技术股份有限公司 Serial port communication method, apparatus and system
CN109510689B (en) * 2018-12-25 2022-03-22 迈普通信技术股份有限公司 Serial port communication method, device and system
CN110032536A (en) * 2019-03-28 2019-07-19 北京龙鼎源科技股份有限公司 Two be MCU method of data synchronization, apparatus and system

Similar Documents

Publication Publication Date Title
CN101313486B (en) The block ack protocols of radio packet network
US8326988B2 (en) Systems and methods for data alignment
EP2928108B1 (en) System, method and apparatus for multi-lane auto-negotiation over reduced lane media
US10396921B2 (en) Multi-lane synchronization method, synchronization apparatus and system, and computer storage medium
CN108011698B (en) RSSP-I secure communication method based on dual-system synchronization
US20230118809A1 (en) Method and apparatus for sending and receiving multiframe, device, system, and storage medium
WO2006019501B1 (en) Efficient data transmission by data aggregation
CN107528667B (en) Method and device for transmitting frame data between near-end equipment and far-end equipment
CN108521343A (en) A kind of processing method and processing device of OAM message
WO2020098409A1 (en) Time synchronization method and device, and storage medium
CN108092746A (en) A kind of serial port communication method and system
CN105183687A (en) Time-sharing serial communication method and system
WO2020038424A1 (en) Data packet transmission method and apparatus, storage medium, and electronic apparatus
US9485053B2 (en) Long-distance RapidIO packet delivery
CN102868557B (en) Method for realizing configuration synchronization between network manager and xPON (x-passive optical network) device
CN107645747B (en) Method and equipment for sending and receiving data
CN103684736A (en) Clock synchronization method for high-speed communication
WO2019140974A1 (en) Data transmission control method and apparatus, data transmission device and storage medium
WO2020248865A1 (en) Control word transmission method, apparatus, and computer readable storage medium
US8542701B2 (en) Method and device for determining timeslot configuration in TDM transmission
WO2018196833A1 (en) Message sending method and message receiving method and apparatus
CN105407084B (en) A kind of network transmission device, method and system
CN104320411A (en) Virtual carrier sense networking communication method based on half-duplex channel
CN110855689B (en) Method for separating SRIO protocol control character and data packet facing 128bit width
CN102457431A (en) Cell transmission method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20201029

Address after: No. 2-3167, zone a, Nonggang City, No. 2388, Donghuan Avenue, Hongjia street, Jiaojiang District, Taizhou City, Zhejiang Province

Applicant after: Taizhou Jiji Intellectual Property Operation Co.,Ltd.

Address before: 201616 Shanghai city Songjiang District Sixian Road No. 3666

Applicant before: Phicomm (Shanghai) Co.,Ltd.

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: 20180529