Skip to content

Serial.flush() have a problem #2502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jyzhkj opened this issue Sep 11, 2016 · 4 comments
Closed

Serial.flush() have a problem #2502

jyzhkj opened this issue Sep 11, 2016 · 4 comments
Assignees
Milestone

Comments

@jyzhkj
Copy link

jyzhkj commented Sep 11, 2016

void loop()
{
digitalWrite(12, 1);
Serial.print("abcdffew");
Serial.flush();
digitalWrite(12, 0);
delay(100); // wait for a second
}

see the 12 pin when down, the last byte is not Send End.

so I try to change the HardwareSerial.cpp to:

void HardwareSerial::flush()
{
if(!_uart || !uart_tx_enabled(_uart)) {
return;
}

uart_wait_tx_empty(_uart);
long tt =uart_get_baudrate(_uart);
tt=12000000/tt;

delayMicroseconds(tt);
}

@plinioseniore
Copy link
Contributor

Hi @jyzhkj from your code looks like you are using an USART to RS485, I've found the same behavior and the last byte is not send as the flush doesn't empty the send queue before moving to the next instruction.

@fishersolutions
Copy link

I have also found the same issue.
Is there a fix other than adding in your own delay?

igrr pushed a commit that referenced this issue Oct 15, 2017
* Add a workaround-delay in Serial.flush()

In relation to #2536 and #2502

Tested at 80MHz and 160MHz with flash-frequency at both 40MHz and 80MHz, the bug mentioned in the above issues manifests in all cases. The proposed workaround seems to work fine, I tested at 2400bps, 9600bps, 115200bps, 230400bps and 2Mbps and didn't see anomalous output.

* Remove extraneous character

* Update HardwareSerial.cpp
d-a-v pushed a commit to d-a-v/Arduino that referenced this issue Oct 15, 2017
* Add a workaround-delay in Serial.flush()

In relation to esp8266#2536 and esp8266#2502

Tested at 80MHz and 160MHz with flash-frequency at both 40MHz and 80MHz, the bug mentioned in the above issues manifests in all cases. The proposed workaround seems to work fine, I tested at 2400bps, 9600bps, 115200bps, 230400bps and 2Mbps and didn't see anomalous output.

* Remove extraneous character

* Update HardwareSerial.cpp
@devyte devyte added this to the 2.5.0 milestone Jul 13, 2018
@d-a-v
Copy link
Collaborator

d-a-v commented Oct 12, 2018

@jyzhkj This 2 years old issue seems to have been solved a year ago by #3714.
Is it OK, can you close it ?

@d-a-v
Copy link
Collaborator

d-a-v commented Oct 12, 2018

Closing due to comment in similar issue #2536 and per #3714 fix.

@d-a-v d-a-v closed this as completed Oct 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants