您的位置:山东大学 -> 科技期刊社 -> 《山东大学学报(工学版)》

山东大学学报 (工学版) ›› 2020, Vol. 50 ›› Issue (3): 24-30.doi: 10.6040/j.issn.1672-3961.0.2019.705

• 机器学习与数据挖掘 • 上一篇    下一篇

基于UART串口的多机通讯

马金平()   

  1. 山东大学机械工程学院,山东 济南 250061
  • 收稿日期:2019-11-19 出版日期:2020-06-20 发布日期:2020-06-16
  • 作者简介:马金平(1986—),男,山东胶南人,硕士,主要研究方向为机械制造及自动化,高分子材料科学与工程,创新创业教育等. E-mail:mjp@sdu.edu.cn
  • 基金资助:
    国家科技部创新方法工作专项资助项目(2017IM030100)

A multi-microcontroller communication method based on UART asynchronous serial communication protocol

Jinping MA()   

  1. School of Mechanical Engineering, Shandong University, Jinan 250061, Shandong, China
  • Received:2019-11-19 Online:2020-06-20 Published:2020-06-16
  • Supported by:
    国家科技部创新方法工作专项资助项目(2017IM030100)

摘要:

针对目前不同物联网设备之间多机通讯模块繁多、设备结构复杂、成本高的问题,提出一种基于通用异步收发传输器(universal asynchronous receiver/transmitter,UART)串口的多机通讯方法。基于微控制器自带的UART串口通讯方式,利用控制线控制通讯设备对通信线路的占用,采用主从控制策略,设定通讯协议和通讯主机、从机,主机作为信息转发和识别的单元,从机组成信息处理的单元,并通过通讯协议实现多从机扩展的功能。通过移植μC/OS-Ⅱ操作系统到STM32微控制器上,借助μC/OS-Ⅱ的实时多任务特性,将信息的接收、发送和识别设计成不同优先级的任务。试验结果表明,多机分时通讯方法能够实现主机、从机的信息接收、发送、识别的功能和多机可靠稳定的通讯,解决传统UART方式无法实现多机互相通讯的问题,为物联网设备的多机通讯提供一种可行方案。

关键词: 串口, 多机通讯, 通讯协议, 微控制器, 嵌入式系统

Abstract:

To reduce the additional communication modules, complexity and costs of the different Internet of Things(IoT) devices communication, a multi-microcontroller communication method based on UART asynchronous serial ports was proposed. Based on the universal asynchronous receiver/transmitter(UART) serial communication method of the microcontroller, the control line was utilized to control the usage of the communication lines by the communication device, and a method of occupying the signal line by multiple machines in a time-sharing manner was realized. The master-slave control strategy was used to set the communication protocol. The master implements signal forwarding and identification, and the slave got signals from the master to achieve reliable and stable communication among multiple machines. By transplanting the μC/OS-Ⅱ operating system to the STM32 microcontroller, and using the real-time multitasking characteristics of μC/OS-Ⅱ, the signal reception, transmission and identification were designed into tasks of different priorities, and the master and the slave were realized. The functions of information receiving, sending and identification and the characteristics of multi-slave expansion were achieved through the communication protocol, solving the problem of multi-microcontroller communication that the traditional UART method could not achieve. The feasibility of the proposed method was verified through experiments, which provided a new solution for multi-microcontroller communication of edge devices in the Internet of Things.

Key words: serial port, multi-microcontroller communication, communication protocol, microcontroller, embedded systems

中图分类号: 

  • TP391.8

图1

主机与从机线路连接原理图"

图2

TLL电平与RS-232电平的对比"

表1

主从机通讯协议结构"

数据 长度
信号头 8
通讯类型 8
源地址 8
目标地址 8
帧长度 7
奇偶校验 1
信号结尾 32
信号内容 0~920

图3

μC/OS-Ⅱ的任务调度原理"

图4

单片机核心板结构"

图5

TTL转RS-232电平转换芯片"

图6

主机和从机接线布局"

表2

试验协议编码"

数据 数值
信号头 AA
通讯类型 00
源地址 **
目标地址 **
帧长度 0B
奇偶校验 **
信号结尾 CC 33 3C C3
信号内容 01

图7

主机和从机接收到的信息"

1 徐翀, 杨锐涛, 成正涛. 物联网环境下的智能家居发射控制系统的设计[J]. 科技风, 2019, (30): 103.
XU Chong , YANG Ruitao , CHENG Zhengtao . Design of smart home launch control system in internet of things environment[J]. Technology Wind, 2019, (30): 103.
2 ALOZIE A , WESTPHAL B , KISCHE S . Surgical revision after percutaneous mitral valve repair by edge-to-edge device: when the strategy fails in the highest risk surgical population[J]. European Journal of Cardio Thoracic Surgery, 2014, 46 (1): 55- 60.
3 GHANBARI Z , JAFARI N N , HOSSEINZADEH M , et al. Resource allocation mechanisms and approaches on the internet of things[J]. Cluster Computing, 2019, (22): 102- 106.
4 ALVI S A, SHAH G A, MAHMOOD W. Energy efficient green routing protocol for internet of multimedia things[C]//2015 IEEE Tenth International Conference on Intelligent Sensors, Sensor Networks and Information Processing (ISSNIP). Singapore: IEEE, 2015: 426.
5 赵红焱. 基于Delphi的实验室设备通讯实现[J]. 涟钢科技与管理, 2019, (5): 60- 62.
ZHAO Hongyan . Delphi-based laboratory equipment communication implementation[J]. Lian Steel Technology and Management, 2019, (5): 60- 62.
6 王广斌. 基于串口的OPC通讯技术在油库的应用[J]. 石油库与加油站, 2019, 28 (4): 25- 28.
WANG Guangbin . Application of OPC communication technology based on serial port in oil depot[J]. Oil Depot and Gas Station, 2019, 28 (4): 25- 28.
7 赵健, 张鑫褆, 李佳明, 等. 群体智能2.0研究综述[J]. 计算机工程, 2019, 45 (12): 1- 7.
ZHAO Jian , ZHANG Xinti , LI Jiaming , et al. Research review of crowd intelligence 2.0[J]. Computer Engineering, 2019, 45 (12): 1- 7.
8 孙文磊, 张学东, 熊宗慧, 等. 智能制造及其关键技术[J]. 新疆大学学报(自然科学版), 2019, 36 (4): 379- 386.
SUN Wenlei , ZHANG Xuedong , XIONG Zonghui , et al. Intelligent manufacturing and its key technologies[J]. Journal of Xinjiang University (Natural Science Edition), 2019, 36 (4): 379- 386.
9 SHINICHI Fujimoto , HIROSHI Inai , JIRO Yamakita . Performance evaluation of packet reassembly at an edge device in ATM-LANS[J]. Electronics & Communications in Japan, 2001, 84 (1): 40- 48.
10 蒋元中, 金浪滨, 汤杭森, 等. 基于串口通讯的闸站监控数据共享方案的设计与实现[J]. 浙江水利科技, 2019, 47 (1): 62- 63.
JIANG Yuanzhong , JIN Langbin , TANG Hangsen , et al. Design and implementation of monitoring data sharing scheme based on serial port communication[J]. Zhejiang Hydrotechnics, 2019, 47 (1): 62- 63.
11 林宏翔, 罗中良, 魏晓慧, 等. 基于串口通讯的程控射频开关控制器设计[J]. 日用电器, 2018, (10): 94- 98.
LIN Hongxiang , LUO Zhongliang , WEI Xiaohui , et al. Design of remote RF switch controller based on serial communication[J]. Electrical Appliances, 2018, (10): 94- 98.
12 张兴宇, 韩策, 曹雷天, 等. 基于串口触摸屏在机电控制系统中的应用[J]. 科技经济导刊, 2018, 26 (18): 46.
ZHANG Xingyu , HAN Ce , CAO Leitian , et al. Application of touch screen based on serial port in electromechanical control system[J]. Technology and Economic Guide, 2018, 26 (18): 46.
13 路染妮. 探究单片机的多串口扩展技术的设计[J]. 自动化与仪器仪表, 2018, (9): 137- 140.
LU Ranni . The design of multi serial port expansion technology[J]. Automation and Instrumentation, 2018, (9): 137- 140.
14 邵金菊, 曲金玉, 高松, 等. 基于RS232串行通信的测距综合实验设计[J]. 教育现代化, 2019, 6 (68): 134- 136.
SHAO Jinju , QU Jinyu , GAO Song , et al. Comprehensive experimental design of ranging based on RS232 serial communication[J]. Education Window, 2019, 6 (68): 134- 136.
15 黄建刚, 张敏, 罗正华. 支持多点远距离通信的RS-232串行总线系统[J]. 成都大学学报(自然科学版), 2017, 36 (2): 172- 175.
HUANG Jiangang , ZHANG Min , LUO Zhenghua . RS-232 serial bus system supporting multi-point long-distance communication[J]. Journal of Chengdu University (Natural Science Edition), 2017, 36 (2): 172- 175.
16 张思超.基于uC/OS-Ⅱ的多路信号采集及控制系统[D].济南:山东师范大学, 2016.
ZHANG Sichao. Multi-channel signal acquisition and control system based on uC/OS-Ⅱ[D]. Jinan: Shandong Normal University, 2016.
17 楚红雨, 李磊民, 黄玉清, 等. 实时操作系统uC/OS-Ⅱ在ARM9上移植的实现[J]. 计算机工程, 2005, 31 (20): 226- 228.
CHU Hongyu , LI Leimin , HUANG Yuqing , et al. Implementation of porting RTOS uC/OS-Ⅱ to ARM9[J]. Computer Engineering, 2005, 31 (20): 226- 228.
18 拉伯罗斯, 邵贝贝. uC/OS-Ⅱ:源码公开的实时嵌入式操作系统[M]. 北京: 中国电力出版社, 2001.
19 梁小骜, 宋庆国, 王勃. uCOS-Ⅲ在Cortex-M4平台上的移植和实现[J]. 电子技术与软件工程, 2017, (16): 199- 201.
LIANG Xiaoao , SONG Qingguo , WANG Bo . Migration and implementation of uCOS-Ⅲ on the Cortex-M4 platform[J]. Electronic Technology and Software Engineering, 2017, (16): 199- 201.
[1] 王泽静1,2,秦敬玉1*,米春旭1. 高精度电阻数据自动采集与动态显示系统设计[J]. 山东大学学报(工学版), 2010, 40(4): 133-137.
[2] 孙 科,刘 刚,房建成 . 基于ARM和DSP的嵌入式导航计算机方案设计[J]. 山东大学学报(工学版), 2007, 37(1): 23-26 .
Viewed
Full text


Abstract

Cited

  Shared   
  Discussed   
[1] 张永花,王安玲,刘福平 . 低频非均匀电磁波在导电界面的反射相角[J]. 山东大学学报(工学版), 2006, 36(2): 22 -25 .
[2] 施来顺,万忠义 . 新型甜菜碱型沥青乳化剂的合成与性能测试[J]. 山东大学学报(工学版), 2008, 38(4): 112 -115 .
[3] 韩雪. 平庄西露天煤矿滑坡灾害远程监测实例分析[J]. 山东大学学报(工学版), 2009, 39(4): 116 -120 .
[4] 李梁,罗奇鸣,陈恩红. 对象级搜索中基于图的对象排序模型(英文)[J]. 山东大学学报(工学版), 2009, 39(1): 15 -21 .
[5] 陈瑞,李红伟,田靖. 磁极数对径向磁轴承承载力的影响[J]. 山东大学学报(工学版), 2018, 48(2): 81 -85 .
[6] 秦通,孙丰荣*,王丽梅,王庆浩,李新彩. 基于极大圆盘引导的形状插值实现三维表面重建[J]. 山东大学学报(工学版), 2010, 40(3): 1 -5 .
[7] 刘忠国,张晓静,刘伯强,刘常春 . 视觉刺激间隔对大脑诱发电位的影响[J]. 山东大学学报(工学版), 2006, 36(3): 34 -38 .
[8] 王勇, 谢玉东.

大流量管道煤气的控制技术研究

[J]. 山东大学学报(工学版), 2009, 39(2): 70 -74 .
[9] 陈华鑫, 陈拴发, 王秉纲. 基质沥青老化行为与老化机理[J]. 山东大学学报(工学版), 2009, 39(2): 125 -130 .
[10] 卜德云 张道强. 自适应谱聚类算法研究[J]. 山东大学学报(工学版), 2009, 39(5): 22 -26 .