diff options
author | Matthijs Kooijman <matthijs@stdin.nl> | 2015-07-30 17:54:32 +0200 |
---|---|---|
committer | Matthijs Kooijman <matthijs@stdin.nl> | 2015-07-31 14:06:20 +0200 |
commit | 303ebdb0ccbc13dec765f1ce7ca681d73a7e9b90 (patch) | |
tree | 6e299ad815e577436c58612dd28cb19b6f68b88a /cores/arduino/HardwareSerial.cpp | |
parent | 31e0c941240f2b1d0e4f97d6e65d3a1ad66fbae5 (diff) |
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.
Diffstat (limited to 'cores/arduino/HardwareSerial.cpp')
-rw-r--r-- | cores/arduino/HardwareSerial.cpp | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index a2029a8..5cd89e5 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -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); |