Skip navigation.
Home
The QNX Community Portal

View topic - Cannot configure serial port for a correct data reading

Cannot configure serial port for a correct data reading

For discussion of realtime and/or embedded programming.

Cannot configure serial port for a correct data reading

Postby castiaux.remy » Thu May 24, 2012 2:49 pm

Hi,

I have a serial device that communicates data at 100000 baud, 2 stop bits and an even parity. When I connect the device to my laptop running windows and configure a data serial port monitor (Docklite) to see the data, I can see a correct data reading (trames of 25 bytes beginning by 0x0F and ending by 0x00)

see SBUS_receiver.png attached picture

When I connect the device to a CPU running QNX6.4.1 and configure the port by a C driver in this way:

Code: Select all
int Init_serial_port(int * fd)
{
   struct termios       termios_p;

   // Open the serial port
   *fd = open(config.ser_device, O_RDWR  | O_NOCTTY | O_NDELAY);

   //If the port was successfully opened, configure it
    if (*fd != -1)
    {
       // Get the current port attributes
       if(tcgetattr(*fd, &termios_p))
       {
          printf("Error get\n");
          close(*fd);
          perr(APL_ERR_IO_ERROR);
          return(APL_ERR_IO_ERROR);
       }

       termios_p.c_cflag |= (CLOCAL | CREAD);

       termios_p.c_cflag |= (CSTOPB | PARENB);//set 2 stopbits and paritycheck
       termios_p.c_iflag |=  INPCK; //set input paritycheck

       // Set input and output baud rates
       cfsetispeed(&termios_p, config.baudrate);
       cfsetospeed(&termios_p, config.baudrate);

       // Apply the serial port modifications now
       if(tcsetattr(*fd, TCSANOW, &termios_p))
       {
          printf("Error set\n");
          close(*fd);
          perr(APL_ERR_IO_ERROR);
          return(APL_ERR_IO_ERROR);
       }
       
        //flush the serial port
       if(tcflush(*fd, TCIOFLUSH))
       {
          printf("Error flush\n");
          close(*fd);
          perr(APL_ERR_IO_ERROR);
          return(APL_ERR_IO_ERROR);
       }

       // Get the attributes of the serial port
       if(tcgetattr(*fd, &termios_p))
       {
          printf("Error get\n");
          close(*fd);
          perr(APL_ERR_IO_ERROR);
          return(APL_ERR_IO_ERROR);
       }
       else
       {
          printf("c_cflag: %x\n",termios_p.c_cflag);
          printf("c_iflag: %x\n",termios_p.c_iflag);
          printf("c_ispeed: %i\n",termios_p.c_ispeed);
          printf("c_ospeed: %i\n",termios_p.c_ospeed);
          printf("**********************************\n");
       }
    }

    printf("Serial port opened correctly\n");
   return(0);
}


Next in my driver, I read the data by those instructions:

Code: Select all
   
while(1)
{
     result = read(fd, buffer, 1);
     printf("%x ", buffer[0]);
}


When I launch my driver, the reading of the data is wrong as you can see in the console.png picture

when I execute the stty command line on the serial port of the target, I have the following result:

Code: Select all
>stty < /dev/ser5
Name:  /dev/ser5
Type:  serial
Opens: 1
+raw +clocal +imaxbel +onlcr
 intr=^C  quit=^\ erase=^?  kill=^U   eof=^D start=^Q  stop=^S  susp=^Z
lnext=^V   min=01  time=00   pr1=^[   pr2=5B  left=44 right=43    up=41
 down=42   ins=40   del=50  home=48   end=59
par=even bits=8 stopb=2 baud=100000 rows=0,0
GC /uav>


It seems to me that the serial port is correctly configured, isn't it?
Attachments
Console.png
Reading of the data on the QNX target CPU
(19.95 KiB) Not downloaded yet
SBUS_receiver.png
Data reading from a serial port monitor
(99.4 KiB) Not downloaded yet
castiaux.remy
New Member
 
Posts: 2
Joined: Thu May 24, 2012 1:57 pm

Re: Cannot configure serial port for a correct data reading

Postby mario » Thu May 24, 2012 4:07 pm

I'm not sure QNX can deal with non standard 100000 baudrate. Not all serial chip can support that baud rate hence I think QNX serial driver isn't trying to be smart about this and handle new chip.

If memory serves me right there is an argument to the driver to change the clock ratio, maybe 100000 can be acheive through this?
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Re: Cannot configure serial port for a correct data reading

Postby maschoen » Thu May 24, 2012 5:24 pm

If you can determine which UART chip is on the board, and you can get the specs, you might be able to program it directly. It still may or may not work with the QNX serial driver.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: Cannot configure serial port for a correct data reading

Postby castiaux.remy » Tue May 29, 2012 2:17 pm

I use a serial board with 2x 2x QUAD 16C550 UARTS. I think that the board can handle 100000 as baudrate.
By removing the flags O_NOCTTY | O_NDELAY in the open() instruction, I received data with a better structure. Nevetheless, the incoming data frame are not the ones I expected.
I think the problem is related to the non-default baudrate and the QNX driver. I did several tests by changing the baudrate and I obtain different data frame structures as you can see on attached picture..
Anyone can confirm this fact?

Thank you
Attachments
Data_100000.png
Baudrate = 100000
(19.78 KiB) Not downloaded yet
Data_76800.png
baudrate = 76800
(18.56 KiB) Not downloaded yet
Data_57600.png
Baudrate = 57600
(27.18 KiB) Not downloaded yet
castiaux.remy
New Member
 
Posts: 2
Joined: Thu May 24, 2012 1:57 pm


Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 1 guest