11576 views|19 replies

411

Posts

9

Resources
The OP
 

Serial communication, frame header and frame tail checksum do not understand, God's guidance [Copy link]

 
Serial communication, 1. Do you set the frame header and frame tail checksum yourself? Is this considered a protocol? 2. I see some protocols have a frame header but no frame tail but have a checksum. Can the frame tail be present or not? 3. Is the frame tail the checksum? Is it enough to have either the frame tail or the checksum? 4. Do both the frame header and the frame tail have to be present or the frame header must be present but not the frame tail? As a newbie, I was confused while searching online. I would like to ask an expert to explain the above questions.                                                               
This post is from stm32/stm8

Latest reply

A data frame is a basic unit of data transmission, which refers to the data transmitted at one time. This can be an asynchronous serial port byte or the content of a communication protocol transmission. Obviously, as long as there is data transmission, the frame header and frame tail must exist, and the content has nothing to do with whether it is a protocol. The introduction of communication protocols is to ensure the reliability of data transmission. For this purpose, some measures must be taken, so the protocol must have a structure. The protocol structure is diverse and related to specific applications. Even the protocol itself can be hierarchical, which is actually completely consistent with the nature of communication between people. By analyzing the way people communicate with each other, it is very helpful to understand the communication protocol. It might be helpful to do some "poetry skills" first.  Details Published on 2018-7-3 17:28
 

6040

Posts

204

Resources
2
 
If it is a custom protocol, you can define it as you like, with or without anything. If it is a standard protocol, you must follow the standard.
This post is from stm32/stm8

Comments

Uh-huh  Details Published on 2018-7-2 10:58
 
 

1972

Posts

0

Resources
3
 
The purpose of adding a frame header or a frame trailer or both is to ensure the reliability of communication and the convenience of receiving data, which will be very convenient when parsing. The purpose of adding a checksum is to ensure the correctness of the communication data and to improve the reliability of communication. Generally speaking, a communication protocol will contain these two elements. Of course, the protocol you define may not contain them, and the position is also set according to personal preference. It is not required to have a frame header, frame trailer and checksum. You only need to ensure that your protocol can communicate normally and meet your needs. Other standard communication protocols, such as Modbus and Ethernet, must be implemented strictly in accordance with the protocol standards.
This post is from stm32/stm8

Comments

What counts as analysis?  Details Published on 2018-7-2 11:01
What counts as analysis?  Details Published on 2018-7-2 10:58
 
 

411

Posts

9

Resources
4
 
lcofjp posted on 2018-7-2 10:10 If it is a custom protocol, then you can define it as you like, with or without anything. If it is a standard protocol, then follow the standard.
Yes
This post is from stm32/stm8
 
 
 

411

Posts

9

Resources
5
 
bobde163 posted on 2018-7-2 10:22 The purpose of adding a frame header or a frame trailer or both is to ensure the reliability of communication and the convenience of receiving data. It will be very convenient when parsing and increase...
What is parsing?
This post is from stm32/stm8
 
 
 

411

Posts

9

Resources
6
 
bobde163 posted on 2018-7-2 10:22 The purpose of adding a frame header or a frame trailer or both is to ensure the reliability of communication and the convenience of receiving data. It will be very convenient when parsing. Add...
When serial communication is implemented in the project, how should the master and slave devices transmit to each other, such as whether the checksum needs to be transmitted to each other, etc. Can the master briefly explain the transmission process?
This post is from stm32/stm8

Comments

Communication between two devices is like a conversation between two people. First of all, the two people must at least speak the same language, such as Chinese or English. Of course, they cannot understand each other if they speak different languages. In serial communication, the "language and text" used by everyone is bytes, a total of 256 bytes, just like Chinese  Details Published on 2018-7-2 15:14
 
 
 

4005

Posts

0

Resources
7
 
1. Do you define the checksum for the frame header and the frame tail by yourself? Is this considered a protocol? There must be a standard for dividing the bytes of the serial port into data packets. The typical modbus uses time intervals to divide packets. Of course, you can also define it yourself according to your actual situation. The checksum is to improve the data's anti-interference or reliability, and has nothing to do with packet division. 2. I have seen some protocols with a frame header but no frame tail but with a checksum. Can the frame tail be there or not? It is possible to put a special mark and the length of the data to be sent (or specify the length) in the frame header, so that the size of the buffer to be received can be limited at the receiving end, mainly for the case where the length of the data packet is not fixed. 3. Is the frame tail the checksum? Is it enough to have one of the frame tail and the checksum? It still means that packet division and checksum are two different things. If you cannot determine the length of a data packet, there is no way to talk about checksum. 4. Do both the frame header and the frame tail have to be there, or does the frame header have to be there but not the frame tail? I won't say it anymore: lol
This post is from stm32/stm8

Comments

Great God Great God Great God  Details Published on 2018-7-2 18:36
Great God Great God Great God  Details Published on 2018-7-2 18:33
 
 
 

1972

Posts

0

Resources
8
 
Shijizai posted on 2018-7-2 11:01 Serial communication, when implementing functions in the project, how should the master and slave devices communicate with each other, such as whether the checksum needs to be transmitted to each other, etc. Can the master simply...
Communication between two devices is like a conversation between two people. First of all, the two people must at least speak the same language, such as Chinese or English. Of course, they cannot understand each other if they speak different languages. In serial communication, the "language and text" used by everyone is bytes, a total of 256 bytes, just like Chinese characters in Chinese. Then, if you want to talk, you usually say it sentence by sentence to better understand the other party's meaning. It is rare to say it word by word. In the corresponding serial communication protocol, most of them are multiple bytes "forming a sentence" and then sent out. The frame header is like a greeting before speaking: "I'm going to speak, you listen", and then say what you want to say. The frame tail is like a greeting after a sentence is finished: "I'm done", and then the other party will deal with the meaning of your words. The checksum is like a secret code. Both parties define the rules of the secret code in advance, such as the sum of all the strokes of a character must be equal to 100. In this way, after hearing what you said, the other party will calculate the total number of strokes to see if it is correct. If not, it means that either the other party said something wrong, or I heard it wrong and cannot handle it. So using our daily communication process as a model, you can see that you can define the frame header, frame trailer, and checksum yourself. For example, when two people are whispering to each other, you don’t need these things, but if you are asking questions across the table, you may need a frame header or frame trailer to indicate the start or end of speaking. I don’t know if you can understand this explanation.
This post is from stm32/stm8

Comments

What you are talking about is more like a system application layer program. The complexity of the protocol is related to the hardware. For example, when data packets are transmitted over the network, it cannot be assumed that the first data sent arrives first. Frame numbers or timestamps must be added to distinguish them. This is not the case with simple serial ports. There is no need to make it too complicated. What exactly do you want to do?  Details Published on 2018-7-3 08:52
What you are talking about is more like a system application layer program. The complexity of the protocol is related to the hardware. For example, when data packets are transmitted over the network, it cannot be assumed that the first data sent arrives first. Frame numbers or timestamps must be added to distinguish them. This is not the case with simple serial ports. There is no need to make it too complicated. What exactly do you want to do?  Details Published on 2018-7-2 20:50
 
 
 

411

Posts

9

Resources
9
 
huo_hu posted on 2018-7-2 11:22 1. Do you set the header and footer checksum yourself? Is this a protocol? How to divide the bytes of the serial port into data packets is to have a label...
Great God Great God
This post is from stm32/stm8
 
 
 

411

Posts

9

Resources
10
 
huo_hu posted on 2018-7-2 11:22 1. Do you set the header and footer checksum yourself? Is this a protocol? How to divide the bytes of the serial port into data packets is to have a label...
Let me ask another question. If I want to transfer the USART2 of a microcontroller to the USART2 of another microcontroller, how should I write the program at this time? USART_SendData(USART2,'A'); should I use this? But how to distinguish the USART2 of the two microcontrollers? If I write it this way, will it be sent to the USART2 of the original microcontroller? How should I send it at this time?
This post is from stm32/stm8

Comments

This side sends data, and the other side receives data. The two programs don't work together.  Details Published on 2018-7-2 20:53
 
 
 

4005

Posts

0

Resources
11
 
bobde163 posted on 2018-7-2 15:14 Communication between two devices is like a conversation between two people. First of all, the two people must at least speak the same language, such as Chinese or English...
What you are talking about is more like a system application layer program. The complexity of the protocol is related to the hardware. For example, when a data packet is transmitted over the network, it cannot be assumed that the first data sent will arrive first. It must be distinguished by a frame number or timestamp. This will not happen with a simple serial port. There is no need to make it too complicated. What exactly do you want to do? Show it out and let us see.
This post is from stm32/stm8
 
 
 

4005

Posts

0

Resources
12
 
Shijizai posted on 2018-7-2 18:36 I have another question. If I want to transfer data from the USART2 of one microcontroller to the USART2 of another microcontroller, how should the program be used at this time...
This side sends data, and the other side receives data. The two programs don't match.
This post is from stm32/stm8

Comments

What about the program? I write this sentence USART_SendData(USART2,'A'); Can this microcontroller transmit to the other side or this microcontroller transmit to the host computer? Master, if MCU1's USART2 transmits to MCU2's USART3, should I write USART_SendData(USART2,'A'); or this  Details Published on 2018-7-3 08:57
 
 
 

411

Posts

9

Resources
13
 
bobde163 posted on 2018-7-2 15:14 Communication between two devices is like a conversation between two people. First of all, the two people must at least speak the same language, such as Chinese or English...
It is very popular and understandable. Thank you very much.
This post is from stm32/stm8
 
 
 

411

Posts

9

Resources
14
 
huo_hu posted on 2018-7-2 20:53 This side sends data, the other side receives data, the two programs don't match
What about the program? I wrote this sentence USART_SendData(USART2,'A'); Can this microcontroller transmit to the other side or this microcontroller transmit to the host computer? Master, if MCU1's USART2 transmits to MCU2's USART3, should I write USART_SendData(USART2,'A'); or USART_SendData(USART3,'A');?
This post is from stm32/stm8

Comments

mcu1 writes to usart2, I don't care what it uses to receive  Details Published on 2018-7-3 15:18
 
 
 

4005

Posts

0

Resources
15
 
Shijizai posted on 2018-7-3 08:57 What about the program? I wrote this sentence USART_SendData(USART2,'A'); Can this microcontroller transmit to the other side or this microcontroller transmit to the upper side...
MCU1 writes to USART2, what is used to receive it on the other side? I don't care
This post is from stm32/stm8
 
 
 

1w

Posts

142

Resources
16
 
1. Do you define the header and footer checksum yourself? Is this considered a protocol? A1: It is not necessary to define it yourself. Some protocols have mandatory requirements. Only the header, footer and checksum of the frame may not be called a "protocol". The typical 11-bit asynchronous serial port format (1 start bit, 1 end bit, 1 check bit, 8 data bits) cannot be called a protocol. The protocol must have an agreement on content parsing.
This post is from stm32/stm8
 
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 

1w

Posts

142

Resources
17
 
2. I have seen some protocols with a frame header but no frame trailer but with a checksum. Can a frame trailer be present or not? A2: The structure of a data frame can be a preamble + length code + data code + checksum. Obviously, when there is a length code or the length of the data code is always constant, then there is no need for an end code. Note that the original poster has a wrong concept here. There must be a frame trailer. The last byte or even the last data bit is the frame trailer regardless of its nature. Obviously, it is not rigorous to say frame header and frame trailer. It should be said as a preamble and end code.
This post is from stm32/stm8
 
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 

1w

Posts

142

Resources
18
 
3. Is the end of the frame the checksum? Is it enough to have either the end of the frame or the checksum? A3: The end code is a special agreement in the protocol. For a frame structure that does not require an end code, it is obviously not necessary to have an end code. This is still a misunderstanding caused by the wrong concept of the end of the frame and the end code. In addition, the check code is not just the checksum, it can be in many forms, and even most of them are not checksums because the fault tolerance of the checksum is too poor.
This post is from stm32/stm8
 
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 

1w

Posts

142

Resources
19
 
4. Do both the frame header and the frame trailer have to be present or the frame header must be present but the frame trailer is not? A4: The frame header and frame trailer must be present, otherwise there will be nothing, but the leading code and the ending code may not be present. This is still a misunderstanding caused by the wrong concept of the frame header and frame trailer.
This post is from stm32/stm8
 
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 

1w

Posts

142

Resources
20
 
A data frame is a basic unit of data transmission, which refers to the data transmitted at one time. This can be an asynchronous serial port byte or the content of a communication protocol transmission. Obviously, as long as there is data transmission, the frame header and frame tail must exist, and the content has nothing to do with whether it is a protocol. The introduction of communication protocols is to ensure the reliability of data transmission. For this purpose, some measures must be taken, so the protocol must have a structure. The protocol structure is diverse and related to specific applications. Even the protocol itself can be hierarchical, which is actually completely consistent with the nature of communication between people. By analyzing the way people communicate with each other, it is very helpful to understand the communication protocol. It might be helpful to do some "poetry skills" first.
This post is from stm32/stm8
 
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list