Suggestion to improve Serial library

Hello,

Arduino's Serial (Serial - Arduino Reference) library is very good!
It is easy to use and satisfies most needs.

However, sometime we need more.
In my application half-dublex communication application, I need to change the direction of a transmit/receive multiplexer when transmission finishes. Timing is critical! Thus I need to know when Serial.write or Serial.print finish its job.

I think it would be very usefull if following behaviour/functionality can be added to the Serial library;

  • A generic way of testing if Serial finishes its send function
  • A function such as "WaitUntilTransmitEnds()"

Thx

?A generic way of testing if Serial finishes its send function

A "Serial.print" or "write" returns as soon as the last byte has been written to the Tx register.
Sure, the line won't be "free" until the Tx register is empty again, but such a function is easy to write.

A "Serial.print" or "write" returns as soon as the last byte has been written to the Tx register.

The need is to know when the last byte has left the processor so a piece of hardware can be switched to a receive mode.

Sure, the line won't be "free" until the Tx register is empty again, but such a function is easy to write.

It is easy to write but the question has come up several times. I think it's time to move the code into the core.

Ideally, the core would call a function when transmit completes so the user wouldn't have to use a busy-wait.

Dear AWOL,

A "Serial.print" or "write" returns as soon as the last byte has been written to the Tx register.
Sure, the line won't be "free" until the Tx register is empty again, but such a function is easy to write.

It may be "easy" for you. But, it is not so trival for other novice people like me.
Can you please share your solution with us so that we can learn from you?
How to make a generic solution (i.e. a solution applicable to Serial, Serial1, Serial2, Serial3) if the last bit has left the processor?
Thank you for help and sharing your experience with us.

It's harder than you might think. Previous discussion: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1270241636

Easy solution: use a delay(n) after serial.print() completes.