Go to file
Matthijs Kooijman 0a6072dccb Fix SoftwareSerial timings
Instead of using a lookup table with (wrong) timings, this calculates
the timings in SoftwareSerial::begin. This is probably a bit slower, but
since it typically happens once, this shouldn't be a problem.
Additionally, since the lookup tables can be removed, this is also a lot
smaller, as well as supporting arbitrary CPU speeds and baudrates,
instead of the limited set that was defined before.

Furthermore, this switches to use the _delay_loop_2 function from
avr-libc instead of a handcoded delay function. The avr-libc function
only takes two instructions, as opposed to four instructions for the old
one. The compiler also inlines the avr-libc function, which makes the
timings more reliable.

The calculated timings directly rely on the instructions generated by
the compiler, since a significant amount of time is spent processing
(compared to the delays, especially at higher speeds). This means that
if the code is changed, or a different compiler is used, the
calculations might need changing (though a few cycles more or less
shouldn't cause immediate breakage).

The timings in the code have been calculated from the assembly generated
by gcc 4.8.2 and gcc 4.3.2.

The RX baudrates supported by SoftwareSerial are still not unlimited. At
16Mhz, using gcc 4.8.2, everything up to 115200 works. At 8Mhz, it works
up to 57600. Using gcc 4.3.2, it also works up to 57600 at 16Mhz and up
to 38400 at 8Mhz. Note that at these highest speeds, communication
works, but is still quite sensitive to other interrupts (like the
millis() interrupts) when bytes are sent back-to-back, so there still
are corrupted bytes in RX.

TX works up to 115200 for all combinations of compiler and clock rates.

This fixes #2019
2015-01-26 17:03:25 +01:00
bootloaders merge 2013-10-14 12:42:42 +02:00
cores/arduino Temporary fix for pulseIn() regression. 2015-01-18 17:34:40 +01:00
firmwares Merge branch 'master' into ide-1.5.x 2014-09-16 12:19:39 +02:00
libraries Fix SoftwareSerial timings 2015-01-26 17:03:25 +01:00
variants Merge branch 'master' into ide-1.5.x 2014-02-12 17:17:33 +01:00
boards.txt set correct max size for mega2560 2014-09-20 03:09:54 +05:30
platform.txt Upped version to 1.6.0 2014-11-18 14:48:01 +01:00
programmers.txt added support for the ArduinoISP 2014-07-02 15:03:12 +02:00