Arduino Mega 2560 pro - serial communication issue

Hello all,
my first post ... after years :slight_smile: ...i solved almost my question in the past but I really cannot solve the issue this time.
Maybe it is an HW related issue and I'm ordering a new board but I try to enter the post because I see just another commenting similar issue.

Here below a very simple sketch.


#define FW_VER 0.0
unsigned long nowTime = millis();
unsigned long cnt = 0;
void setup() 
{

	Serial.begin(115200);
	
	delay(500);
	//sysTime = millis();
	
	Serial.println(F("\r\n*********************************************"));
	Serial.print(F("*     test"));
	Serial.print((String)FW_VER);
	Serial.println(F(" by I.B.       *"));
	Serial.println(F("*********************************************"));

}

void loop() 
{
	char outBuf[100];
	if (Serial.available() > 0)
	{
		String command = Serial.readStringUntil('\n');   
		if(command.length()>3)
		{
			Serial.println(F("Ok!"));
		} 
		else
			Serial.println(F("short!"));	
	}
	
	if((unsigned long)(millis() - nowTime) >=200)
	{
		nowTime = millis();
		cnt++;
		sprintf(outBuf,"Count=%010lu;Time=%010lu;\r\n", cnt, nowTime);
	Serial.print(outBuf);
	}
}

With this sketch randomly i have missing char in the transferred string over the USB

It is completely random without any relation with for example the other print when I type something.
I guess it is a problem of the CH340 but not having yet a second board I cannot judge.

Any comment from you experts?
Thanks in advance!
P.S.: I hope I posted in the right category!

Have you tested it with different baud rates and/or a different terminal window like putty?

yes the related GUI that should use it do not get the proper code meanwhile with ESP do not have any issue.
So if the start-stop-message is not transmitted well, the GUI doesn't react.

Baudrate, i can try but for my system I need 115200.
And here where he has similar, i see baud is different.

https://forum.arduino.cc/t/serial-flush-doesnt-wait-for-the-end-of-the-transmission/144094

To me is really an CH340 issue, maybe the oscillator.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.