Proposal to improve SoftwareSerial #1198

Closed
RobTillaart opened this Issue Jan 2, 2013 · 1 comment

Comments

4 participants
@RobTillaart

see also - http://arduino.cc/forum/index.php?topic=138497.0 -

Investigated if the magic numbers in SoftwareSerial to determine the bit timing could not be replaced by formulas.

the colums named - rxintra rxstop - are in every table identical so merging that would save footprint.

It appeared that the timing tables can be replaced by formulas that gives smaller footprint and enables non-standard baud rates over SoftwareSerial. This latter allows to compensate the baud rate a bit if the baud rate of the other devices differs due to clock differences.

-- 16Mhz formulas:
rxstop = 16000000L/(7 * baudrate) - 2;
rxintra = rxstop; // this can be removed too as these are always identical.
tx = rxstop - 4;
rxcenter = rxstop/2 - 5;

-- 8Mhz formulas (not tested)
int rxstop = 8000000L/(7 * baudrate) - 4;
int rxintra = rxstop;
int tx = rxstop - 3;
int rxcenter = max(rxstop/2 - 7, 1);

-- 20Mhz formulas (not tested)
int rxstop = 20000000L/(7 * baudrate) - 1;
int rxintra = rxstop;
int tx = rxstop - 3;
int rxcenter = rxstop/2 - 4;

Only tested the 16Mhz version and the behaviour tested so far is identical to the table driven version.
Furthermore the sketch size - and thus the library footprint - is 182/192 bytes less. (See forum thread).

@ffissore ffissore added the New label Feb 27, 2014

@cmaglie cmaglie removed the New label Feb 27, 2014

@sandeepmistry

This comment has been minimized.

Show comment Hide comment
@sandeepmistry

sandeepmistry Mar 9, 2016

Member

This has been completed by @matthijskooijman in #2032.

Member

sandeepmistry commented Mar 9, 2016

This has been completed by @matthijskooijman in #2032.

universam1 referenced this issue in universam1/openLRSng Sep 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment