All Forums
 Microsoft Windows CE
 CE Drivers
 Forcing a specific parity level (serial ports)
 Forum Locked  Topic Locked
 Send Topic to a Friend
 Printer Friendly
Author Topic  

akidder

1519 Posts

Posted - 08 Aug 2002 :  12:42:55  Show Profile  Email Poster
Q: The device I'm communicating with requires me to control the parity bit in a non-standard fashion. How can I do this?

The Windows CE DCB data structure includes the Parity field for setting automatic or manual control of the parity bit. You can force the parity bit to the MARK ("1" or -12V) or SPACE ("0" or +12V) state by changing this field, then calling SetCommState().

However, while the StrongARM UARTs implement most of the functionality of the 16550 UARTs, they do not support forcing the parity to a Mark or Space state. If you try to set the Parity field to one of these states, you will get error 87 (ERROR_INVALID_PARAMETER). The XScale UART does not have this limitation; see below for details.

If you need to set the parity bit to a specific value, you can use an ADS product that has a separate UART, like the Graphics Master, or you can set the UART's parity type to generate the parity bit you want. The rest of this post describes the latter solution.

What is Parity?

The parity bit is a simple means of error checking. The idea is this: you specify ahead of time whether the parity of the transmission is to be even or odd. Suppose the parity is chosen to be odd. The transmitter will then set the parity bit in such a way as to make an odd number of 1's among the data bits and the parity bit. If there are five 1's among the data bits, already an odd number, the parity bit will be set to 0.(*)

Setting the Parity Bit to a Specific Level

You can set a specific parity level by first adding up the number of bits that are set to "1", then setting the UART's parity type to generate the targeted parity bit. The following pseudocode illustrates how to do this:
  desired_parity_bit = 0 or 1
bits_set_to_one = number of bits in data byte that are set to "1"
;
if ( (bits_set_to_one & 0x01) == desired_parity_bit) )
dcb.Parity = EVENPARITY;
else
dcb.Parity = ODDPARITY;
;
SetCommState (hSerialPort, dcb);

For related information, please see the serial communications topic index.

----------------------
Drew Kidder
ADS Technology Transfer

(*) Thanks to http://www.mindspring.com/~jc1/serial/Basics/BitFormat.html (now only remembered by the google cache) for this concise explanation of parity.

Edited by akidder 10-May-2006: Update example, correcting dcb.fParity to dcb.Parity.

akidder

1519 Posts

Posted - 08 Sep 2003 :  11:04:10  Show Profile  Email Poster
#XScale_parity

XScale Supports Fixed Parity Levels

The XScale processor adds support for setting the parity bit directly. Use the CE constants SPACEPARITY and MARKPARITY to set the DCB.Parity field for the XScale serial port of interest. See the ForceParity sample application for an example.
Go to Top of Page
  Topic  
 Forum Locked  Topic Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
Eurotech Support Forums © Eurotech Inc. Go To Top Of Page
This page was generated in 0.02 seconds. Snitz Forums 2000