Skip to content
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

Add isFlushed() method to HardwareSerial class for AVR and UARTClass for SAM #3737

Closed
wants to merge 1 commit into from
Closed

Conversation

ghost
Copy link

@ghost ghost commented Aug 27, 2015

Needed a non-blocking way to check if the transmit buffer was flushed/clear. This is a re-request because I stink at Git, original request was #3589. Sorry!

@ghost
Copy link
Author

ghost commented Aug 27, 2015

@PaulStoffregen @matthijskooijman Matt, you were right about the AVR code, should be fixed now. Everything is in one nice commit now as well.

@matthijskooijman
Copy link
Collaborator

I believe the AVR code still has a race condition. Note that flush() checks the UDRIE0 (uart data register empty interrupt enable) bit, not UDRE0.

@ghost
Copy link
Author

ghost commented Aug 27, 2015

At this point I've spent way too much time on this. If someone wants to
jump in and correct the AVR portion then be my guest, otherwise this pull
will die.

On Thu, Aug 27, 2015 at 9:24 AM, Matthijs Kooijman <notifications@github.com

wrote:

I believe the AVR code still has a race condition. Note that flush()
checks the UDRIE0 (uart data register empty interrupt enable) bit, not
UDRE0.


Reply to this email directly or view it on GitHub
#3737 (comment).

@PaulStoffregen
Copy link
Contributor

If you do work on this more, I highly recommend connecting a MAX483 or similar chip. Just a little code after writing data should poll isFlushed() and de-assert the driver enable pin. If you monitor the chip's output, you'll be able to very easily tell if you're truncating the data. Or the same could be accomplished with a logic OR gate, or with a digital oscilloscope and no extra circuits at all.

@PaulStoffregen
Copy link
Contributor

Also, if you want some other code to look at, my HardwareSerial code for Teensy has an extension called transmitterEnable(pin), which causes it to generate the driver enable control signal for those common RS-485 chips. Teensy has provided this feature for years. I have personally used it in projects and so have hundreds of other people, so I can say with very good confidence it has correct timing on controlling that pin on both AVR and ARM chips.

@ghost
Copy link
Author

ghost commented Aug 27, 2015

Have a Due and a SP3485, going to do this within the hour actually. Don't
have an AVR based board to test anything out on. Honestly only care about
the SAM part because that's what I need it for. Someone more familiar with
the AVR side should re-write isFlushed() for that.

On Thu, Aug 27, 2015 at 9:45 AM, Paul Stoffregen notifications@github.com
wrote:

Also, if you want some other code to look at, my HardwareSerial code for
Teensy has an extension called transmitterEnable(pin), which causes it to
generate the driver enable control signal for those common RS-485 chips.
Teensy has provided this feature for years. I have personally used it in
projects and so have hundreds of other people, so I can say with very good
confidence it has correct timing on controlling that pin on both AVR and
ARM chips.


Reply to this email directly or view it on GitHub
#3737 (comment).

@matthijskooijman
Copy link
Collaborator

@thatcadguy, regarding the AVR code, I think (based on the current flush() function, which IIRC I wrote a while ago) replacing the return line in your function with this should be sufficient:

return bit_is_clear(*_ucsrb, UDRIE0) && bit_is_set(*_ucsra, TXC0);

I don't have time right now to actually test this, but perhaps you can put the above line in your PR for anyone else to test?

And thanks for investing some time in the AVR part, even if it doesn't interest you directly! :-)

@ghost
Copy link
Author

ghost commented Aug 28, 2015

@matthijskooijman Updated. I tested the SAM code on the Due today, works fine.

Add isFlushed() to HardwareSerial class for AVR and to UARTClass class
for SAM. This provides a non-blocking way to check if the transmit
buffer is flushed.
@ghost
Copy link
Author

ghost commented Jan 13, 2016

Just rebased this in case anyone merges it soon.

@ghost
Copy link
Author

ghost commented May 17, 2016

@cmaglie Hi, is there something else my branch needs to get merged? I'd like to see this get merged soon.

@Chris--A
Copy link
Contributor

I know its only being picky, but what about simply flushed() as the function name.

@ghost
Copy link
Author

ghost commented Nov 5, 2016

@Chris--A If that's what it takes to get this merged, then sure.

@facchinm facchinm added the Component: HardwareSerial The hardware serial functionality of the core libraries label Jan 24, 2017
@facchinm
Copy link
Member

Partially moved to arduino/ArduinoCore-sam#7

@ghost
Copy link
Author

ghost commented Aug 12, 2017

Closing because this hasn't been acted upon in 2 years.

@budulinek
Copy link

Please reopen and merge this commit. We need isFlushed() method for non-blocking Serial.write() on half duplex communication (such as RS485).

Thanks.

@matthijskooijman
Copy link
Collaborator

This is no longer the right place for this PR. To have it merged, it should be resubmitted to the ArduinoCore-avr repo (if not already done, for ArduinoCore-sam there seems to be arduino/ArduinoCore-sam#7). Also, any discussion about adding this method more generally into the Stream class (which might be appropriate), would need to happen in the ArduinoCore-API repo probably.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: HardwareSerial The hardware serial functionality of the core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants