简体   繁体   English

两个软件实体(Uart / I2C /等)之间串行通信的简单实现

[英]A simple implementation of serial communication between two software entities (Uart / I2C / etc.)

I've done many projects that include a PC & an arduino / PLC / some kind of other microcontroller / processor, and in every project we had a different protocol used for communication between the PC application and the embedded one. 我已经完成了许多项目,其中包括PC和arduino / PLC /某种其他微控制器/处理器,并且在每个项目中,我们都有不同的协议用于PC应用程序和嵌入式应用程序之间的通信。 Usually the hardware / controller developer invents a simple protocol which always changes throughout the project, and goes into the form of 通常,硬件/控制器开发人员会发明一个简单的协议,该协议在整个项目中都会不断变化,并以以下形式出现:

Barker | Size | Data | Checksum

This time I'm implementing both sides, so I figured - This has been done a million times before. 这次我要实现双方,所以我想-这已经做了一百万遍了。 There must be a base protocol for these things with implementations in C, C#, Java, and such. 这些事情必须有基本协议,并以C,C#,Java等实现。 What I'm looking for is a lightweight layer that transfers stream based serial communication into a message based one. 我正在寻找的是轻量级的层,它将基于流的串行通信转换为基于消息的消息。

I've been looking around for one for a while, but I couldn't find anything on my own. 我已经寻找了一段时间,但我自己找不到任何东西。 Do you happen to know one? 你碰巧认识一个吗?

I had exactly the same requirements for a recent project and I found nothing simple enough for low-end 8-bit microcontrollers. 我对最近的项目有完全相同的要求,但对于低端的8位微控制器,我发现并没有什么简单的方法可言。 So I designed MIN (Microcontroller Interconnect Network) to do the job (inspired by CAN and LIN). 因此,我设计了MIN(微控制器互连网络)来完成这项工作(受CAN和LIN的启发)。

The code is on github here: https://github.com/min-protocol/min (check out the wiki there). 该代码位于github上: https//github.com/min-protocol/min (请查看此处的Wiki)。

I defined a layer 0 (the UART settings) and layer 1 (the frame layer, with checksums, etc.) plus a C API. 我定义了第0层(UART设置)和第1层(带有校验和的帧层等)以及C API。

I'm also working on a higher layer that formally defines how sensor data (temperature, pressure, voltage, etc.) are packed, with a JSON representation and a tool to autogenerate the embedded code to pack/unpack them from frames. 我还在一个更高层上工作,该层正式定义了传感器数据(温度,压力,电压等)的打包方式,并带有JSON表示法和自动生成嵌入代码以将其从帧中打包/解包的工具。 The end goal is to create a Wireshark dissector that can be clipped on to the serial line and when fed with the JSON will display the signals in human-readable form. 最终目标是创建一个Wireshark解剖器,可以将其夹在串行线上,当与JSON配合使用时,它将以人类可读的形式显示信号。

I wrote a blog post showing a Hello World app running on an Arduino board (with an FTDI UART-USB breakout board carrying the data up to my host PC): 我写了一篇博客文章,展示了一个在Arduino板上运行的Hello World应用程序(通过FTDI UART-USB分支板将数据传输到我的主机PC):

https://kentindell.wordpress.com/2015/02/18/micrcontroller-interconnect-network-min-version-1-0/ https://kentindell.wordpress.com/2015/02/18/micrcontroller-interconnect-network-min-version-1-0/

This serial problem occurs so often that it would be nice if we as a community just nailed it rather than keep re-coding it for every project. 这个串行问题经常发生,如果我们作为一个社区只是钉住它而不是为每个项目继续对其进行编码,那将是一个很好的选择。

Check Open Source HDLC 检查开源HDLC

I recently came across MIN - never used this one though 我最近遇到了MIN-虽然从未使用过

Also check this Simple serial point-to-point communication protocol 还要检查此简单的串行点对点通信协议

Using X/Y/Z MODEM protocol must be a good choice to solve your problem. 使用X / Y / Z MODEM协议必须是解决您的问题的好选择。 It's easy to implement and ready-to-use. 它易于实施且易于使用。 I use X-MODEM on an ISP tool communicates with our cortex-m0 powered MCU, and it works pretty well. 我在ISP工具上使用X-MODEM与由cortex-m0驱动的MCU进行通信,并且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM