About the start and end of a frame

Source: Internet
Author: User

Serial communication How to judge a frame of data sent over. Set a time interval. After this time interval there is no data to be able to determine the completion of a frame of data transmission.

It's not safe to get an end character! What if the end character is Thulium? or receive a character error?

Judge the length of the frame data also not ah, because the length of the frame data may not be completely correctly received, in case the loss of 1/2 of data, by judging the number of frame data also not AH!

There's no better way?

Frame data has a fixed period, it is a good way to judge the time interval, but do not know how to do it. For example, 3-5MS has no data, it should be a frame of data sent to complete. But how do you judge the 3-5ms? The last byte of time is remembered in the interrupt.

You can do it if you send and receive it.
Data frames can be like this: start character + data content + Check character + end character
Your data content is ASCII, or 16 binary.


--This useless, lost data, these definitions are not working!!!

I have always been very troubled by this problem, the use of time interval to judge is really a good way, such as a lot of SCM on the receiving port protocol frame has done so. It is estimated that many of the physical layer implementations of the serial protocol may use this method. But sometimes it's a less generic or less well-implemented approach.
If the single software, basically programmed to achieve the current frame error, will not affect the next frame to receive it.
It is certainly not enough to judge the end character, for example, if the end character of a frame is lost, it will definitely affect the next frame's reception.
But at the same time to determine the start character, data length, check, terminator or can be done to receive the error frame, does not affect the next frame receive.
Judging the time interval can enable a timer, when there is data to the reset timer, so if there is data received, the timer will never occur overflow interrupt. If the timer overflows, it means that there is not enough time to receive the data, and a frame is over.
The size of the frame can also be fixed to some extent to solve the problem, but may cause waste.
I don't know if there's any better way.

Whether the data frame is finished, incomplete, or self-defined protocol

As to whether a string of data has been sent out, this is by the UART hardware interface (depending on the UART controller, the hardware interface also has a timeout setting) and interrupt to ensure that

When will serial data be processed? It must be the best time to deal with a frame when it is finished. A frame receive is completed with a certain interval of time that can be used for processing.
How can you tell if a frame is just received? I'm going to set a 5MS and no data to judge as a frame end seems to have a problem.
The principle is that there should be no problem. Am I doing the wrong thing?

If you do not receive a frame to deal with, processing will also affect the received. Since the processing is also processed to receive BUF, the receive is also received to receive buf inside go.
Do you have a better way?

By the end of the receiver to get a problem, because the Terminator may not receive, not to be able to never deal with, garbage data is more and more.
There is also a problem by data length, because there is the possibility of losing data, which may not be able to get fixed length data.

I remember doing something similar to the PPP protocol: PPP is the delimiter used to make frames with 0x7e, and the data between the first and the second is a complete frame, and if the information (data) field appears 0x7e combination, it is filled with special characters. This is done by converting each 0x7e byte that appears in the Information field to a 2-byte sequence (0x7d,0x5e). If the 0x7d byte appears in the Information field, it is converted to 2 bytes (0x7d,0x5d). If you consider data loss, you can set a 2-byte checksum before the Terminator to verify a frame, or limit the length of the frame (such as 1450), which can be considered a missing delimiter if there are more than 1450 cases. If there is only one delimiter, then you have to wait for 2012 to arrive. Add one point: if you want to ensure the correctness and efficiency of the transmission, it may be necessary to draw on a little tcpip principle, to achieve a simple time-out retransmission mechanism, the introduction of the Seq/ack mechanism.

It's too much trouble with the ACK, one to spend time.

Or join the verification mechanism, failure can be based on the settings, whether retransmission.

Using time intervals, this approach is ultimately not expected to be considered.
First of all, it is poor portability, and there is not necessarily a guarantee that, after porting the operating system, the multitasking OS, when performing different priority tasks, you are not necessarily accurate.

Even with timers, it is possible to have higher-priority interrupts in privileged tasks still in process, at which time the timer is useless.


So the most reliable and easy to transplant is to join the calibration mechanism;

Of course, if it is very software, with time interval can also be accepted, after all, too simple program, with what method can be achieved.

I think this is part of the agreement, which can be defined according to external factors,
Generally outside the environment is better, when there is no need for complex protocol, of course, there will be no large possibility of loss of data bits
The data stream of the serial port is not very big, and the transmission distance cannot be too far in the 232 protocol.
There is basically no problem that you say.
For long-distance transmission, 485 chips can be used.

Serial communication is not only refers to the serial communication, serial communication should be more stable

My idea is that you first have to confirm under experimental conditions that your communication is not going to go wrong.
Second, you define the communication protocol to ensure that even if a few frames of data loss, your program, can still run robustly

To process the data to determine the status of the CS line? So we know that serial communication is not in the hair data, CS line for must not do not do data processing (busy), CS line for high data processing (not busy), the effective information is picked out, invalid data is removed, processing to the entire receive buffer a data has not so far ( Increase the fault tolerance of the program, the data errors directly thrown away, and can not affect the next frame of the data reception and processing, do not know whether this is feasible, but also to do experiments to verify it! A time to deal with the possibility of a non-existent situation. I don't know if there's any better way.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.