Skip to content

Due Serial.flush() missing last byte #4128

Closed
@PhiJu5

Description

@PhiJu5

http://forum.arduino.cc/index.php?topic=153928.0

To show the problem, add to
\sam\1.6.6\cores\arduino\HardwareSerial.h
public:
void disableTXRX() {};
same in
\sam\1.6.6\cores\arduino\UARTClass.h
In
\sam\1.6.6\cores\arduino\UARTClass.cpp
Add
void UARTClass::disableTXRX(void) {
_pUart->UART_CR = UART_CR_RSTRX | UART_CR_RXDIS | UART_CR_RSTTX | UART_CR_TXDIS;
}

Create a test sketch using Serial2&3, Serial 2 sends to Serial3, 9600 baud,
write 100 bytes in a loop using Serial2
than immediately call
Serial2.flush();
Serial2.disableTXRX();

There will be a byte missing on Serial3 RX.
If you add a delay(5) just after flush(),
no missing byte.

The fix is in \sam\1.6.6\cores\arduino\UARTClass.cpp
in void UARTClass::flush( void )
Replace as proposed by 'pylon'
while ((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY);
by
while ((_pUart->UART_SR & UART_SR_TXEMPTY) != UART_SR_TXEMPTY);

and no need to add a delay after flush() to have no missing byte.

Metadata

Metadata

Assignees

Labels

Board: Arduino DueApplies only to the DueComponent: HardwareSerialThe hardware serial functionality of the core librariesfeature requestA request to make an enhancement (not a bug fix)

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions