So this really isn't a plea for help or anything like that, more of an informational post. I was doing some tinkering with a serial LCD that I came across and had need to make use of another serial port since the hardware port is tied up by the Uno. I was making a crude clock display and noticed that it was losing an unusual amount of time so I dug into it.
Turns out that SoftwareSerial has some "quirks" that aren't documented as well as they should be.
- You can't send and receive at the same time. If you try to overlap send/receiving you WILL lose incoming data.
- It blocks with interrupts disabled for the entire time it is sending or receiving a byte. This is really bad since it takes approx 1mS to send a byte at 9600 baud.
- Due to number 2, functions that depend upon the Arduino's use of Timer0 (millis(), micros() and delay()) will be severely impacted since timer0 overflows will be completely missed and not handled before another occurs.
All is not lost though. There is an alternative serial library that uses interrupts to do things and otherwise plays much more nicely. It's not without it's limits though.
- It hijacks Timer1 to do its thing which precludes using pins 9 and 10 for PWM.
- It forces you to use pins 8 and 9, so it only offers one additional port.
Each has its benefits and downfalls, so both should be evaluated. The later one isn't screwing up my timekeeping at all. The previous was making my "clock" lose nearly an hour per day. Now it's keeping time as I expected.
The library is called AltSoftSerial and is available here: