Extract the parity bit in serial communication

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

Reply to
fulltime
Loading thread data ...

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.
Reply to
CBFalconer

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

Reply to
Paul Keinanen

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

Reply to
fulltime

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
 Click to see the full signature
Reply to
Tim Wescott

You should have stated this in your original post.

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

Reply to
Paul Keinanen

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?

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

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

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

Reply to
fulltime

how can this parity error flag be accessed? thks..

Reply to
fulltime

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 
 Click to see the full signature
Reply to
CBFalconer

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.