Go Down

Topic: Serial error checking (Read 2718 times) previous topic - next topic


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.  

Here is the thread in "hardware interfacing" where posted this hack

1) This is quite small (one variable, one assignment statement), should I suggest this as a wiring improvement.

2) 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.


I have an old LED scrolling sign I'd like to use with my Arduino but it communicates at 9600/7/E/1.  Would this hack do the trick?


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.

1) check page 192-194 of the AVR168 datasheet for the USART registers.

2) Use serial.begin(9600); to set baud rate and set up interrupt handler/buffering.

3) set word length to 7  
USCR0B = UCSR0B & B11111011;
UCSR0C = UCSR0C | B00000010;
UCSR0C = UCSR0C & B11111110;

4) set parity to even
UCSR0C = UCSR0C | B00100000;
UCSR0C = UCSR0C & B11101111;

5) 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.

Go Up