pipeSG,
I'm assuming you are wanting to clear RX buffers and are using Serial.flush() to do it.
The problem is that the Arduino team changed what "flush" does in HardwareSerial
when they went to TX buffering and interrupt driven output in the newer versions of the
Arduino core code.
HardwareSerial no longer purges out the RX buffer data like it still does in the Softserial libraries.
In HardwareSerial flush() now waits to push all the character in the software buffers
out the USART but can return before the last 2 characters fully exit the USART.
The HardwareSerial code does not account for
1 character that can be in the USART FIFO and 1 in the USART transmit buffer,
so IMO, the new flush() is even useless for trying to ensure that all the characters have exited
the USART.
My view is that in the grand scheme of things this issue around the term "flush"
is caused by a big terminology disconnect
as the serial i/o guys from decades ago defined it to mean empty/eliminate but in the newer
C++ stream i/o speak "flush" means to push out the buffered data and force it to be written
to the stream.
Unfortunately because of this change,
there is now no way to toss all the RX buffered characters, using
the current HardwareSerial API, which is what I assume you are needing.
While you could go in and update HardwareSerial to give back the old functionality,
or even play games with a class wrapper that re-defines flush() to make it work like
it used to, my suggestion is to write your own code snippet to flush/purge/empty out the RX buffers when you
need to ensure that you are starting with a clean/empty RX buffer.
While not as efficient as what could be done in the actual library,
it will work on either SoftSerial or HardwareSerial no matter which
version of the IDE you use.
Instead of Serial.flush() do something like:
while(Serial.read() >= 0){}; // flush out RX buffer
--- bill