-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Add config options to due Serial1, 2, and 3 #1998
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
Conversation
Note, this should address issue #1343 |
Adds ability to set length, parity and stop bit configuration to hardware serial ports using USART module (Serial1, Serial2, and Serial 3) on Due to allow compatibility with avr devices.
Thank you! Very well done. |
No problem. Unfortunately, it is not possible to enable full config for the UART (Serial) due to limitations of the module hardware. Section 35.5 (page 757) of the datasheet states that the UART only supports 8-bit character handling. That said, it does however support different parity settings (even odd, force 0, force 1, no parity) - see section 35.6.2 (page 765). It would be simple to make the UART configurable in this respect but I didn't know if it would cause confusion. If it were to be implemented it would certainly be sensible to mention the limitation over the other ports in the documentation. Similarly, the USART module also supports force 0 and force 1 for parity, along with 1.5 stop bits -neither of which I implemented. However, if it is though by others that it would be worth implementing the extra modes for the USART and the basic config for the UART then I'm happy to submit a further pull request. Although parity modes are now supported, it should be noted that the parity error bit is never checked... maybe that's for a future update. The USARTs can also be made to support 9 bit data length, but that would involve a much more significant patch. |
Oh, I see, I think that implementing all the possible modes is the way to go: in any case is better than now where Serial doesn't support any mode at all. I'm wondering about some possible problems with the actual API:
MARK/SPACE and half-bits modes are so rare that I'll leave them unimplemented for now. |
Ok, I'll look at sorting all available modes for all ports (including mark/space + 1.5 stop) with error checking over the next few days. Support for 9-bit is an interesting challenge, I had previously considered using a ring buffer to do this. but didn't get around to implementing it. Coincidentally, it looks like someone has already pretty much got the job done using the same ring buffer method over a year ago for 1.0.x in the pull request referenced in the link you gave... yet it wasn't merged? |
The 9-bit support in #1221 is too much expensive in terms of resources (at least for 8bit MCUs), so its not likely to be merged, see Paul's comment here: My suggestion is to keep this pull request into the borders of the current Arduino API, to get it merged soon and eventually implement new features in another pull request. Lastly, I know that the challenge to try to implement a new solution straight away may be tempting, but I strongly advice you to discuss any API change proposal in the developers mailing list before starting the actual coding to reduce the risk of getting into the unpleasant situation of rejecting a pull-request or, worse, doing the same work twice. |
The suggested additional config options for Serial1, Serial2 and Serial3 along with basic config for UART has been submitted in #2006 |
Adds ability to set length, parity and stop bit configuration to hardware serial ports using USART module (Serial1, Serial2, and Serial 3) on Due to allow compatibility with avr devices.