I just hacked wiring_serial.c and wiring.h so I could return the value of the UCSR0A register. I can now receive any number of serial bytes, then check to see if there were any hardware receive errors. This works for testing, but obviously hacking wiring isnt the right way to do this for "production" code.
This is quite small (one variable, one assignment statement), should I suggest this as a wiring improvement.
I would like to create a "test_serial" library that is an exact copy of wiring_serial.c except with my hack. I assume if you only used functions from the test _serial library there would be no conflict with wiring_serial. However -- when I simply rename and recompile wiring_serial.c I get compile errors. Any hints on how to easily clone an existing library.
finally if I can get a "test_serial" library running there are some other troubleshooting functions that could be added like "autobaud", possibly an error rate test, even/odd parity etc. Not stuff that would go in the core, but perhaps useful with old equipment.
The hack as given is just to check for receive errors.
But it shouldnt be hard to set 7/even parity.
(typing this in for the second time arrgh.)
Note: I havent tested this and I can be a bit dyslexic on bit order. Please check the datasheet yourself. You may also want to look at "wiring_serial" to see how the syntax looks.
Use serial.begin(9600); to set baud rate and set up interrupt handler/buffering.
set word length to 7
USCR0B = UCSR0B & B11111011;
UCSR0C = UCSR0C | B00000010;
UCSR0C = UCSR0C & B11111110;
set parity to even
UCSR0C = UCSR0C | B00100000;
UCSR0C = UCSR0C & B11101111;
use the serial.read and serial.print functions as normal.
This works because the USART registers are written to once by serial.begin. Once that is set up you can change most of the parameters yourself. I used this same trick with MS-DOS to set nonstandard baud rates.