CN102521183B - Serial port simulating method for embedded system - Google Patents

Serial port simulating method for embedded system Download PDF

Info

Publication number
CN102521183B
CN102521183B CN201110396365.7A CN201110396365A CN102521183B CN 102521183 B CN102521183 B CN 102521183B CN 201110396365 A CN201110396365 A CN 201110396365A CN 102521183 B CN102521183 B CN 102521183B
Authority
CN
China
Prior art keywords
data
serial port
pin
timer
simulative serial
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
CN201110396365.7A
Other languages
Chinese (zh)
Other versions
CN102521183A (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.)
Shenzhen Clou Electronics Co Ltd
Original Assignee
Shenzhen Clou Electronics 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 Clou Electronics Co Ltd filed Critical Shenzhen Clou Electronics Co Ltd
Priority to CN201110396365.7A priority Critical patent/CN102521183B/en
Publication of CN102521183A publication Critical patent/CN102521183A/en
Application granted granted Critical
Publication of CN102521183B publication Critical patent/CN102521183B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Communication Control (AREA)
  • Dc Digital Transmission (AREA)

Abstract

The invention discloses a kind of serial port simulating method for embedded system.The invention discloses a kind of method of the mode simulative serial port using software for embedded system.This method by MCU General Purpose I/O pins, I/O pin and timer models serial ports can be interrupted, the Timer Controlling sampling interval is utilized when receiving data, detection receives serial ports binary bits data flow, the data of serial ports reception are synthesized according to the data bit, stop position, check bit of setting, the accumulation of error caused by avoiding timer unstable using I/O interrupt causes Data reception errors;The time for sending each data using Timer Controlling when serial ports is sent sends data come simulative serial port.It is contemplated that taking the mode simulative serial port of software in existing system, so as to reduce the cost of hardware expanding serial port chip, and then the profit margin of product is improved, bring higher economic benefit.

Description

Serial port simulating method for embedded system
Technical field
The present invention relates to a kind of method for embedded system simulative serial port in a manner of using software, utilize MCU's General Purpose I/O pins and the interruption of I/O pin can be interrupted combine timer interruption simulative serial port in a manner of software and complete data and connect Receive and send.
Background technology
Used in industrial circle serial ports and its generally, the change due to customer demand often occur in many matured products, Need to increase some functions, and these functions need to use extra serial ports, but existing matured product is again without extra Idle serial ports, MCU is changed or the extra serial port extended chip of increase is both uneconomical to solve if taken for this demand Increase extra R & D design cost again.
The content of the invention
The present invention carries out the reception and transmission of data by using MCU I/O pin and timer interruption simulative serial port, In the case of being changed without MCU and the extra serial port extended chip of increase, increase serial ports reduce product Innovation Input and hardware into This.
To achieve these goals, the technical scheme is that by MCU interrupt I/O pin, General Purpose I/O pins and Timer models serial ports.When simulative serial port receives data, MCU reception pin down trigger starts sample clock generator, described The baud rate that the fixed time interval of sample clock generator is set according to simulative serial port is calculated, after timer startup between each sampling Sampled every the state of the reception IO to simulative serial port, obtain a data bit of the data flow of current time serial ports reception State, stop sampling after the data bit of byte is sampled, pieced together according to the data bit sampled in this cycle The data of one byte.When simulative serial port sends data, timer period is set according to simulative serial port baud rate, starts timing Device, the state of data pin is sent in each cycle according to the data bit for the data to be sent setting simulative serial port, when a byte Data be sent completely after stop timer.
As materialization, the step of simulative serial port receives data, is:
1. the IO for receiving pin of MCU simulative serial ports is set to be interrupted for low level triggering, wherein the reception pin is can Interrupt I/O pin;
2. timer is calculated according to the baud rate of simulative serial port setting after pin triggering is interrupted when simulative serial port receives In the cycle, forbid simulative serial port to receive the triggering of pin and interrupt, start timer;
Wherein, step 2. described in timer period=1/ (simulative serial port baud rate * 2)
3. timer triggers the state for receiving pin of reading simulative serial port after interruption first, draw if simulative serial port receives The state of pin is that high level then represents that simulative serial port receives corrupt data, forbids timer, returns to step 1.;
Represent that simulative serial port reception data start bit is correct if the state of simulative serial port reception pin is low level, weight New settings timer period, timer is restarted, step is jumped to and 4. continues;
Wherein, step 3. described in the simulative serial port baud rate of timer period=1/
4. timers trigger reads the state of the reception pin of simulative serial port after interrupting, if simulative serial port receives pin State is that high level then represents that simulative serial port receives the data that a place value is 1;
Represent that simulative serial port receives the number that a place value is 0 if the state of simulative serial port reception pin is low level According to;
Keep timer period constant, restart timer;
5. repeating the above steps 4., after repeating n times, 6. no parity check bit walk jumps to step, has verification bit walk then to jump Go to step 7.;
Wherein, the verification of the stop position of the data bit of N=simulative serial ports setting+simulative serial port setting+simulative serial port setting Position
6. the data step-by-step received, which is pieced together byte deposit, receives buffering area, notice upper level applications have been received by One byte data;
7. the high-order number of the data bit received and the even-odd check contrast of setting are counted, if the high position counted Number with setting even-odd check it is consistent, then the data step-by-step received piece together byte deposit receive buffering area, notice Upper level applications have been received by a byte data;If the even-odd check of the high-order number counted and setting differs Cause, abandon this data bit received;
8. stopping timer forbidding timer interruption simultaneously, repeat step is 1. to 7. completion duration data receive process.
As materialization, the step of simulative serial port sends data, is:
(1) it is high level to keep sending pin when no data is sent, wherein it is General Purpose I/O pins to send pin;
(2) when user needs to send data, timer period is set, it is low level to put and send pin, starts timer;
Wherein, the simulative serial port baud rate of the timer period described in step (2)=1/
(3) after timer interruption, set according to the lowest orders of data to be sent and send the level of pin sending Data shift right one;
Wherein, lowest order is that 1 setting sends pin holding high level, and lowest order is 0 and sets transmission pin to keep low Level
(4) until current byte is sent completely, no parity check sends data and jumps to step (5) repeat step (3), there is odd even Verification then jumps to step (6);
(5) it is high level to put and send pin, completes the transmission of current byte, jumps to step (1) and continues next byte Send;
(6) following timing week is set according to 1 number sent in the even-odd check of setting and step (3)~(4) The level of transmission pin in phase;
(7) it is high level to put and send IO, completes the transmission of current byte and keeps the timer period that this sets as 2 In the cycle above, jump to the transmission that step (1) continues next byte.
Method provided by the invention can be under conditions of being changed without design while not increasing extra hardware cost Increase the serial ports quantity of whole product, to meet the needs of user, the method can directly reduce what change hardware plan was brought The input of R&D costs, while the increase for increasing extra hardware and then controlling hardware cost can also be reduced.
Brief description of the drawings
Fig. 1 is to illustrate at the starting I/O interrupt triggering moment of the present invention and the timer interruption moment received in data procedures Figure;
Fig. 2 is the schematic diagram of the triggering moment of the timer interruption of the delivery time of the present invention.
Embodiment
The present invention is further described with reference to the accompanying drawings and detailed description.
During data are received, the low level that utilization can interrupt I/O pin interrupts the beginning for judging to receive data.Open The timing cycle of timer is calculated after the reception data that begin according to communication baud rate, sets timer interruption.In timer interruption Judge the data bit received.Enough data are received in timer interruption according to data bit, check bit, the number of stop position Position.Data bit according to receiving pieces together the data of a byte.As shown in figure 1, when being triggered for present invention starting I/O interrupt Carve and receive the timer interruption moment in data procedures.
As shown in Fig. 2 it is the schematic diagram by the triggering moment of the timer interruption of delivery time of the present invention.Sending number During, according to the interrupt cycle for sending the communication baud rate calculating timer that send data.Each timer interruption When set according to the data bit currently to be sent MCU I/O pin state.Data bit be sent completely after according to the odd even of setting 1 number in verification and the data bit sent determines the state of the I/O pin that needs are set during timer interruption next time.Hair Keep sending the time that I/O pin is persistently no less than 2 timer periods for high level after having sent a byte.
The foregoing is only a preferred embodiment of the present invention, is not intended to limit the scope of the present invention.

Claims (1)

1. for embedded system serial port simulating method, methods described by MCU interrupt I/O pin, General Purpose I/O pins and Timer models serial ports, it is characterised in that
When simulative serial port receives data, MCU reception pin down trigger starts sample clock generator, and the sample clock generator is determined When the interval baud rate that is set according to simulative serial port be calculated, timer start after in each sampling interval to simulative serial port The state for receiving IO is sampled, and the state of a data bit of the data flow of current time serial ports reception is obtained, when sampling Stop sampling after the data bit of one byte, the number of a byte is pieced together according to the data bit sampled in this cycle According to;
When simulative serial port sends data, timer period is set according to simulative serial port baud rate, starts timer, in each cycle The state of simulative serial port transmission data pin is set according to the data bit for the data to be sent, when the data of a byte are sent completely After stop timer;
The simulative serial port receives the step of data and is:
1. the IO for receiving pin of MCU simulative serial ports is set to be interrupted for low level triggering, wherein the reception pin is to interrupt I/O pin;
2. the cycle of timer is calculated according to the baud rate of simulative serial port setting after simulative serial port receives pin triggering interruption, Forbid simulative serial port to receive the triggering of pin to interrupt, start timer;
Wherein, step 2. described in timer period=1/ (simulative serial port baud rate * 2)
3. timer triggers the state for receiving pin of reading simulative serial port after interruption first, if simulative serial port receives pin State is that high level then represents that simulative serial port receives corrupt data, forbids timer, returns to step 1.;
Represent that simulative serial port reception data start bit is correct if the state of simulative serial port reception pin is low level, set again Determine timer period, restart timer, jump to step and 4. continue;
Wherein, step 3. described in the simulative serial port baud rate of timer period=1/
4. timers trigger reads the state of the reception pin of simulative serial port after interrupting, if simulative serial port receives the state of pin Then represent that simulative serial port receives the data that a place value is 1 for high level;
Represent that simulative serial port receives the data that a place value is 0 if the state of simulative serial port reception pin is low level;
Keep timer period constant, restart timer;
5. repeating the above steps 4., after repeating n times, 6. no parity check bit walk jumps to step, has verification bit walk then to jump to Step is 7.;
Wherein, the check bit of the stop position of the data bit of N=simulative serial ports setting+simulative serial port setting+simulative serial port setting
6. the data step-by-step received, which is pieced together byte deposit, receives buffering area, notice upper level applications have been received by one Byte data;
7. the high-order number of the data bit received and the even-odd check contrast of setting are counted, if high-order counted Number is consistent with the even-odd check of setting, then the data step-by-step received is pieced together byte deposit receives buffering area, notifies upper strata Application program has been received by a byte data;If the even-odd check of the high-order number counted and setting is inconsistent, lose Abandon this data bit received;
8. stopping timer forbidding timer interruption simultaneously, repeat step is 1. to 7. completion duration data receive process;
The simulative serial port sends the step of data and is:
(1) it is high level to keep sending pin when no data is sent, wherein it is General Purpose I/O pins to send pin;
(2) when user needs to send data, timer period is set, it is low level to put and send pin, starts timer;
Wherein, the simulative serial port baud rate of the timer period described in step (2)=1/
(3) after timer interruption, the level for sending pin is set the data sent according to the lowest order of data to be sent Move to right one;
Wherein, lowest order is that 1 setting sends pin holding high level, and lowest order is 0 and sets transmission pin to keep low level
(4) until current byte is sent completely, no parity check sends data and jumps to step (5) repeat step (3), there is even-odd check Then jump to step (6);
(5) it is high level to put and send pin, completes the transmission of current byte, jumps to the transmission that step (1) continues next byte;
(6) set according to 1 number sent in the even-odd check of setting and step (3)~(4) in a following timing cycle Transmission pin level;
(7) it is high level to put and send IO, completes the transmission of current byte and keeps the timer period that this sets as more than 2 Cycle, jump to the transmission that step (1) continues next byte.
CN201110396365.7A 2011-12-02 2011-12-02 Serial port simulating method for embedded system Active CN102521183B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201110396365.7A CN102521183B (en) 2011-12-02 2011-12-02 Serial port simulating method for embedded system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201110396365.7A CN102521183B (en) 2011-12-02 2011-12-02 Serial port simulating method for embedded system

Publications (2)

Publication Number Publication Date
CN102521183A CN102521183A (en) 2012-06-27
CN102521183B true CN102521183B (en) 2018-01-26

Family

ID=46292112

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201110396365.7A Active CN102521183B (en) 2011-12-02 2011-12-02 Serial port simulating method for embedded system

Country Status (1)

Country Link
CN (1) CN102521183B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109213673A (en) * 2017-07-07 2019-01-15 深圳市有方科技股份有限公司 A kind of development approach and device based on serial ports simulation software

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103268248B (en) * 2012-10-17 2015-12-16 厦门雅迅网络股份有限公司 The method of ARM platform LINUX system Imitating multichannel full duplex serial ports
CN105468554A (en) * 2015-11-27 2016-04-06 宁波三星医疗电气股份有限公司 Method for realizing polarity-adaptive UART simulation
CN106960168B (en) * 2016-01-11 2020-02-04 杭州海康威视数字技术股份有限公司 Card number data acquisition method and device
CN107423239B (en) * 2017-05-05 2019-04-30 山东大学 Low-power scm complete data frame method of reseptance under Halt mode
CN107357742A (en) * 2017-07-14 2017-11-17 上海瀚银信息技术有限公司 A kind of serial ports analogy method and computer equipment
CN108701112B (en) * 2017-11-29 2020-04-28 深圳和而泰智能控制股份有限公司 Method and device for simulating serial port communication based on query mode
CN110879791B (en) * 2019-09-30 2021-03-19 湖南格兰博智能科技有限责任公司 Non-blocking two-wire serial port communication simulation method
CN112000600A (en) * 2020-07-29 2020-11-27 深圳市智微智能软件开发有限公司 Method, system, device and storage medium for realizing infrared protocol through IO simulation
CN112597081A (en) * 2020-12-22 2021-04-02 青岛鼎信通讯股份有限公司 UART software implementation method based on low-voltage Internet of things sensing terminal
CN113806259B (en) * 2021-08-23 2024-06-14 宁波奥克斯电气股份有限公司 Method, device and microcontroller for simulating special communication port
CN114253879B (en) * 2021-12-23 2024-07-02 北京恒源利通电力技术有限公司 Multi-channel serial port communication method and system based on software simulation

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101471787A (en) * 2007-12-25 2009-07-01 希姆通信息技术(上海)有限公司 Method for software simulation UART based on wireless communication module
CN101510184A (en) * 2009-03-13 2009-08-19 上海微电子装备有限公司 Multichannel serial communications system and control method thereof
CN102117254A (en) * 2011-01-17 2011-07-06 青岛海信日立空调系统有限公司 Embedded-system-based asynchronous data receiving method

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101471787A (en) * 2007-12-25 2009-07-01 希姆通信息技术(上海)有限公司 Method for software simulation UART based on wireless communication module
CN101510184A (en) * 2009-03-13 2009-08-19 上海微电子装备有限公司 Multichannel serial communications system and control method thereof
CN102117254A (en) * 2011-01-17 2011-07-06 青岛海信日立空调系统有限公司 Embedded-system-based asynchronous data receiving method

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109213673A (en) * 2017-07-07 2019-01-15 深圳市有方科技股份有限公司 A kind of development approach and device based on serial ports simulation software

Also Published As

Publication number Publication date
CN102521183A (en) 2012-06-27

Similar Documents

Publication Publication Date Title
CN102521183B (en) Serial port simulating method for embedded system
CN102306136B (en) Baud rate self-adaption method based on input capture function of singlechip
CN102650947B (en) Continuous increment over-the-air upgrade method of Android handheld equipment
CN102541599B (en) Method and system for upgrading electronic equipment on line, and television
CN101860624A (en) Crash auto-restart method and mobile phone
CN108038283B (en) Virtual clock synchronization's high-efficient high coverage rate SoC verifies platform
CN108701112B (en) Method and device for simulating serial port communication based on query mode
CN104360974A (en) Method and device for automatically adjusting Baud rate of universal asynchronous receiver/transmitter (UART)
CN103268248B (en) The method of ARM platform LINUX system Imitating multichannel full duplex serial ports
CN106315758B (en) The softening resin regeneration control method of water softener
CN107357742A (en) A kind of serial ports analogy method and computer equipment
CN110148292A (en) A kind of wireless remote control decoding method and coding and decoding device
CN111897560B (en) Program upgrading system, method, device and storage medium based on NB-IoT module
CN212159910U (en) MCU integrated uncapping detection circuit and electric energy meter control chip
CN101923480B (en) Method and device for starting terminal equipment
CN104375820A (en) Event-driven processor and operating method thereof
CN103024543A (en) Implementation method and implementation device for low power consumption of set top box
CN102298095A (en) Method for ensuring accurate measurement on pulse width in multi-task singlechip system and device
KR101747123B1 (en) Method and apparatus for writing data to storage medium
CN105911852A (en) Analogue watch timing method
CN103513996A (en) Android system recovery method of terminal equipment and terminal equipment
CN102270028B (en) Automatic Loongson mainboard resetting device based on field programmable gate array (FPGA)
CN105242968B (en) A kind of remote radio frequency signal reception software coding/decoding method
CN104181909B (en) Method for determining software error in the integrated control system based on virtualization
CN109256998A (en) Control the method and system and servo motor of current of electric sampling with high precision

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant