Learning C with the Freenove WSP32-WROVER starter kit and there's an issue I cannot find an answer to. Using the provided code to input some data with UART, it would seem to have a strange behavior whenever I input string that is larger than 12 characters. Under 12, everything is fine.
/**********************************************************************
Filename : SerialRW
Description : Use UART read and write data between ESP32 and PC.
Auther : www.freenove.com
Modification: 2020/07/11
**********************************************************************/
String inputString = ""; //a String to hold incoming data
bool stringComplete = false; // whether the string is complete
void setup() {
Serial.begin(9600);
Serial.println(String("\nESP32 initialization completed!\n")
+ String("Please input some characters,\n")
+ String("select \"Newline\" below and click send button. \n"));
}
void loop() {
if (Serial.available()) { // judge whether data has been received
char inChar = Serial.read(); // read one character
inputString += inChar;
if (inChar == '\n') {
stringComplete = true;
}
}
if (stringComplete) {
Serial.printf("inputString: %s \n", inputString);
inputString = "";
stringComplete = false;
}
}
The output of any larger than 12 characters string is sometimes a little bit different, but always seems to follow a similar pattern. For any 13 characters long string, I get :
⸮⸮?
The ouput changes if I add characters, for example 20 characters is this :
D⸮⸮?
I assume the unprintable character is a new line.
The baud rate is set at the same value both in the code and in the serial monitor and I get the same results if I change the baud rate.
Any explanation regarding this behaviour and how to avoid it would be most welcomed.