Yes that can be done. The normal way is to execute read() repeatedly and discard the contents, until it is empty, but if you look into hardwareSerial.cpp, you will find that
But all of these issues are caused by either the program being in an interrupt for too long, (at 115200bps that would be more than 85uS or so) and not responding to the UART's RX interrupt on time, or because you don't read the buffer before it is full. At 115200, eh let's do the math. 8N1 = 10 bits (1 start, 8 data, 1 stop) so 11520 Bps = approx 11.520 Bytes / ms, which comes down to 87us per byte * however big the buffer is.
You just have to keep in mind that if you use external libraries, they may do things that conflict with your priorities.
Thanks again, unfortunately it's quite late in my time zone, so I'll be back tomorrow. But I had a very interesting question, will an external interrupt on Serial fix my problem? if so, how can this be implemented.
Just to tell you that the use of dynamic variables is discouraged on a small MCU to prevent heap fragmentation.
Actually it looks like the RX interrupt is not always executed on time.
Eh yeah, but it does that polling at a regular interval and not by calling a function from the main loop. So i suspect it is using a timer interrupt to call a function. When that function is called by a timer, it is an ISR, which disables all other interrupts while it is within that.
So, just to verify. If you do a simple Serial Passthrough (no other code anywhere !) do you lose bytes ?
If so then the issue is in code you have included
Well i always simply look at the code. Either on Github or i open the .h & .cpp files using notepad++, so i can see what resources are used and how the library is structured. Usually things are not to complex, though sometimes i am left scratching my head as well. Rarely does it not provide me with answers.