EmbeddedRelated.com
Forums

Extract the parity bit in serial communication

Started by fulltime September 3, 2007
Hi all,

In serial communication, eg. RS232 or RS422, we can configure the
port
(for example) to send 8 data bits, Even parity bit and 1 stop bit.
However, when the receiver receives, it only reads in the code and
output to the screen. How can I capture the parity bit that is sent?


Thank you for your advice.
FT

fulltime wrote:
> > In serial communication, eg. RS232 or RS422, we can configure the > port (for example) to send 8 data bits, Even parity bit and 1 stop > bit. However, when the receiver receives, it only reads in the code > and output to the screen. How can I capture the parity bit that is > sent?
If the transmitted parity bit (calculated at the transmitter, before transmission) doesn't agree with the received parity (calculated at the receiver, on the received bits) the parity error flag is raised. -- Chuck F (cbfalconer at maineline dot net) Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net> -- Posted via a free Usenet account from http://www.teranews.com
On Sun, 02 Sep 2007 23:54:57 -0700, fulltime <PiaoChieh@gmail.com>
wrote:

>Hi all, > >In serial communication, eg. RS232 or RS422, we can configure the >port >(for example) to send 8 data bits, Even parity bit and 1 stop bit. >However, when the receiver receives, it only reads in the code and >output to the screen. How can I capture the parity bit that is sent?
Recalculate the parity bit from the received data bits. If the ParityError (PE) in the status register is set, invert the calculated parity bit. Why do you want to know the parity bit in the first place :-). Paul
On Sep 3, 3:08 pm, Paul Keinanen <keina...@sci.fi> wrote:
> On Sun, 02 Sep 2007 23:54:57 -0700, fulltime <PiaoCh...@gmail.com> > wrote: > > >Hi all, > > >In serial communication, eg. RS232 or RS422, we can configure the > >port > >(for example) to send 8 data bits, Even parity bit and 1 stop bit. > >However, when the receiver receives, it only reads in the code and > >output to the screen. How can I capture the parity bit that is sent? > > Recalculate the parity bit from the received data bits. If the > ParityError (PE) in the status register is set, invert the calculated > parity bit. > > Why do you want to know the parity bit in the first place :-). > > Paul
Thanks for your reply, Paul. Actually I need to use a 9 bit protocol to send data from my pc to the device. However, I thought of using 8 data bits and either mark/space parity. This parity bit is set or cleared based on the addressing required by the device. However, before I would like to test my codes before connecting to the device, hence I need to perform some loop back communication, i.e to send via one port and to recv via another port on my PC. hence, i need to figure out the parity bit being received. In this case of mark/even parity bit, i cant possibly use the parityError(PE) register, can I? any other ways to check the parity bit tat was sent out with the message byte? Thanks again FT
On Mon, 03 Sep 2007 00:24:18 -0700, fulltime wrote:

> On Sep 3, 3:08 pm, Paul Keinanen <keina...@sci.fi> wrote: >> On Sun, 02 Sep 2007 23:54:57 -0700, fulltime <PiaoCh...@gmail.com> >> wrote: >> >> >Hi all, >> >> >In serial communication, eg. RS232 or RS422, we can configure the >> >port >> >(for example) to send 8 data bits, Even parity bit and 1 stop bit. >> >However, when the receiver receives, it only reads in the code and >> >output to the screen. How can I capture the parity bit that is sent? >> >> Recalculate the parity bit from the received data bits. If the >> ParityError (PE) in the status register is set, invert the calculated >> parity bit. >> >> Why do you want to know the parity bit in the first place :-). >> >> Paul > > Thanks for your reply, Paul. > > Actually I need to use a 9 bit protocol to send data from my pc to the > device. However, I thought of using 8 data bits and either mark/space > parity. This parity bit is set or cleared based on the addressing > required by the device. However, before I would like to test my codes > before connecting to the device, hence I need to perform some loop > back communication, i.e to send via one port and to recv via another > port on my PC. hence, i need to figure out the parity bit being > received. > > In this case of mark/even parity bit, i cant possibly use the > parityError(PE) register, can I? any other ways to check the parity > bit tat was sent out with the message byte? >
He just told you that. Re-read his post, and think about the answer. I've had the pleasure of sitting next to someone who has gotten 9-bit signaling to work on a PC -- it was a pleasure because _he_ did all the tearing-your-hair-out part, and _I_ got to use the application! At any rate, it used the above method, and it's quite dependable with the 16450/16550 UARTs that you find in PC's. -- Tim Wescott Control systems and communications consulting http://www.wescottdesign.com Need to learn how to apply control theory in your embedded system? "Applied Control Theory for Embedded Systems" by Tim Wescott Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
On Mon, 03 Sep 2007 00:24:18 -0700, fulltime <PiaoChieh@gmail.com>
wrote:

>On Sep 3, 3:08 pm, Paul Keinanen <keina...@sci.fi> wrote: >> On Sun, 02 Sep 2007 23:54:57 -0700, fulltime <PiaoCh...@gmail.com> >> wrote: >> >> >Hi all, >> >> >In serial communication, eg. RS232 or RS422, we can configure the >> >port >> >(for example) to send 8 data bits, Even parity bit and 1 stop bit. >> >However, when the receiver receives, it only reads in the code and >> >output to the screen. How can I capture the parity bit that is sent? >> >> Recalculate the parity bit from the received data bits. If the >> ParityError (PE) in the status register is set, invert the calculated >> parity bit. >> >> Why do you want to know the parity bit in the first place :-). >> >> Paul > >Thanks for your reply, Paul. > >Actually I need to use a 9 bit protocol to send data from my pc to the >device.
You should have stated this in your original post.
>However, I thought of using 8 data bits and either mark/space >parity. This parity bit is set or cleared based on the addressing >required by the device. However, before I would like to test my codes >before connecting to the device, hence I need to perform some loop >back communication, i.e to send via one port and to recv via another >port on my PC. hence, i need to figure out the parity bit being >received. > >In this case of mark/even parity bit, i cant possibly use the >parityError(PE) register, can I?
Why not ? Of course you have to disable any Tx or Rx FIFOs on the *450+ family and also note that you really have to poll for the transmit shift register empty bit (i.e that the stop bit of the character has actually been sent), before changing the parity setting of the Tx register and loading the next character. On the stupid *450+ series UARTs you don't get an interrupt when the last stop bit is sent, only when the last _character_ is loaded into the transmit shift register. Those "standard" UARTs are more or less useless for high speed RS-485 or 9 bit communication due to this design flaw. It should also be noted that NT/Win200/XP/Vista do some virtualisation with the device access, so MS-DOS and possibly Win-9x might be more suitable, if you quickly want to manipulate the UART registers, without writing a device driver. Paul
Hi Paul,

Thank you so much for your reply.

1. In the your reply, you mentioned abt "disabling the Tx or Rx
FIFOs". But why is there a need to disable it?
Mark/Space parity can be set when configuring the com port right? So
all messages sent will have its parity bit set (assuming mark parity
is used) till I close the port and re-configure the port to use a new
parity setting?

2. When you say "change the parity setting of the Tx register, before
loading the next character", do u mean re-configuring the com port?

3. Are there any restrictions on the receiver side? The receiver can
simply read the parity bit to determine if its '0' or '1' once it has
received the 8th bit of data ?

4. I am pretty new to this serial comm. Wondering if you have any URL
or reference I can refer to in order to understand which registers
(e.g. transmit shift register, status register) are present for me to
use?

Thank you once again.
FT


On Sep 3, 3:03 pm, CBFalconer <cbfalco...@yahoo.com> wrote:
> fulltime wrote: > > > In serial communication, eg. RS232 or RS422, we can configure the > > port (for example) to send 8 data bits, Even parity bit and 1 stop > > bit. However, when the receiver receives, it only reads in the code > > and output to the screen. How can I capture the parity bit that is > > sent? > > If the transmitted parity bit (calculated at the transmitter, > before transmission) doesn't agree with the received parity > (calculated at the receiver, on the received bits) the parity error > flag is raised. > > -- > Chuck F (cbfalconer at maineline dot net) > Available for consulting/temporary embedded and systems. > <http://cbfalconer.home.att.net> > > -- > Posted via a free Usenet account fromhttp://www.teranews.com
how can this parity error flag be accessed? thks..
fulltime wrote:
> CBFalconer <cbfalco...@yahoo.com> wrote: >> fulltime wrote: >> >>> In serial communication, eg. RS232 or RS422, we can configure >>> the port (for example) to send 8 data bits, Even parity bit and >>> 1 stop bit. However, when the receiver receives, it only reads >>> in the code and output to the screen. How can I capture the >>> parity bit that is sent? >> >> If the transmitted parity bit (calculated at the transmitter, >> before transmission) doesn't agree with the received parity >> (calculated at the receiver, on the received bits) the parity >> error flag is raised. > > how can this parity error flag be accessed? thks..
Depends on the UART in use. Most will raise a bit in the status word. Some will launch an interrupt. Read the data sheets. -- "To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt -- Posted via a free Usenet account from http://www.teranews.com