3

Is there a way to test whether the UART Tx buffer is empty without waiting?

serial.flush() waits, so it won't help me.

I tried looking into serial.SerialEvent(), but the link was broken on the Arduino reference page.

Can anyone point me to a description of it?

3
  • 1
    If you need such fine control over the UART then you may need to drop to low-level manipulation of the registers. Commented May 19, 2014 at 14:52
  • No, there is no method to do this in the source of the serial driver in the main Arduino repository, but it shouldn't be too hard to add one, which checks either the software-maintained buffer or the hardware register of the UART itself, or both, according to your need. Commented May 19, 2014 at 16:11
  • If you use SoftwareSerial then definitely not. With HardwareSerial that could be possible but you'd have to change the source code yourself. Commented May 19, 2014 at 18:58

1 Answer 1

1

It doesn't look like that function is implemented. The source for HardwareSerial.{cpp,h} are in /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino under OS-X. (Someone better versed in Window than I may have to chime in here to point you to that source location.)

Taking HardwareSerial::available() as a model, create a new function, say, HardwareSerial::txremaining(), that does the same thing, but for the transmit buffer.

Left as an exercise for the student:
Make a common function that returns the contents of an arbitrary ring-buffer and use it in both ::available() and ::txremaining().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.