diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2011-03-06 12:20:42 -0500 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2011-03-06 12:20:42 -0500 |
commit | 0ba1f0ec5040b68d2b09266c461d1a22b64c7e1b (patch) | |
tree | b0f881f7473e9e6b1fcdf1137e10bd1bc830febd | |
parent | 01d82d82770de18628b0fc9f9be1c85c7abc294e (diff) |
Flushing outgoing and incoming data in Serial.end().
That is, waiting for outgoing data to transmit and dropping any received data.
-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 6738675..1154ae7 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -313,16 +313,22 @@ void HardwareSerial::begin(long baud) sbi(*_ucsrb, _rxen); sbi(*_ucsrb, _txen); sbi(*_ucsrb, _rxcie); - cbi(*_ucsrb, _udrie); // XXX: what if there's already data in the tx buffer? + cbi(*_ucsrb, _udrie); } -// XXX: should we empty the rx and tx buffers here? void HardwareSerial::end() { + // wait for transmission of outgoing data + while (_tx_buffer->head != _tx_buffer->tail) + ; + cbi(*_ucsrb, _rxen); cbi(*_ucsrb, _txen); cbi(*_ucsrb, _rxcie); cbi(*_ucsrb, _udrie); + + // clear any received data + _rx_buffer->head = _rx_buffer->tail; } int HardwareSerial::available(void) |