当前位置:网站首页>Several common device communication protocols in embedded development are summarized
Several common device communication protocols in embedded development are summarized
2022-06-21 21:09:00 【Lixiaoyao】
Focus on 、 Official account of star standard , Straight to the highlights
source : Network material
Embedded devices need to set parameters during operation , This job is often done by PC Machine to achieve , Need to design a protocol for communication between both parties , There are three representative agreements as follows :

As can be seen from the table above , Generally, the memory and computing performance of embedded devices are limited , Therefore, fixed binary is the preferred communication protocol .
One . simplicity
The guarantee agreement is a simple solution , Obscurity often means that implementation is difficult and error prone . The structure of the agreement should be plane , The scope of each domain is clear , The data field shall be designed with fixed length and position as far as possible , The notes are detailed , Documents are clear , Examples abound , Let people get started and understand as soon as possible .
Protocols generally require the following domains : Frame head , length , The frame type , Destination address , source address , data , check , Frame tail .
Two . Scalable
It must be ensured that the protocol is still competent after adding functions and changing hardware in the future , This is often achieved by reserving space , The change of agreement should only be an increase in quantity , So as not to cause changes in the protocol structure .
3、 ... and . Low coupling
Ideally, each protocol packet is atomic information , That is, this agreement package is not involved with other agreement packages , To prevent errors caused by communication frame loss and setting involvement .
Four . stability
The length of the protocol package is appropriate : Too small contains too little information , There are many kinds of protocol packages , It is easy to cause communication confusion and implicated errors ; Too big contains too much information , Poor readability , Framing and de framing are difficult , It will also bring the defect that communication is vulnerable to interference , The general protocol length is based on the minimum atomic information .
The protocol must include a verification mechanism , So that the receiver can judge whether the protocol package is received correctly and completely , If there is an error, a better mechanism is needed to ensure successful communication ( Like retransmission ).
5、 ... and . high efficiency
Classify the protocol package according to the information type , Such as : Set network information parameters , Set the current operating parameters , Can be distinguished , Facilitate program processing .
Encoding the same operations into a subset is an efficient means , Such as Read operation , Encoded as 0x0010,Write operation , Encoded as 0x0020.
Data should be designed as isomorphic as possible , If there is a difference , At least put data of the same type together , In this way, the program can make full use of pointers and linear addressing to speed up processing .
6、 ... and . Easy to implement
Minimize the use of complex algorithms , Such as , The communication link is stable , The check code of the data frame can be determined by CheckSum Instead of CRC. Unless resources are very tight , Otherwise, don't squeeze too much information into one data , Because it will bring poor readability and implementation difficulties .
7、 ... and . software development
Try to make the hardware ISR Complete the drive work , Don't let “ process ” Participate in complex temporal logic , Otherwise, the processor will stumble and the logic will be complex ! Such as :
Receive fixed length data frames , have access to DMA, Every frame received DMA_ISR Send a message to the process . Handle with care DMA Fault anomaly ( The received data frame length is normal, but the data is wrong , The data is the second half of the previous frame + The first half of this frame ).
Receive data frames of variable length , You can use state machines , When receiving “ End of frame data ” Send a message to the process when . Be careful of data disorder and timeout exception ( In case of data disorder, the state machine needs to be reset in time , Timeouts are generally monitored by timers ).
8、 ... and . Consider hardware
If the communication link is a high-speed bus ( Such as SPORT Can be up to 100Mbps), It is generally designed to generate one interrupt per frame , It's triggered by length DMA To achieve , The protocol needs to be designed with a fixed length , See Appendix A. It has high efficiency , But less flexible .
If the communication link is a low-speed bus ( Such as UART commonly 100kbps), Generally, receiving a byte generates an interrupt , The protocol can be designed into variable length frames , See Appendix B. It has high flexibility , But less efficient .

The figure above shows PC Format of sending data frame , The total length is 64 byte , yes 4 An integral multiple of a byte , Meet the vast majority 32 Features of bit processor structure alignment .
0x3C:INT8U, Frame head , Visible characters ’<’
Len:INT8U, The total data length of this frame , In the figure 4 That is to say 64
Dst:INT8U, Identifies the name of the target device ID Number
Src:INT8U, Identify the source device ID Number
Data:56 Byte storage area , The content depends on the specific communication frame ( Examples are shown in table 2)
Cmd:INT16U, Category of data frame
CS:INT8U, For all the data in front of it (62 byte ) Conduct 8 Bit accumulation and check
0x7D:INT8U, Frame tail , Visible characters ’}’
Data Domain data structure instance :

A method based on variable length format UART Communication protocol example :

PC And iWL880A( A wireless communication product , See www.rimelink.com) The communication frame adopts variable length format , As shown in the figure below . Most equipment ( It's common for PC machine ) For reception, use “ A carriage return ” The mechanism is easy to handle , In the agreement Tail Is equal to 0x0D( A newline ).
Copyright notice : Source network of this paper , Free delivery of knowledge , The copyright belongs to the original author . If involves the work copyright question , Please contact me to delete .
‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧ END ‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧
Pay attention to my WeChat official account , reply “ Add group ” Join the technical exchange group according to the rules . Click on “ Read the original ” See more sharing , Welcome to share 、 Collection 、 give the thumbs-up 、 Looking at .边栏推荐
- LeeCode435 无重叠区间
- PCA based face recognition system and face pose analysis
- Shutter input box assembly
- LeeCode70 爬楼梯
- libtorch显存管理示例
- evaluating expression ‘ew.sqlSegment != null and ew.sqlSegment != ‘‘ and ew. mybaties plus问题
- 多线程实例代码(demo)
- Cocoapods安装(Xcode8.0之后,无限卡在Setting up CocoaPods master repo)
- Show you how to distinguish several kinds of parallelism
- Idea has this class but can't find it
猜你喜欢
随机推荐
Harbor high availability cluster design and deployment (practice + video), based on offline installation
用户态热补丁原理与应用
TC3608H高效率 1.2MHz DC-DC 升压器 IC
Pfsense configuring tinc site to site tunneling tutorial
Laravel imports and exports excel using phpoffice
Jingdong 39 year old "graduate" found a new job within a week after being laid off, with a salary increase of 20%!
Adum1401arwz-rl adenault digital signal isolation module
ADUM1401ARWZ-RL 亚德诺 数字信号隔离模块
欢迎使用Markdown编辑器
AXI_ Bus_ Matrix_ 4x4 design - logic design
SMILES的基本规则
Flutter PageView组件
总结了嵌入式开发中几种常见的设备通信协议
Simulate the input and get the contents of print output
網關是什麼
Take off, annual salary: 400000+
Qu'est - ce qu'une passerelle
The final scheme of adding traceid at the C end
Data path: three people walk, there must be my teacher!
[summary of smart trash cans based on Hetai ht32f52352]









