[serial com (rs232)] 9 bits needed

Sep 30, 2015 5 Replies

I am trying to build a rs485 network using microcontrolers Microcontrolers have the hability to recieve 9 bits data. They use this as an 'adress'. If the adresse matches the folowing data (8bits) are read (causing an interrupt) otherwize they are ignored until the next adress. gcc can't be configurated for 9 bits (CS9 doesn't exist) Is there another way to do it?? Many thanks in advances Andre


Is it 9 bits with no parity? If so, maybe you could bodge it by fiddling the parity bit for each byte sent.

For example:

101010100 = 10101010 + 0 parity (set parity to even before sending this byte) 101010101 = 10101010 + 1 parity (set parity to odd before sending this byte)

And when receiving you can set the receiver for 8 bits + parity (odd or even) with PARMRK (i.e. characters with bad parity are not discarded but marked in the datastream), then calculate the parity of the 8 bits and combine it with the "parity error" indication to know what the 9th bit must have been.

bitfields?

#include #include int main(int argc, char *argv[], char *env[]){ int i; struct { /*9 bit field*/ unsigned x:9; } y; y.x=500; for (i=0;i

GCC is the compiler - it has nothing to do with serial communication.

On the 8250 family of serial interfaces (in the IBM PC way) have a mode called 'stick parity' where you can send the ninth bit, controlling it with the parity selection. On receive, you can follow the parity error bit. Clumsy, but working.

-TV

"9 bit" is a hardware feature of the UART. Hardware support is best, unless you "bit-bang" the serial bits totally in software.

It's not a compiler issue. Look at how the Microchip PIC or Atmel AVR do it: it's via control registers and data that are all 8-bit-bytes.

Software bit-banging.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required