Skip to content

Use an unsigned long for the baudrate and use Arduino core methods #2

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

Merged
merged 1 commit into from
Feb 22, 2016

Conversation

romainreignier
Copy link
Contributor

I found the bug that prevents us to use baudrates higher than 19200 (37767 actually). A int was used instead of a unsigned long in the begin() method :)

And I have add some improvements mentioned in the issue #1.

For the value of the timeout, I have used the one found in that library.
Note that I now use micros() instead of millis() to have a more precise timing. But micros() will rollover after only 70 minutes. To avoid that, we can still use millis() that will rollover after approximately 50 days, or a more robust approach would be to use a custom superMicros() using a 64 bits variable like illustrated here (sorry, it is in French).

I have removed the Serial.flush(). If they were needed to clear the RX buffer, we should use the following instead:

while(Serial.read() >= 0);

I have replaced the custom serialRead() method by the Arduino's Serial.readBytes() with a timeout of 0.

Finally, I have replaced the polling of the UCSR0A register by the use of the Arduino's Serial.flush() method, so the library should work with other Arduino architectures like the Arduino DUE and Zero (the build is OK for the Due, I will try to upload it to the DUE tonight).

I manage to have a working communication at 115200 bauds while using qmodbus on a PC and an Arduino UNO.

yaacov added a commit that referenced this pull request Feb 22, 2016
Thanks, 
I didn't notice the int thing 👍
@yaacov yaacov merged commit f3a9bdc into yaacov:master Feb 22, 2016
@yaacov yaacov mentioned this pull request Feb 22, 2016
@romainreignier romainreignier deleted the improved_datarate branch February 22, 2016 15:44
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

Successfully merging this pull request may close these issues.

2 participants