Use an unsigned long for the baudrate and use Arduino core methods #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found the bug that prevents us to use baudrates higher than 19200 (37767 actually). A
int
was used instead of aunsigned long
in thebegin()
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 ofmillis()
to have a more precise timing. Butmicros()
will rollover after only 70 minutes. To avoid that, we can still usemillis()
that will rollover after approximately 50 days, or a more robust approach would be to use a customsuperMicros()
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:I have replaced the custom
serialRead()
method by the Arduino'sSerial.readBytes()
with a timeout of0
.Finally, I have replaced the polling of the
UCSR0A
register by the use of the Arduino'sSerial.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.