ESP32 doesn't see all the data in UART rx buffer

Alexix
Posts: 2
Joined: Wed Nov 27, 2019 7:28 pm

ESP32 doesn't see all the data in UART rx buffer

Postby Alexix » Thu Nov 28, 2019 4:36 pm

I am using ESP32 WROOM to communicate with TI PGA460 chip via asynchronous UART2 (pins 16 17, 115200 8N2). The command transmission from ESP32 works fine, but the problem appears with the response data reception.

PGA460 responds with known number of bytes every time. ESP32 receives them all, but the reading functions (eg. Serial.read(), Serial.available(), ...) see a various number of received bytes in buffer (from 0 to all of the received) (randomly?). For example, PGA460 responds with 10 bytes, all of them are being received by ESP32, but when the reading function is called (serial.read inside while(serial.available) cycle), it recognizes (for example) 7 of them. (sometimes none of them)

It was noticed that if I send someting via Serial monitor (using Arduino IDE (UART connection with PC), the rest of the bytes are being found in the buffer (even if the UART2 connection with PGA460 was preliminary unpluged). What could be a reason of that and the possible solution ? (the same connection with other ESP32 works fine in both ways)
Last edited by Alexix on Mon Dec 02, 2019 11:18 pm, edited 1 time in total.

Alexix
Posts: 2
Joined: Wed Nov 27, 2019 7:28 pm

Re: ESP32 doesn't see all the data in UART rx buffer

Postby Alexix » Mon Dec 02, 2019 11:17 pm

UPD:

Attached the example of received bytes from UART buffer.

All the shown bytes were sent to ESP32 as a single pack of data. --END-- line represents the point, where Serial2.available / Serial2.read think the Rx buffer is now empty. After interracting with Serial port (UART with PC) (for example sending something via serial monitor of Arduino IDE), ESP32 detects the rest of the received bytes.

The tested code is provided below.

Code: Select all

void setup()
{
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N2);
}

void loop()
{
while (Serial2.available()>0)
	{
	Serial.println(Serial2.read(), HEX);
	i=1;
	delay(10);
	}

if (i==1)
	{
	Serial.println("--END--");
	Serial.println(" ");
	i=0;
	}
delay(100);
}
Attachments
sdf.png
sdf.png (16.98 KiB) Viewed 642 times

Who is online

Users browsing this forum: Baidu [Spider] and 17 guests