[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: I need to configure serial port to send 5 bit characters



Why shift ? A serial port sends least significant bit first. 

Per Zander

On Fri, 4 Oct 2002 gerhard@xxxxxxx.at wrote:

> 
> Hello,
> 
> even when the hardware does not support 5 bits (and that's a fact) you can 
> send 
> 5 bit characters using a simple trick:
> 
> 1. Configure the serial port for 8 data bits
> 2. Take your character and shift it left by 3
> 3. Set the 3 lowest bits to 1
> 4. Send it out
> 
> This should basically work, but you have o live with some limitations.
> 
> - Between two characters you have now 3 more stop bits, this means that you 
> cannot send at the full data rate
> - This works only on transmitting. When you want that receiving works the 
> same way you must ensure that the opposite system inserts also some pause 
> time between two characters, and you have to mask off the "unused stop bits".
> 
> Hope this may work for you,
> Gerhard
> 
> > Hi,
> > 
> > The hardware does not support 5 bit characters. This means that
> > it is impossible for the driver to support 5 bit characters.
> > 
> > /Mikael
> > 
> > -----Original Message-----
> > From: owner-dev-etrax@xxxxxxx.com]On">mailto:owner-dev-etrax@xxxxxxx.com]On
> > Behalf Of Henry Minsky
> > Sent: Friday, October 04, 2002 3:25 AM
> > To: dev-etrax
> > Subject: I need to configure serial port to send 5 bit characters
> > 
> > 
> > 
> > I need to configure the serial port to send 5 bit characters. This is to
> > 
> > communicate with
> > a teletype (yes a real mechanical teletype).
> > 
> > The following code works on my PC linux,
> > 
> > int serial_open() {
> >    ttyfd = open(device_name, O_RDWR | O_NONBLOCK);
> >    if (ttyfd < 0) {
> >      printf("error could not open device %s", device_name);
> >      return (-1);
> >    }
> > 
> >    /* Set 5 bit char size */
> >    tcgetattr(ttyfd,&ttyset);
> >    cfmakeraw(&ttyset);
> >    ttyset.c_cflag &= (((ttyset.c_cflag & ~CSIZE) | CS5)| CSTOPB);
> >    ttyset.c_cflag &= ~(PARENB | CRTSCTS);
> >    ttyset.c_iflag = ttyset.c_oflag = ttyset.c_lflag = (tcflag_t) 0;
> >    cfsetospeed(&ttyset,device_speed);
> >    cfsetispeed(&ttyset,device_speed);
> >    tcsetattr(ttyfd,TCSADRAIN,&ttyset);
> > 
> >    return ttyfd;
> > }
> > 
> > But when I run it on the etrax devboard, the character size that gets
> > sent seems to still be 8 bits.
> > 
> > Does the serial driver not support 5 bit characters (the CS5 option to 
> > c_cflag) ? Is there any workaround for
> > this so I can generate 5 bit characters from the serial port?
> > 
> > Thanks,
> > 	Henry
> > 
>