Pages: [1]   Go Down
Author Topic: Serial error checking  (Read 903 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
he's not a real doctor
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1232301240

Questions:
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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
he's not a real doctor
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
http://www.atmel.com/dyn/resources/prod_documents/doc2545.pdf

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.
Logged

Pages: [1]   Go Up
Jump to: