SlashDevin / NeoSWSerial

Efficient alternative to SoftwareSerial with attachInterrupt for RX chars, simultaneous RX & TX
169 stars 42 forks source link

Support for 31250 baud rate (MIDI). #13

Closed jarosz closed 7 years ago

jarosz commented 7 years ago

I assumed it wouldn't work on 8MHz, so there is fallback to 19200.

I guessed the value of rxWindowWidth - it works for me, but I don't know the formula to calculate it.

SlashDevin commented 7 years ago

Looks good, and looks safe! :) Thanks for the contribution.

jarosz commented 7 years ago

Could you tell me where does rxWindowWidth take its value from?

SlashDevin commented 7 years ago

Hehe... umm it depends on the microgriffage factor of the selected baud rate.

IIRC, it is a fudge factor that has two purposes: it is a fixed-point fractional addition to the bit time(s) that effectively rounds the division result (actually a multiply); and it helps accommodate the interrupt dispatch time that happens for each bit change (0-to-1 or 1-to-0). Rather than go with a "tuned" calculation that may be processor/clock/compiler version depending, I added a SWAG until it worked reliably. :( It may be susceptible to compiler version, but I do not "expect" much change in the dispatch time. (I may have jinxed myself by saying that...)