diff options
Diffstat (limited to 'cores/arduino/HardwareSerial.cpp')
-rw-r--r-- | cores/arduino/HardwareSerial.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index 1ae90c3..e512421 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -350,6 +350,8 @@ try_again: *_ubrrh = baud_setting >> 8; *_ubrrl = baud_setting; + transmitting = false; + sbi(*_ucsrb, _rxen); sbi(*_ucsrb, _txen); sbi(*_ucsrb, _rxcie); @@ -446,8 +448,9 @@ int HardwareSerial::read(void) void HardwareSerial::flush() { - while (_tx_buffer->head != _tx_buffer->tail) - ; + // UDR is kept full while the buffer is not empty, so TXC triggers when EMPTY && SENT + while (transmitting && ! (*_ucsra & _BV(TXC0))); + transmitting = false; } size_t HardwareSerial::write(uint8_t c) @@ -464,6 +467,9 @@ size_t HardwareSerial::write(uint8_t c) _tx_buffer->head = i; sbi(*_ucsrb, _udrie); + // clear the TXC bit -- "can be cleared by writing a one to its bit location" + transmitting = true; + sbi(*_ucsra, TXC0); return 1; } |