Cannot configure serial port for a correct data reading

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]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);

}[/code]

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

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:

>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?

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?

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.

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