Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

9 bit communication on RS 232

7 views
Skip to first unread message

suchitra

unread,
Nov 18, 2003, 7:07:48 AM11/18/03
to
Hello All
I wanted to know how can we configure com port for 9 bit
communication.
I intend to use the 9th bit as Address/data bit..since i want to
communicate with more than one devices.
I am using turbo c compailer if some one can give me some reference
code that will be great..
with kind Regards
Suchitra

moocowmoo

unread,
Nov 18, 2003, 7:34:07 AM11/18/03
to
"suchitra" <ssb...@rediffmail.com> wrote in message
news:110cc2fe.03111...@posting.google.com...

I'm pretty sure that the acceptable values for serial data bit count are
5,6,7 or 8. You might be able to fake the extra bit by sending character by
character switching between odd and even parity as required but it's not
going to be very quick.

The real solution is to send the extra bit in an extra byte.

Peter


Tilmann Reh

unread,
Nov 18, 2003, 7:43:21 AM11/18/03
to
suchitra schrieb:

> I wanted to know how can we configure com port for 9 bit
> communication.
> I intend to use the 9th bit as Address/data bit..since i want to
> communicate with more than one devices.
> I am using turbo c compailer if some one can give me some reference
> code that will be great..

While most, if not all, embedded controllers have this ability
with their UARTs, I fear that the standard PC COM port has not...

Perhaps setting parity to "mark" for address and to "space" for
data could work, as Peter already mentioned. Eventually you will
need pauses between bytes to ensure you don't change the parity
settings while sending is in progress.
You might also consider using 8 bits with the MSB as a/d bit,
reducing the information content to 7 bits per byte.

--
Dipl.-Ing. Tilmann Reh
Autometer GmbH Siegen - Elektronik nach Maß.
http://www.autometer.de

==================================================================
In a world without walls and fences, who needs Windows and Gates ?
(Sun Microsystems)

Michael Hofmann

unread,
Nov 18, 2003, 8:46:49 AM11/18/03
to
suchitra wrote:
> Hello All
> I wanted to know how can we configure com port for 9 bit
> communication.
> I intend to use the 9th bit as Address/data bit..since i want to
> communicate with more than one devices.

though not proficient with the protocol, I could imagine you might be
able to abuse a second stop bit for your purpose.

HTH,
Michael

Mark A. Odell

unread,
Nov 18, 2003, 8:51:38 AM11/18/03
to
"moocowmoo" <mel...@hotmail.com> wrote in
news:bpd3k8$6t3$1$830f...@news.demon.co.uk:

>> I wanted to know how can we configure com port for 9 bit
>> communication.

You can't.

>> I intend to use the 9th bit as Address/data bit..since i want to
>> communicate with more than one devices.
>

> I'm pretty sure that the acceptable values for serial data bit count are
> 5,6,7 or 8.

True but the 8051's have a 9-bit mode where the extra bit means "this is
an address byte, wake up and see if it's for you".

> You might be able to fake the extra bit by sending character by
> character switching between odd and even parity as required but it's not
> going to be very quick.

That's how most do it with a PC or normal UART.



> The real solution is to send the extra bit in an extra byte.

I agree, dump the odd 9-bit mode and use a protocol that does not depend
on hardware specific features.

--
- Mark ->
--

Tauno Voipio

unread,
Nov 18, 2003, 9:25:39 AM11/18/03
to

"Tilmann Reh" <tilma...@autometer.de> wrote in message
news:3FBA13E9...@autometer.de...

> suchitra schrieb:
>
> > I wanted to know how can we configure com port for 9 bit
> > communication.
> > I intend to use the 9th bit as Address/data bit..since i want to
> > communicate with more than one devices.
> > I am using turbo c compailer if some one can give me some reference
> > code that will be great..
>
> While most, if not all, embedded controllers have this ability
> with their UARTs, I fear that the standard PC COM port has not...
>

There is the 9th bit on 8250-style chips, although the standard COM port
drivers do not understand to use it. It's the 'stick parity' bit which can
be used with 8-bit data length.

If you are not forced to use the ninth bit, you may be better off by
encapsulating the data in PPP-like frames, which are binary-transparent with
plain old 8-bit data transfer channel.

For details, get RFC 1662.

HTH

Tauno Voipio
tauno voipio @ iki fi


Gerhard v d Berg

unread,
Nov 18, 2003, 10:35:47 AM11/18/03
to
"suchitra" <ssb...@rediffmail.com> wrote in message
news:110cc2fe.03111...@posting.google.com...

Electronic Design Magazine, Ideas for Design, December 1, 1998
Use the PC's UART with 9-bit Protocols,
Alejandreo J. Formicelli
Article seems to have disappeared from the WEB
It requires the UART to be configured for 8-bit character plus parity.
It checks the parity of the 8-bit character (address) and then
sets the UART for odd or even parity to ensure parity will be a
'one' before transmitting the 8-bit character (address) parity.

Below is the listing included with the article

// Use The PC's UART
// With 9-Bit Protocols
// Author: Alejandro J. Formichelli
//
SendFrame( char bfr[], int bfrLen )
{
SetParity( bfr[0], ADDR ); // first byte of buffer is slave address
SendByte( bfr[0] );
for( i = 1; i < bfrLen; i++ )
{
SetParity( bfr[i], DATA );
SendByte( bfr[i] );
}
}

SetParity( char byte, int byteType )
{
if( byteType == ADDR ) // get the new register value
regVal = addrTbl[byte]; // depending on the byte type
else
regVal = dataTbl[byte];

while( inTx ) // waits end of transmission of last byte,
; // before reconfiguring the UART
WriteParityReg( regVal ); // reprogram the parity register
}

Have Fun!

Gerhard van den Berg


Android Cat

unread,
Nov 18, 2003, 10:25:17 AM11/18/03
to
suchitra wrote:
> Hello All
> I wanted to know how can we configure com port for 9 bit
> communication.
> I intend to use the 9th bit as Address/data bit..since i want to
> communicate with more than one devices.

Using a 9th bit is a kludge that should be avoided if at all possible. It
ties you directly to whatever serial chip you are using (if it supports
it) and will probably be brittle code that will break easily. And you
might run into problems if you route the data over anything other than an
actual wire.

There are plenty of other ways to put an address field in packet headers.
(And you don't need a whole PPP suite for a simple protocol.)

--
Ron Sharp.


Andrew

unread,
Nov 18, 2003, 12:17:20 PM11/18/03
to

It is perfectly possible but difficult to produce 9-bit data on a standard
PC UART. However, as noted by other posters 9-bit mode is almost a standard
for microcontrollers, using the 9th bit as an address flag.

Several posters have noted the possibility of forcing a 1 or 0 in the parity
bit which is the only way of achieving what you want. In DOS it is
moderately easy to achieve this. In Windows almost impossible.

However, there are ready written libraries and device drivers available eg.
Comm-Drv from http://www.wcscnet.com/Software.htm


Syd Rumpo

unread,
Nov 18, 2003, 12:44:12 PM11/18/03
to

The so-called 'stop bit' is really just a gap between characters whose
minimum length can usually be set, so you couldn't really use that.
Be careful of using parity - it's quite possible, but remember that
the PC UART has FIFO buffers for data, in other words data may be
queued but changes in parity will happen 'immediately'.


--
Syd

FirmwareMyster

unread,
Nov 18, 2003, 3:45:57 PM11/18/03
to

"Syd Rumpo" <sydr...@notthisclara.co.uk> wrote in message
news:mckkrv4s1qog481v3...@4ax.com...

I've done this on Windows98 using VB4. No problem,
other than it takes a very long time for VB to toggle the parity bit.
Hopefully that is fixed in newer versions of VB.

Unbeliever

unread,
Nov 18, 2003, 7:22:39 AM11/18/03
to

"suchitra" <ssb...@rediffmail.com> wrote in message
news:110cc2fe.03111...@posting.google.com...

I assume that you are using a PC architecture UART as you do not mention
this minor detail. The PC's uarts do not really support 9 bit addressing as
some microcontrollers do. However, you can emulate this bit with the parity
bit. On sending, send with the parity bit high for address and low for
data. On receiving receive with parity low always. That way a byte
received with a parity error will be an address byte (that is if you need
the PC to decode addresses). This does not work for full duplex comms. If
you don't care about the PC being able to respond to addresses, then just
ignore parity errors. You will naturally lose the protection that the
parity bit gives you against data corruption.

HTH
Alf
alf...@remove.the.obvious.ieee.org
www.micromagic.net.au

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.536 / Virus Database: 331 - Release Date: 3/11/2003


Chris Giese

unread,
Nov 18, 2003, 10:55:50 PM11/18/03
to
ssb...@rediffmail.com (suchitra) wrote:

>Hello All
>I wanted to know how can we configure com port for 9 bit
>communication.
>I intend to use the 9th bit as Address/data bit..since i want to
>communicate with more than one devices.

Set up the serial chip to use "stick parity". This is described
in the serial chip documents. The parity bit is "stuck-at-0"
or "stuck-at-1" while the other 8 bits are being transmitted.

You can't change the parity bit until transmit is complete.
However, the Transmitter Empty (TEMT) bit in the serial chip
does not generate an interrupt. This means that transmit
must be polled, which may not work (or not work _well_) under
Windows. Turn the FIFO off too; if the serial chip has one.

The receive side of the software must detect and interpret
parity "errors" to recover the 9th bit.

David Brown

unread,
Nov 19, 2003, 2:53:23 AM11/19/03
to

"FirmwareMyster" <f...@am.nospam> wrote in message
news:9yvub.26152$cs6....@newssvr32.news.prodigy.com...

I've used the parity bit successfully for a 9th bit, taking care to wait for
the buffers to empty before changing the bit. It was painfully slow,
however, even with W2K and Delphi, so I guess the problem covers all windows
forks.

I have heard of a driver that is available (for quite a lot of money) that
does this sort of switching at a lower level, and therefore does it faster,
providing solid 9-bit communications in windows.

Richard Lang

unread,
Nov 19, 2003, 7:22:17 PM11/19/03
to
NoEma...@execpc.com (Chris Giese) wrote in message news:<3fbae8a3...@news.voyager.net>...

As noted by others, if stick parity is availiable (win32 API supports
it) use this, otherwise the only option you have is to fiddle parity
between odd and even on a byte-by-byte basis (I once got this going on
Sun Solaris for Intel and guess that linux would be much the same)

There are one or two manufacturers of ISA/PCI serial comms. cards that
support 9-bit mode, try

http://www.mv.com/ipusers/effsol/products.html

Andrew

unread,
Nov 20, 2003, 8:46:26 AM11/20/03
to
<snip>

> I've used the parity bit successfully for a 9th bit, taking care to
> wait for the buffers to empty before changing the bit. It was
> painfully slow, however, even with W2K and Delphi, so I guess the
> problem covers all windows forks.
>
> I have heard of a driver that is available (for quite a lot of money)
> that does this sort of switching at a lower level, and therefore does
> it faster, providing solid 9-bit communications in windows.

Comm-Drv from http://www.wcscnet.com/Software.htm

0 new messages