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

Serial port simulating method for embedded system Download PDF

Info

Publication number
CN102521183A
CN102521183A CN2011103963657A CN201110396365A CN102521183A CN 102521183 A CN102521183 A CN 102521183A CN 2011103963657 A CN2011103963657 A CN 2011103963657A CN 201110396365 A CN201110396365 A CN 201110396365A CN 102521183 A CN102521183 A CN 102521183A
Authority
CN
China
Prior art keywords
serial port
data
timer
pin
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.)
Granted
Application number
CN2011103963657A
Other languages
Chinese (zh)
Other versions
CN102521183B (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

Images

Landscapes

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

Abstract

The invention discloses a serial port simulating method for an embedded system. The invention discloses the serial port simulating method for the embedded system by a software mode. The method comprises the following steps that: general-purpose IO (input-output) pins and interruptable IO pins of an MCU (Micro Control Unit), and a timer are used to simulate the serial port, and a sampling interval is controlled by the timer when data is received; serial port binary bit data stream is test and received, and the data received by the serial port is synthesized according to the set data bits, stop bits and parity bits; the data receiving error caused by error accumulation caused by the instability of the timer is avoided by utilizing IO interrupt; and the time of sending each bit data is controlled by the timer when the data is received by the serial port to simulate the data sending of the serial port. The invention aims to adopt the software mode to simulate the serial port in the traditional system, so that the cost of a hardware expansion serial port chip is reduced, thereby the profit margin of products is improved, and the higher economic efficiency is brought.

Description

The simulative serial port method that is used for embedded system
Technical field
The present invention relates to a kind of method that is used for embedded system with the mode simulative serial port of use software, utilize the universal I pin of MCU and can interrupt reception and the transmission of the interruption combination timer interruption of IO pin with the mode simulative serial port completion data of software.
Background technology
In industrial circle serial ports use and general; A lot of matured products occur because the variation of customer demand through regular meeting; Need to increase some function; And these functions need be used extra serial ports, but existing matured product do not have extra idle serial ports again, solve not only uneconomical but also increase extra research and development design cost if take to change MCU or increase extra serial ports expansion chip for this demand.
Summary of the invention
The present invention carries out the reception and the transmission of data through IO pin and the timer break simulation serial ports that utilizes MCU, is not changing MCU and is increasing under the situation of extra serial ports expansion chip, increases research and development input and hardware cost that serial ports reduces product.
To achieve these goals, technical scheme of the present invention is interrupted IO pin, universal I pin and the timer simulative serial port through MCU.When simulative serial port receives data; The reception pin down trigger of MCU starts sample clock generator; The baud rate that the fixed time interval of said sample clock generator is set according to simulative serial port calculates; Timer starts the back and in each SI the state of the reception IO of simulative serial port is sampled; Obtain the state of a data bit of the data stream that the current time serial ports receives, when the data bit that samples a byte after, stop to sample, piece together the data of a byte according to the data bit that samples in this cycle.When simulative serial port sends data; Set timer cycle according to the simulative serial port baud rate; Start timer, the data bit according to the data that will send in each cycle is set the state that simulative serial port sends the data pin, after the data transmission of a byte is accomplished, stops timer.
As specializing, the step that said simulative serial port receives data is:
The IO that 1. the reception pin of MCU simulative serial port is set is that low level triggers interruption, and wherein said reception pin is for can interrupt the IO pin;
2. calculate the cycle of timer according to the baud rate of simulative serial port setting when simulative serial port receives to have no progeny in the pin triggering, forbid that simulative serial port receives the triggering interruption of pin, starts timer;
Wherein, timer cycle=1/ (simulative serial port baud rate * 2) of step described in 2.
3. have no progeny during timer triggers the first state of the reception pin that reads simulative serial port if simulative serial port receives the state of pin to be high level then to represent that simulative serial port receives data and makes mistakes, is forbidden timer, gets back to step 1.;
If the state of simulative serial port reception pin is low level then representes that simulative serial port reception data start bit is correct, reset timer cycle, restart timer, jump to step and 4. continue;
Wherein, the timer cycle=1/ simulative serial port baud rate of step described in 3.
4. have no progeny during timer the triggers state of the reception pin that reads simulative serial port is high level then representes that it is 1 data that simulative serial port receives a place value if simulative serial port receives the state of pin;
Be low level then represent that it is 0 data that simulative serial port receives a place value if simulative serial port receives the state of pin;
Keep timer cycle constant, restart timer;
5. repeat above-mentioned steps 4., repeat N time after, 6. the no parity check bit walk jumps to step, has check bit communication then to jump to step 7.;
Wherein, the check bit of the position of rest of the data bit of N=simulative serial port setting+simulative serial port setting+simulative serial port setting
6. piece together byte to the data step-by-step that receives and deposit send buffer in, the notice upper level applications has received a byte data;
7. the parity checking of the number of the high position of the data bit that receives of statistics and setting contrasts; If the number of a high position that counts is consistent with the parity checking of setting; Then piece together byte to the data step-by-step that receives and deposit send buffer in, the notice upper level applications has received a byte data; If the number of a high position that counts and the parity checking of setting are inconsistent, abandon the data bit that this receives;
8. stop timer and forbid that simultaneously timer interrupts, repeating step is 1. to 7. accomplishing the duration data receiving course.
As specializing, the step that said simulative serial port sends data is:
Keeping when (1) no datat is sent sending pin is high level, and wherein sending pin is the universal I pin;
(2) when the user need send data, set timer cycle, putting and sending pin is low level, starts timer;
Wherein, the timer cycle described in the step (2)=1/ simulative serial port baud rate
(3) have no progeny in the timer, according to the lowest order of data to be sent set send pin level one of the data shift right of sending;
Wherein, lowest order is 1 transmission pin maintenance high level is set that lowest order is 0 transmission pin maintenance low level is set
(4) repeating step (3) sends until current byte and accomplishes, and no parity check sends data and jumps to step (5), has parity checking then to jump to step (6);
(5) putting the transmission pin is high level, accomplishes the transmission of current byte, jumps to the transmission that step (1) continues next byte;
(6) level of the transmission pin in the following timing cycle is set according to 1 the number of sending in parity checking of setting and step (3)~(4);
(7) putting transmission IO is high level, and accomplishing the transmission of current byte and keeping the timer cycle of this setting is the cycle more than 2, jumps to the transmission that step (1) continues next byte.
Method provided by the invention can not changed design proposal and not increase simultaneously the serial ports quantity that increases entire product under the condition of extra hardware; To satisfy user's demand; The method can directly reduce the input of the R&D costs brought of change hardware plan, also can reduce the increase that increases additional hardware and then control hardware cost simultaneously.
Description of drawings
Fig. 1 is the initial IO down trigger moment of the present invention and receives the timer interruption moment synoptic diagram in the data procedures;
Fig. 2 is the triggering synoptic diagram constantly that the timer of delivery time of the present invention interrupts.
Embodiment
Below in conjunction with accompanying drawing and embodiment the present invention is further specified.
In the process that receives data, utilization can be interrupted the beginning of the low level interruption judgement reception data of IO pin.Begin to receive after the data timing cycle that calculates timer according to communication baud rate, set timer and interrupt., timer judges the data bit that receives in interrupting.Number according to data bit, check bit, position of rest receives enough data bit in timer interrupts.Piece together the data of a byte according to the data bit that receives.As shown in Figure 1, for the timer in the initial IO down trigger moment of the present invention and the reception data procedures interrupts constantly.
As shown in Figure 2, be the triggering synoptic diagram constantly that interrupts through the timer of delivery time of the present invention.In the process of sending data, according to the interrupt cycle of sending the communication baud rate calculating timer that will send data.When interrupting, each timer sets the state of the IO pin of MCU according to the current data bit that will send.Data bit send to be accomplished the state of back IO pin of needs setting when determining that according to the number of 1 in the data bit of parity checking of setting and transmission timer interrupts next time.Sent that to keep after the byte sending the IO pin be the time that high level continues to be no less than 2 timer cycles.
The above is merely preferred embodiment of the present invention, is not to be used to limit protection scope of the present invention.

Claims (3)

1. the simulative serial port method that is used for embedded system, said method is characterized in that through interrupted IO pin, universal I pin and the timer simulative serial port of MCU,
When simulative serial port receives data; The reception pin down trigger of MCU starts sample clock generator; The baud rate that the fixed time interval of said sample clock generator is set according to simulative serial port calculates; Timer starts the back and in each SI the state of the reception IO of simulative serial port is sampled; Obtain the state of a data bit of the data stream that the current time serial ports receives, when the data bit that samples a byte after, stop to sample, piece together the data of a byte according to the data bit that samples in this cycle;
When simulative serial port sends data; Set timer cycle according to the simulative serial port baud rate; Start timer, the data bit according to the data that will send in each cycle is set the state that simulative serial port sends the data pin, after the data transmission of a byte is accomplished, stops timer.
2. the simulative serial port method that is used for embedded system according to claim 1 is characterized in that, the step that said simulative serial port receives data is:
The IO that 1. the reception pin of MCU simulative serial port is set is that low level triggers interruption, and wherein said reception pin is for can interrupt the IO pin;
2. calculate the cycle of timer according to the baud rate of simulative serial port setting when simulative serial port receives to have no progeny in the pin triggering, forbid that simulative serial port receives the triggering interruption of pin, starts timer;
Wherein, timer cycle=1/ (simulative serial port baud rate * 2) of step described in 2.
3. have no progeny during timer triggers the first state of the reception pin that reads simulative serial port if simulative serial port receives the state of pin to be high level then to represent that simulative serial port receives data and makes mistakes, is forbidden timer, gets back to step 1.;
If the state of simulative serial port reception pin is low level then representes that simulative serial port reception data start bit is correct, reset timer cycle, restart timer, jump to step and 4. continue;
Wherein, the timer cycle=1/ simulative serial port baud rate of step described in 3.
4. have no progeny during timer the triggers state of the reception pin that reads simulative serial port is high level then representes that it is 1 data that simulative serial port receives a place value if simulative serial port receives the state of pin;
Be low level then represent that it is 0 data that simulative serial port receives a place value if simulative serial port receives the state of pin;
Keep timer cycle constant, restart timer;
5. repeat above-mentioned steps 4., repeat N time after, 6. the no parity check bit walk jumps to step, has check bit communication then to jump to step 7.;
Wherein, the check bit of the position of rest of the data bit of N=simulative serial port setting+simulative serial port setting+simulative serial port setting
6. piece together byte to the data step-by-step that receives and deposit send buffer in, the notice upper level applications has received a byte data;
7. the parity checking of the number of the high position of the data bit that receives of statistics and setting contrasts; If the number of a high position that counts is consistent with the parity checking of setting; Then piece together byte to the data step-by-step that receives and deposit send buffer in, the notice upper level applications has received a byte data; If the number of a high position that counts and the parity checking of setting are inconsistent, abandon the data bit that this receives;
8. stop timer and forbid that simultaneously timer interrupts, repeating step is 1. to 7. accomplishing the duration data receiving course.
3. the simulative serial port method that is used for embedded system according to claim 1 is characterized in that, the step that said simulative serial port sends data is:
Keeping when (1) no datat is sent sending pin is high level, and wherein sending pin is the universal I pin;
(2) when the user need send data, set timer cycle, putting and sending pin is low level, starts timer;
Wherein, the timer cycle described in the step (2)=1/ simulative serial port baud rate
(3) have no progeny in the timer, according to the lowest order of data to be sent set send pin level one of the data shift right of sending;
Wherein, lowest order is 1 transmission pin maintenance high level is set that lowest order is 0 transmission pin maintenance low level is set
(4) repeating step (3) sends until current byte and accomplishes, and no parity check sends data and jumps to step (5), has parity checking then to jump to step (6);
(5) putting the transmission pin is high level, accomplishes the transmission of current byte, jumps to the transmission that step (1) continues next byte;
(6) level of the transmission pin in the following timing cycle is set according to 1 the number of sending in parity checking of setting and step (3)~(4);
(7) putting transmission IO is high level, and accomplishing the transmission of current byte and keeping the timer cycle of this setting is the cycle more than 2, jumps 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 true CN102521183A (en) 2012-06-27
CN102521183B 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 (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103268248A (en) * 2012-10-17 2013-08-28 厦门雅迅网络股份有限公司 Method for simulating multi-circuit dual-full-duplex serial port under ARM (advanced RISC machine) platform LINUX system
CN105183686A (en) * 2015-07-30 2015-12-23 深圳市振邦智能科技有限公司 Method and apparatus for starting simulated serial port communication
CN105468554A (en) * 2015-11-27 2016-04-06 宁波三星医疗电气股份有限公司 Method for realizing polarity-adaptive UART simulation
CN106960168A (en) * 2016-01-11 2017-07-18 杭州海康威视数字技术股份有限公司 A kind of card number data capture method and device
CN107357742A (en) * 2017-07-14 2017-11-17 上海瀚银信息技术有限公司 A kind of serial ports analogy method and computer equipment
CN107423239A (en) * 2017-05-05 2017-12-01 山东大学 Low-power scm complete data frame method of reseptance under Halt patterns
CN105183686B (en) * 2015-07-30 2018-08-31 深圳市振邦智能科技股份有限公司 A kind of method and apparatus starting simulative serial port communication
CN108701112A (en) * 2017-11-29 2018-10-23 深圳和而泰智能控制股份有限公司 A kind of method and apparatus based on the communication of inquiry mode simulative serial port
CN109213673A (en) * 2017-07-07 2019-01-15 深圳市有方科技股份有限公司 A kind of development approach and device based on serial ports simulation software
CN110879791A (en) * 2019-09-30 2020-03-13 湖南格兰博智能科技有限责任公司 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
CN114253879A (en) * 2021-12-23 2022-03-29 北京恒源利通电力技术有限公司 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 (19)

* 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
CN103268248A (en) * 2012-10-17 2013-08-28 厦门雅迅网络股份有限公司 Method for simulating multi-circuit dual-full-duplex serial port under ARM (advanced RISC machine) platform LINUX system
CN105183686B (en) * 2015-07-30 2018-08-31 深圳市振邦智能科技股份有限公司 A kind of method and apparatus starting simulative serial port communication
CN105183686A (en) * 2015-07-30 2015-12-23 深圳市振邦智能科技有限公司 Method and apparatus for starting simulated serial port communication
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
CN106960168A (en) * 2016-01-11 2017-07-18 杭州海康威视数字技术股份有限公司 A kind of card number data capture method and device
CN107423239A (en) * 2017-05-05 2017-12-01 山东大学 Low-power scm complete data frame method of reseptance under Halt patterns
CN107423239B (en) * 2017-05-05 2019-04-30 山东大学 Low-power scm complete data frame method of reseptance under Halt mode
CN109213673A (en) * 2017-07-07 2019-01-15 深圳市有方科技股份有限公司 A kind of development approach and device based on serial ports simulation software
CN107357742A (en) * 2017-07-14 2017-11-17 上海瀚银信息技术有限公司 A kind of serial ports analogy method and computer equipment
CN108701112A (en) * 2017-11-29 2018-10-23 深圳和而泰智能控制股份有限公司 A kind of method and apparatus based on the communication of inquiry mode simulative serial port
WO2019104531A1 (en) * 2017-11-29 2019-06-06 深圳和而泰智能控制股份有限公司 Method and device for simulating serial port communication based on querying mode
CN108701112B (en) * 2017-11-29 2020-04-28 深圳和而泰智能控制股份有限公司 Method and device for simulating serial port communication based on query mode
CN110879791A (en) * 2019-09-30 2020-03-13 湖南格兰博智能科技有限责任公司 Non-blocking two-wire serial port communication simulation method
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
CN114253879A (en) * 2021-12-23 2022-03-29 北京恒源利通电力技术有限公司 Multi-channel serial port communication method and system based on software simulation

Also Published As

Publication number Publication date
CN102521183B (en) 2018-01-26

Similar Documents

Publication Publication Date Title
CN102521183A (en) Serial port simulating method for embedded system
CN102546843B (en) A kind of method by the multiple UART communication interfaces of software simulated implementation
CN102354443B (en) Wireless infrared (IR) remote control device and operating method thereof
CN101227737B (en) Method for switching double module mobile terminal from GSM to TD-SCDMA
CN101894036A (en) Mobile terminal and starting up method thereof
CN103268248B (en) The method of ARM platform LINUX system Imitating multichannel full duplex serial ports
CN103412734A (en) Method for automatically setting addresses of splicing units
CN108701112B (en) Method and device for simulating serial port communication based on query mode
CN105157294A (en) Control method and system for multi-online intelligent oil returning and multi-online system
CN105472377B (en) Television set debugging method and device
CN107357742A (en) A kind of serial ports analogy method and computer equipment
CN107423239A (en) Low-power scm complete data frame method of reseptance under Halt patterns
CN201667010U (en) Intelligent time controller
CN106067866B (en) A kind of long-range delivery method of rate electricity price based on power information acquisition system
CN102063785B (en) Method for automatically emitting infrared remote control signals and system thereof
CN101833480B (en) Method for realizing watchdog by using timer and resetting pin of singlechip
CN102945596A (en) Signal reception method of remote controller
CN101365078B (en) Remote control command code forwarding method for television set receiver
WO2021218354A1 (en) Interaction method, system, and apparatus under device low power consumption state
CN105468554A (en) Method for realizing polarity-adaptive UART simulation
CN106219673B (en) Soften the softening resin regeneration control method of water treatment facilities
CN102325222B (en) A kind of method and apparatus of carrying out event reminding by utilizing terminal equipment
CN105159129B (en) Intelligent appliance control system and control method
CN201248336Y (en) Airport bird scaring device
CN209132881U (en) A kind of narrowband Intelligent gas meter based on internet of things

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