-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esp32 s3 serial2 read out invalid value when data size is big #7027
Comments
@flybeyond - How are you reading the data? 200 bytes is the size for the UART driver to copy UART FIFO data to the internal Arduino Serial ringbuffer. https://www.arduino.cc/reference/en/language/functions/communication/serial/ |
After checking source code, the issue is caused by setRxBufferSize will not change buffer size dynamically. It just changes a variable and the variable will take effect in construct function. Say, if the code looks like Serial.begin(); Serial.setRxBufferSize(1024); it will not work. And Serial.setRxBufferSize(1024); Serial.begin(); It will work. The behavior is not the same as other arduino devices. It's better to change for consistence. |
maybe related? #6998 |
@SuGlider I tried Serial.readBytes(buffer, length) to read big data, it takes very long time to complete. 699 bytes take about 1.3s. 09:06:21.341 -> data len 699 left len 0 |
@VojtechBartoska they are not the same issue. In this case, the setRxBufferSize will not take effect after begin(). And in my test, set the rx buffer size to 2k. I found some data should not shown in read function, show up. Some data show in previous readout value. Highly suspect there are some memory corruption. I think this is a critical issue. |
Here I found a similar issue. Some one said uart reception of long data has issue for years. Is that true? Any plans to fix it ? |
@flybeyond - I used this code and I can read 1024 bytes on UART 0, by sending data using Arduino Serial Monitor: char uartBuff[1024];
// 128 Chars to send to UART: SerialMonitor also send \n \r depending on the setup...
//0123456789abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ!*$#0123456789abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ!*$@
void setup() {
Serial.setRxBufferSize(1024);
Serial.begin(115200);
Serial.println("\nStart reading up to 1024 bytes...");
size_t alreadyRead = 0;
while (alreadyRead < sizeof(uartBuff)) {
size_t s = 0;
while (Serial.available() && alreadyRead < sizeof(uartBuff)) {
uartBuff[alreadyRead++] = Serial.read();
s++;
}
if (s) {
Serial.printf("So far read %d bytes\n", s);
}
delay(50);
}
// dump data read
Serial.println("UART has read 1024 bytes");
for (int i = 0; i < sizeof(uartBuff); i++) {
if (!(i & 0x3f)) Serial.println();
Serial.print(uartBuff[i]);
}
}
void loop() {
// put your main code here, to run repeatedly:
} Ouput:
|
@flybeyond - Another test with an ESP32 sending data and an ESP32-S3 receiving data. ESP32 sends data using Serial UART 0 port. Sends data no-stop. ESP32 Data Sender Sketch: // Sends 64 bytes block - non stop - no \n \r
char buff[] = "0123456789abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ!*$#0123456789abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ!*$@";
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.write((const uint8_t *) buff, sizeof(buff) - 1);
Serial.flush();
}
ESP32-S3 Data Receiver Sketch: char uartBuff[1024];
void setup() {
Serial2.setRxBufferSize(2048);
Serial2.begin(115200, SERIAL_8N1, 17, 18);
Serial.begin(115200);
Serial.println("\nStart reading up to 1024 bytes...");
delay(100);
Serial2.flush(false); // flush RX & TX
size_t alreadyRead = 0;
while (alreadyRead < sizeof(uartBuff)) {
size_t s = 0;
while (Serial2.available() && alreadyRead < sizeof(uartBuff)) {
uartBuff[alreadyRead++] = Serial2.read();
s++;
}
if (s) {
Serial.printf("So far read %d bytes\n", s);
}
}
// dump data read
Serial.println("UART has read 1024 bytes");
for (int i = 0; i < sizeof(uartBuff); i++) {
if (!(i & 0x3f)) Serial.println();
Serial.print(uartBuff[i]);
}
}
void loop() {
// put your main code here, to run repeatedly:
} ESP3-S3 Output:
|
If we add a Serial.println("\nStart reading up to 1024 bytes...");
delay(100);
Serial2.flush(false); // flush RX & TX
delay(2000); // <<<<<===== Here... we force Serial2 to receive all 1024 at once in the "background" of this delay
size_t alreadyRead = 0;
The output is:
Which means that the Serial 2 Rx buffer has stored at least 1024 bytes at once in the meantime that the sketch was doing something else ( So, everything works fine.... |
@flybeyond Can this be considered as solved? |
Board
ESP32S3 Dev Module
Device Description
plain module
Hardware Configuration
GPIO 17 18 as serial2
Version
v2.0.4
IDE Name
Arduino
Operating System
N/A
Flash frequency
40Hz
PSRAM enabled
no
Upload speed
921600
Description
I use esp32 s3 to read data from a cat1 module. when the module send out big data size say 1000, the read out value will be wrong after 200 bytes to 0xff. Use Serial2.setRxBufferSize(2048) will not resolve the issue.
You can see the debug message, full of 0xff which is not correct.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: