IMX7 UART_BReading

Hi
Here I am writing a simple serial data read application.
I am not able to read the data from serial port (UART_B).
Here is my code for read operation

#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<fcntl.h>
#include<termios.h>
#include <errno.h>

int main(int args,char *argv[])
{
	char buff_tx[100];
	char buff_rx[100];
	int fd;
	struct termios tty;
	
	fd = open("/dev/ttymxc1",O_RDWR);
	if(fd<0)
	{
		printf("fail to open /dev/ttymxc1\n");
		return -1;
	}
	tcgetattr(fd,&tty);
	cfsetispeed(&tty,B9600);
	cfsetospeed(&tty,B9600);

	tty.c_cflag &= ~PARENB;
	tty.c_cflag &= ~CSTOPB;
	tty.c_cflag &= ~CSIZE;
	tty.c_cflag |= CS8;
	tty.c_cflag &= ~CRTSCTS;
	tcsetattr(fd,TCSANOW,&tty);
	
	tcflush(fd,TCIFLUSH);
	
	while(1)
	{
	
		read(fd,buff_rx,sizeof(buff_rx)-1);
		printf("buff_rx = %s\n",buff_rx);
		buff_rx[0]='\0';
	}
	

	close(fd);
	return 0;	
}

But Write operation working properly
Here is the code for write operation

#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<fcntl.h>
#include<stdlib.h>
#include<termios.h>
#include <errno.h>

int main(int args,char *argv[])
{
	char buff_tx[100];
	char buff_rx[100];
	int fd;
	struct termios tty;
	
	fd = open("/dev/ttymxc1",O_RDWR);
	if(fd<0)
	{
		printf("fail to open /dev/ttymxc1\n");
		return -1;
	}
	tcgetattr(fd,&tty);
	cfsetispeed(&tty,B9600);
	cfsetospeed(&tty,B9600);

	tty.c_cflag &= ~PARENB;
	tty.c_cflag &= ~CSTOPB;
	tty.c_cflag &= ~CSIZE;
	tty.c_cflag |= CS8;
	tty.c_cflag &= ~CRTSCTS;
	tcsetattr(fd,TCSANOW,&tty);
	
	tcflush(fd,TCIFLUSH);
	strncpy(buff_tx,"TESTING UART\n",13);
	
	
	
	while(1)
	{
		write(fd,(char *)buff_tx,strlen(buff_tx)-1);
		sleep(1);
		//read(fd,buff_rx,sizeof(buff_rx)-1);
		//printf("buff_rx = %s\n",buff_rx);
		//buff_rx[0]='\0';
	}
	close(fd);
	return 0;	
}

can any one help me to overcome this.

Canonical and noncanonical mode
The setting of the ICANON canon flag in c_lflag determines
whether the terminal is operating in canonical mode (ICANON set)
or noncanonical mode (ICANON unset). By default, ICANON is set.

   In canonical mode:

   * Input is made available line by line.  An input line is
     available when one of the line delimiters is typed (NL, EOL,
     EOL2; or EOF at the start of line).  Except in the case of EOF,
     the line delimiter is included in the buffer returned by
     read(2).

Please check for details:
https://man7.org/linux/man-pages/man3/tcflush.3.html
https://en.wikibooks.org/wiki/Serial_Programming/termios

Hi ashok,
Thanks for your help.
I resolved the problem with your help.
Now we can close this topic.

Hi @TRINU

Glad it worked.
Thanks for the update.