1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-30 19:52:13 +01:00

Prevent losing bytes in HardwareSerial::end()

end() already waited for the buffer to be empty, but then there could
still be two bytes in the hardware registers that still need to be
transmitted (which were dropped or kept in the buffer, depending on the
exact timing).

This changes the wait loop to a call to the flush() function, which
already takes care of really waiting for all bytes to be transmitted,
meaning it is safe to turn off the transmitter.
This commit is contained in:
Matthijs Kooijman 2015-07-30 17:54:32 +02:00
parent b58f239400
commit 9b7b23f045

View File

@ -138,8 +138,7 @@ void HardwareSerial::begin(unsigned long baud, byte config)
void HardwareSerial::end()
{
// wait for transmission of outgoing data
while (_tx_buffer_head != _tx_buffer_tail)
;
flush();
cbi(*_ucsrb, RXEN0);
cbi(*_ucsrb, TXEN0);