Skip to content

Commit 9aa902e

Browse files
committed
Fix Hardwareserial sending a byte twice
https://github.com/arduino/Arduino/issues/3745
1 parent fd79bfe commit 9aa902e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

hardware/arduino/avr/cores/arduino/HardwareSerial.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,11 @@ size_t HardwareSerial::write(uint8_t c)
218218
// significantly improve the effective datarate at high (>
219219
// 500kbit/s) bitrates, where interrupt overhead becomes a slowdown.
220220
if (_tx_buffer_head == _tx_buffer_tail && bit_is_set(*_ucsra, UDRE0)) {
221+
uint8_t oldSREG = SREG;
222+
cli();
221223
*_udr = c;
222224
sbi(*_ucsra, TXC0);
225+
SREG = oldSREG;
223226
return 1;
224227
}
225228
tx_buffer_index_t i = (_tx_buffer_head + 1) % SERIAL_TX_BUFFER_SIZE;
@@ -240,9 +243,12 @@ size_t HardwareSerial::write(uint8_t c)
240243
}
241244

242245
_tx_buffer[_tx_buffer_head] = c;
246+
uint8_t oldSREG = SREG;
247+
cli();
243248
_tx_buffer_head = i;
244249

245250
sbi(*_ucsrb, UDRIE0);
251+
SREG = oldSREG;
246252

247253
return 1;
248254
}

0 commit comments

Comments
 (0)