[En-Nut-Discussion] detecting UART parity errors
Trevor O'Grady
togrady at comtech.uk.com
Wed Dec 17 15:42:53 CET 2003
I'm writing an application that needs to support odd parity checking.
Basically I need to discard bytes that do not have odd parity.
I've set up odd parity checking like so:
//set odd parity on uart0
baud = 1; //parity, 0 (no), 1 (odd) or 2 (even).
UartAvrIOCtl( &devUart0, UART_SETPARITY, &baud );
and I can use the following to read the parity error bit:
//return non zero if parity error else return 0
static u_char parityError()
{
return ( inp(USR) & 0x04 ); //parity error is UCSR0A register bit 2
}
All fine so far.
The problem is that the parity error bit is cleared once the byte is read by
the OS from the UART buffer register.
What I observe is that the parity error bit is NOT set for the first byte I
send that has a parity error but is set for the following bytes with parity
error including the first byte that does not have a parity error. Put
another way, the parity error bit is always one byte behind.
Looks like I'm really reading the parity bit for the previous byte and not
the byte has just been read.
Any ideas what's going on and how I can get round this ?
Is there a way I can stop the NUT OS from reading the UART and just setup my
own UART interrupt which would allow be to read the parity bit before
reading the received byte ?
Tanks in advance
Trevor
More information about the En-Nut-Discussion
mailing list