CN101989249A - Serial port data receiving method of single chip microcomputer - Google Patents

Serial port data receiving method of single chip microcomputer Download PDF

Info

Publication number
CN101989249A
CN101989249A CN 200910109543 CN200910109543A CN101989249A CN 101989249 A CN101989249 A CN 101989249A CN 200910109543 CN200910109543 CN 200910109543 CN 200910109543 A CN200910109543 A CN 200910109543A CN 101989249 A CN101989249 A CN 101989249A
Authority
CN
China
Prior art keywords
data
serial
chip microcomputer
serial port
port data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN 200910109543
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.)
Shenzhen Das Intellitech Co Ltd
Original Assignee
Shenzhen Das Intellitech 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 Shenzhen Das Intellitech Co Ltd filed Critical Shenzhen Das Intellitech Co Ltd
Priority to CN 200910109543 priority Critical patent/CN101989249A/en
Publication of CN101989249A publication Critical patent/CN101989249A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention discloses a serial port data receiving method of a single chip microcomputer. The method comprises the following steps: A. the single chip microcomputer responds to a serial port interrupt signal, memorizes field data and adopts an interrupt mode to receive first serial port data of one communication protocol; B. the receiving mode of the serial port data is changed into an inquiry mode to inquire whether new serial port data is received or not; and C. when the new serial port data is received, the new serial port data is processed until the field data is popped after all the serial port data of the communication protocol is received. In the serial port data receiving method, because the combination of the interrupt mode and the inquiry mode for the serial port of the single chip microcomputer is adopted, the processing time of the single chip microcomputer is greatly reduced when the single chip microcomputer responds to the interrupt, and the response speed of the single chip microcomputer is enhanced and the reliability of the communication is guaranteed under the premise that no hardware equipment is additionally arranged and the Baud rate of the communication is not reduced.

Description

A kind of microcontroller serial port data receive method
Technical field
The present invention relates to a kind of single chip communication method, especially relate to a kind of microcontroller serial port data receive method.
Background technology
The general serial asynchronism transceiver is because its interface is simple, expansion is widely used in the Single Chip Microcomputer (SCM) system flexibly, because the frequency of operation of single-chip microcomputer own is generally lower, processing speed is slower, so in the process of high speed communication, tend to occur the insecure situation of communication.
General serial asynchronism transceiver in the single-chip microcomputer generally has 2 kinds of receive modes: interrupt mode and inquiry mode.Because communication has randomness, thus in the practical application generally based on interrupt mode.The serial data of single-chip microcomputer receives in the following ways in the prior art: received the data of serial ports in real time by byte or word and be put in the buffer zone by interrupt function, come also processing of cyclic query by master routine.Like this, in communication process, will respond serial ports at any time and interrupt, and receive data by calling the Interrupt Process function.And single-chip microcomputer when responding interrupt call Interrupt Process function at every turn, most principal work is exactly the scene that save routine is carried out, each variable and the state that are about to current use all will be saved in the storehouse, and after the Interrupt Process function withdraws from, also need these variablees and state are ejected from storehouse, can then carry out with the assurance program.
As scheme institute 1 and show that the time of a serial data is that data T1 effective time adds data break T2, Fig. 2 forms for receiving a used time of serial data.By prior art, single-chip microcomputer receives a serial data need preserve data time T3 in storehouse, Interrupt Process time T 4, and the data of preserving before ejecting from storehouse need time T 5.Wherein T1 and T2 and communication baud rate are inversely proportional to, and communication baud rate is high more, and T1 and T2 are more little.T3, T4, T5, relevant with the processing speed of single-chip microcomputer, processing speed is fast more, and the time is short more.After signal arrived, single-chip microcomputer responded interruption at T1 in the time, and the preservation scene is changeed then and received serial data, withdraws from interrupt handling routine, the data of preserving in the pop-up a stack after finishing again.The used time is T3+T4+T5, suppose that a communications protocol has n byte, be n* (T1+T2) effective time of serial data, receiving the needed time is n* (T3+T4+T5), and have only n* (T3+T4+T5)<n* (T1+T2), both when next serial data arrives single-chip microcomputer handled be on a serial data could guarantee to receive reliably each serial data.Because T1+T2 is by the communication baud rate decision, so in order to guarantee the reliable of serial data reception, just need reduce the value of time T 3+T4+T5.
The prior art head it off generally is to reduce the baud rate of communication or solve by the method for other auxiliary means of communications by improving the single-chip microcomputer frequency of operation.Employing extends out the technical scheme of CAN (ControllerArea Network, be controller zone network) bus, though can solve the insecure problem of communication, but owing to need extend out CAN bus communication mode, make the complexity that system design becomes, and increased system cost greatly.And this mode one that improves the baud rate of single-chip microcomputer frequency of operation reduction communication is limited by the maximum operation frequency of single-chip microcomputer, the 2nd, need the performance of sacrificial section communication, and under single-chip microcomputer is operated in situation near highest frequency, can bring certain influence to system reliability.
Therefore, be necessary prior art is improved.
Summary of the invention
The objective of the invention is to,, provide a kind of simple, low-cost, do not increasing any hardware device and do not reducing under the prerequisite of communication baud rate, improve the microcontroller serial port data receive method of the response speed of single-chip microcomputer at the above-mentioned shortcoming of prior art.
Technical scheme of the present invention is:
A kind of microcontroller serial port data receive method is provided, has may further comprise the steps:
A, single-chip microcomputer response serial ports look-at-me are preserved field data, adopt interrupt mode to receive first serial data of a communications protocol;
B, change the serial data receiving mode into query pattern, whether inquiry receiving new serial data;
C, when receiving new serial data, handle described new serial data, behind all serial datas of receiving described communications protocol, eject described field data.
Microcontroller serial port data receive method of the present invention, wherein, described steps A comprises:
The serial data receiving mode of A1, single-chip microcomputer is set to interrupt mode, when receiving the serial ports look-at-me, respond described serial ports look-at-me, preserve field data, call first serial data that the Interrupt Process function receives described communications protocol, the inquiry of single-chip microcomputer master routine is also handled described first serial data.
Microcontroller serial port data receive method of the present invention, wherein, described step C is further comprising the steps of:
C1, when not receiving new serial data, eject described field data.
Microcontroller serial port data receive method of the present invention, wherein, among the described step C, a described communications protocol comprises 10~20 serial datas.
The communication mode of the present invention by adopting interrupt mode to combine with query pattern at microcontroller serial port, significantly reduced the processing time of single-chip microcomputer when response is interrupted, do not increasing any hardware device and do not reducing under the prerequisite of communication baud rate, improve the response speed of single-chip microcomputer, guaranteed the reliability of communication.
Description of drawings
Fig. 1 forms synoptic diagram at the serial data processing time of the prior art;
Fig. 2 forms synoptic diagram break period for single-chip microcomputer of the prior art responds;
Fig. 3 forms synoptic diagram break period for the response of the single-chip microcomputer of the embodiment of the invention;
Fig. 4 is the microcontroller serial port data receive method process flow diagram of the embodiment of the invention.
Embodiment
Below in conjunction with accompanying drawing, will be described in detail preferred embodiment of the present invention.
In the Single Chip Microcomputer (SCM) system of reality, just can go to handle it after having only master routine to detect to have received a complete communications protocol.And in the actual communication, a communications protocol generally also is to send data continuously, till all data transmissions of this communications protocol finish.
Go up according to this principle, microcontroller serial port data receive method flow process proposed by the invention may further comprise the steps as shown in Figure 4:
S101, single-chip microcomputer adopt interrupt mode to receive first serial data of a communications protocol;
The serial data receiving mode of single-chip microcomputer is set to interrupt mode, after single-chip microcomputer receives a serial ports look-at-me, respond this look-at-me at once, field data is saved in the storehouse, elapsed time T3, call first serial data that the Interrupt Process function receives a communications protocol, the master routine of single-chip microcomputer is handled first serial data that receives, elapsed time T4;
S102, change microcontroller serial port Data Receiving pattern into query pattern;
After the single-chip microcomputer master routine is handled first serial data, not withdrawing from once and carrying out the ejection data is the operation of elapsed time T5, but changing the serial data receiving mode of single-chip microcomputer into query pattern by interrupt mode, the serial data of back will no longer trigger singlechip interruption this moment;
Whether S103, single-chip microcomputer have received new serial data with the fastest speed inquiry under query pattern;
If received new serial data, then carry out and handle this new serial data, elapsed time T4, behind all serial datas of receiving a communications protocol, the field data in the pop-up a stack, elapsed time T5; If do not receive next serial data, then the field data in the pop-up a stack can then be carried out with the assurance program.
After the serial data receive mode that interruption and inquiry combine more than adopting, if n serial data of same reception, the time that the present invention consumed is T3+n*T4+T5, and it is formed as shown in Figure 3.And the conventional used time of method that receives by byte is n* (T3+T4+T5), receives n data as can be seen equally, and this method is than the time of having saved n* (T3+T4+T5)-(T3+n*T4+T5)=(n-1) * (T3+T5) by existing method.
Microcontroller serial port data receive method provided by the invention, when the byte number n of a communications protocol was big more, the time of saving was also many more.But because single-chip microcomputer will be monopolized by serial communication under inquiry mode, the big more single-chip microcomputer time that takies of n is also just many more, so the value of n neither be the bigger the better in actual the use, general n is for best between the 10-20.So just can under the situation of identical frequency of operation, increase substantially the serial data response speed of single-chip microcomputer, improve processing power, increase the reliability of communication.Especially be fit to be applied to the system of the frequent handling interrupt requests of needs such as interconnection type water saving control system.
Should be understood that, for those of ordinary skills, can be improved according to the above description or conversion, and all these improvement and conversion all should belong to the protection domain of claims of the present invention.

Claims (4)

1. microcontroller serial port data receive method may further comprise the steps:
A, single-chip microcomputer response serial ports look-at-me are preserved field data, adopt interrupt mode to receive first serial data of a communications protocol;
B, change the serial data receiving mode into query pattern, whether inquiry receiving new serial data;
C, when receiving new serial data, handle described new serial data, behind all serial datas of receiving described communications protocol, eject described field data.
2. microcontroller serial port data receive method as claimed in claim 1 is characterized in that, described steps A comprises:
The serial data receiving mode of A1, single-chip microcomputer is set to interrupt mode, when receiving the serial ports look-at-me, respond described serial ports look-at-me, preserve field data, call first serial data that the Interrupt Process function receives described communications protocol, the inquiry of single-chip microcomputer master routine is also handled described first serial data.
3. microcontroller serial port data receive method as claimed in claim 1 is characterized in that, described step C is further comprising the steps of:
C1, when not receiving new serial data, eject described field data.
4. as claim 1,2 or 3 described microcontroller serial port data receive methods, it is characterized in that among the described step C, a described communications protocol comprises 10~20 serial datas.
CN 200910109543 2009-08-07 2009-08-07 Serial port data receiving method of single chip microcomputer Pending CN101989249A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN 200910109543 CN101989249A (en) 2009-08-07 2009-08-07 Serial port data receiving method of single chip microcomputer

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN 200910109543 CN101989249A (en) 2009-08-07 2009-08-07 Serial port data receiving method of single chip microcomputer

Publications (1)

Publication Number Publication Date
CN101989249A true CN101989249A (en) 2011-03-23

Family

ID=43745788

Family Applications (1)

Application Number Title Priority Date Filing Date
CN 200910109543 Pending CN101989249A (en) 2009-08-07 2009-08-07 Serial port data receiving method of single chip microcomputer

Country Status (1)

Country Link
CN (1) CN101989249A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102495813A (en) * 2011-12-02 2012-06-13 西安大唐电信有限公司 Mining embedded multi-serial-port inquiring method
CN107025204A (en) * 2017-05-05 2017-08-08 北京世纪东方国铁科技股份有限公司 One kind judges the available method of board data transmit-receive passage and car-mounted device
CN108304335A (en) * 2018-02-07 2018-07-20 南京南瑞继保电气有限公司 A method of the indefinite long message of serial ports is received by DMA
CN110764926A (en) * 2019-09-23 2020-02-07 北京控制工程研究所 1553B bus RT (reverse transcription) end message stack serial-parallel cross query method

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102495813A (en) * 2011-12-02 2012-06-13 西安大唐电信有限公司 Mining embedded multi-serial-port inquiring method
CN102495813B (en) * 2011-12-02 2014-07-23 西安大唐电信有限公司 Mining embedded multi-serial-port inquiring method
CN107025204A (en) * 2017-05-05 2017-08-08 北京世纪东方国铁科技股份有限公司 One kind judges the available method of board data transmit-receive passage and car-mounted device
CN107025204B (en) * 2017-05-05 2021-03-23 北京世纪东方国铁科技股份有限公司 Method for judging availability of board card data receiving and transmitting channel and vehicle-mounted device
CN108304335A (en) * 2018-02-07 2018-07-20 南京南瑞继保电气有限公司 A method of the indefinite long message of serial ports is received by DMA
CN110764926A (en) * 2019-09-23 2020-02-07 北京控制工程研究所 1553B bus RT (reverse transcription) end message stack serial-parallel cross query method
CN110764926B (en) * 2019-09-23 2022-04-08 北京控制工程研究所 1553B bus RT (reverse transcription) end message stack serial-parallel cross query method

Similar Documents

Publication Publication Date Title
CN101403982B (en) Task distribution method, system for multi-core processor
EP2210368B1 (en) Energy efficient ethernet using active/idle toggling
US9110668B2 (en) Enhanced buffer-batch management for energy efficient networking based on a power mode of a network interface
US7830882B2 (en) Switch scaling for virtualized network interface controllers
US7836195B2 (en) Preserving packet order when migrating network flows between cores
CN106095716A (en) A kind of serial port communication method based on head and the tail round-robin queue
CN101989249A (en) Serial port data receiving method of single chip microcomputer
CN201639589U (en) Embedded dual-redundant network card based on ARM
US9794077B2 (en) Control method, device and optical transceiver
CN101699795B (en) Message congestion processing method and system
CN110995507B (en) Network acceleration controller and method
US20130250760A1 (en) Communication link with intra-packet flow control
US8982757B2 (en) Nonlinear power state transitioning
CN102750245A (en) Message receiving method, module and system as well as device
CN104486187B (en) A kind of CAN communication device and method of dynamic synchronization
CN101841476A (en) Message processing method, device and network equipment
US20090319810A1 (en) Receiving apparatus and activation control method for receiving apparatus
CN101478487A (en) Control method and apparatus for Ethernet exchange device working rate
CN106375240B (en) Ethernet message forwarding method and system between a kind of Multi-netmouth
CN104821895B (en) A kind of power-economizing method and device
CN105262705A (en) Method for reducing on-chip network static power consumption on the basis of on-duty buffer memory
CN101383819B (en) Asynchronous serial data line information transceiving method and asynchronous serial transceiver
CN109800201A (en) The driving method of RS485 real-time tranception control based on linux
US9619005B2 (en) Apparatus and method for saving power of USB device
US8214665B2 (en) Method and system for transmit queue management for energy efficient networking

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C12 Rejection of a patent application after its publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20110323