Serial port receive problem

Hi,

I want 115200 Baudrate, No-Parity, No-Flow Control, One stop bit UART comminication.
My termios configuration like below, but device receive 7 bit data (maximum value 127).
The target device receives a maximum value of 127 but the transmitters are sending 8 bits of data.

fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);

if(fd == -1)    perror("SERIAL: Unable to open port ");
else               fcntl(fd, F_SETFL, FNDELAY);

struct termios port_settings;

cfsetispeed(&port_settings, B115200);
cfsetospeed(&port_settings, B115200);

port_settings.c_cflag &= ~PARENB;
port_settings.c_cflag &= ~CSTOPB;
port_settings.c_cflag &= ~CSIZE;
port_settings.c_cflag |= CS8;

tcsetattr(fd, TCSANOW, &port_settings);

NOTE: Transmitter works fine.

Why this occurs?

I’m using Colibri iMX6ULL 512MB WB IT V1.1A with Iris Rev. 2.0.

Best regards.

Hi @hyaldiz,

Have you checked if the data you’re transmitting is in the two’s complement representation (from -128 to 127)?

Also, I was searching for the termios flags, and I found a good guide that might help you:
https://www.ibm.com/docs/en/aix/7.1?topic=files-termiosh-file

Best regards,
Hiago.

You should also tcgetattr(fd, &port_settings) before modification. I also find it comforting to set all kinds of bits in that port_settings structure and not rely on anything to be set up properly in there for me.

Hi,

Everything works fine like below, thanks for the help.

fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);

if(fd == -1)    perror("SERIAL: Unable to open port ");
else            fcntl(fd, F_SETFL, FNDELAY);

struct termios port_settings;

tcgetattr(fd, &port_settings);  //Get the current attributes of the serial port

cfsetispeed(&port_settings, B115200);
cfsetospeed(&port_settings, B115200);

port_settings.c_cflag &= ~PARENB;
port_settings.c_cflag &= ~CSTOPB;
port_settings.c_cflag &= ~CSIZE;
port_settings.c_cflag |= CS8;
port_settings.c_cflag &= ~CRTSCTS;  //Disable Hardware Flow Control

port_settings.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
                | INLCR | IGNCR | ICRNL | IXON);
port_settings.c_oflag &= ~OPOST;
port_settings.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);


tcsetattr(fd, TCSANOW, &port_settings);

Best regards,

Dear @hyaldiz,

Thanks for the update. So it seems that you solved your issue, right? Can we mark this as solved?

Best regards,

Dear @gclaudino.tx,

Yes, issue solved. You can mark as solved.

Best regards.

1 Like