Log of data loss problem in ESP8266 chip TCP/UDP high-speed real-time transmission

Due to the needs of the project, the ESP8266 chip is used to transmit the vibration sensor signal. Because of its high sampling frequency, it needs a fast transmission speed. Later, the problem of data loss was found, which has been partially solved. The solution is recorded as follows:

The system consists of a MEMS sensor module---STM32F4---ESP8266 module, in which the sensor sampling frequency is set to 4kHz according to the manual parameters, the baud rate of the microcontroller is set to 921600, and the baud rate of the esp8266 is also 921600.

When testing on a standard shaker, the problem of data loss was found, as shown below:

This is the data received when normal, the data is continuous


The data received when the data is lost, you can see the obvious loss of data between the third row and the fourth row

Draw it more clearly


The computer terminal uses the network serial port assistant to receive data.

Reason speculation:

1. The speed of sending data is greater than the speed of receiving data, and the data is lost after the buffer at the receiving end of the computer is full

2. Flow control

3. The phenomenon of sticking and unpacking of TCP protocol

4. The baud rate is too high and it is easy to make mistakes

For 1, there are two buffers, one is the receiving buffer of the wifi module, the other is the receiving buffer of the pc side, the number of bytes sent per second is calculated, the baud rate of 921600 is enough, I wrote another one on the pc side A tcp receiving program, the buffer setting is large enough, it still does not work.

For 2, since the program for configuring the F4MCU is an online code, the flow control is rarely used in the online code, so the flow control pin is re-initialized, the flow control function is turned on, and the data is not lost when it is found.

For 3, I tried the UDP protocol transmission, and found that the data was still lost

For 4, reduce the baud rate to 460800, the phenomenon of data loss is greatly reduced, but still there, the occurrence rate is about 3/10

The above test experiments may be somewhat imprecise, and I hope that colleagues can give more guidance.

Later, I called the after-sales inquiries of the wifi chip, and I accidentally learned that the transmission performance of the WiFi chip has a lot to do with the distance. Before, I was lazy and used the mobile phone hotspot to open the wifi, and the module is in station mode, the signal of the mobile phone hotspot may be weak. I did the experiment again, put the mobile phone at a distance of about 10cm from the chip, and tested it with a baud rate of 460800, and the problem of data loss will never occur again. However, setting the baud rate to 921600 still suffers from occasional data loss.

Therefore, this experiment is summarized as follows, three factors affect the data transmission

1. Flow control is not configured properly

2. Weak wifi signal

3. If the baud rate is set too high, an error will occur

Another question has always existed, about the function of baud rate:

The sampling speed of the sensor chip is obviously set to 4000HZ, the received frequency is about 1000hz when the baud rate is 460800, and the received sampling frequency is about 1666hz when the baud rate is 921600. However, the frequency does not match and no data is lost. Guess the data is stored in the buffer of the microcontroller, the iic is stored, and the serial port is taken out? But it should overflow after long work? However, there is no data loss phenomenon in the test with the wired serial port.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324728225&siteId=291194637