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:
parent
d93c15ca5c
commit
b6c7cc4e08
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue