9 bit communication on RS 232

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

Reply to
suchitra
Loading thread data ...

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 snipped-for-privacy@remove.the.obvious.ieee.org

formatting link

--
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
 Click to see the full signature
Reply to
Unbeliever

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

Reply to
moocowmoo

suchitra schrieb:

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ß.
 Click to see the full signature
Reply to
Tilmann Reh

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

HTH, Michael

Reply to
Michael Hofmann

"moocowmoo" wrote in news:bpd3k8$6t3$1$ snipped-for-privacy@news.demon.co.uk:

You can't.

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

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

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

--
- Mark ->
--
Reply to
Mark A. Odell

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

Reply to
Tauno Voipio

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.
Reply to
Android Cat

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

Reply to
Gerhard v d Berg

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

formatting link

Reply to
Andrew

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
Reply to
Syd Rumpo

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.

Reply to
FirmwareMyster

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.

Reply to
Chris Giese

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.

Reply to
David Brown

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

formatting link

Reply to
Richard Lang

Comm-Drv from

formatting link

Reply to
Andrew

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.