From 303ebdb0ccbc13dec765f1ce7ca681d73a7e9b90 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 30 Jul 2015 17:54:32 +0200 Subject: 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. --- cores/arduino/HardwareSerial.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'cores') 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); -- cgit v1.2.3-18-g5258