Hello,
I am using rockpi s and trying to access UART1.
Able to send data properly but while receiving, data is getting looped back.
Not able to receive data.
struct termios ti;
int main()
{
int fd;
fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_SYNC);
if (fd < 0) {
perror("Can't open serial port");
return -1;
}
tcflush(fd, -TCIOFLUSH);
if (tcgetattr(fd, &ti) < 0) {
perror("Can't get port settings");
return -1;
}
// cfmakeraw(ti);
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
cfsetospeed(&ti,B9600 );
cfsetispeed(&ti, B9600);
if (tcsetattr(fd, TCSANOW,&ti) < 0) {
printf("Can't set speed\n");
return -1;
}
ti.c_cflag |= PARENB;
ti.c_cflag &=~ CSTOPB;
char arr[]="abcdefg";
char readbuf[100];
memset(readbuf,0,10);
int count=write(fd, arr, sizeof(arr));
printf("Bytes transfered=%d\n",count);
while(1){
int read_bytes=read(fd,readbuf,100);
if (read_bytes>0)
printf("%s",readbuf);
}
}
This is how i am trying to use UART.