Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

ttyS0 data problem!

Altera_Forum
Honored Contributor II
1,304 Views

dear all: 

i connected ttyS0(cyclone board console terminal) with my computer. when i send "0D"(HEX) to the board ,but i see "0A"(HEX) in NIOS2 SDK shell. I know the ASCII of "LF" is 0A ,"CR" is 0D. Can anyone help me to solve it??? thanks!!!!!
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
585 Views

You can use termios to change the behavior of the terminals.

0 Kudos
Altera_Forum
Honored Contributor II
585 Views

my code is: 

 

 

struct termios options; 

fd=open("/dev/ttyS0",O_RDWR );  

if(fd==-1) 

{printf("Cannot open ttyS0!!\n"); 

exit(0); 

}  

fcntl(fd,F_SETFL,0); 

 

tcgetattr(fd,&options); 

options.c_cflag |=(CLOCAL | CREAD);// 

 

cfsetispeed(&options,B9600); 

cfsetospeed(&options,B9600); 

 

options.c_cflag &= ~PARENB; 

options.c_cflag &= ~CSTOPB; 

options.c_cflag &= ~CSIZE; 

options.c_cflag |= CS8; 

 

//////////////options.c_cflag &= ~CNEW_RTSCTS; 

options.c_iflag &= ~(IXON | IXOFF | IXANY); 

options.c_iflag = IGNPAR | ICRNL; 

options.c_iflag |= INPCK; 

 

options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); 

options.c_oflag &= ~OPOST; 

//options.c_cc[VMIN]=1; 

//options.c_cc[VTIME]=0; 

 

tcflush(fd,TCIFLUSH); 

tcflush(fd,TCIOFLUSH); 

 

tcsetattr(fd,TCSANOW,&options); 

 

//tcsetattr(1,TCSANOW,&options); 

printf("Baudrate 9600 setting OK!!\n"); 

if (tcsetattr(fd,TCSANOW,&options) != 0)  

perror("SetupSerial failure!! \n");
0 Kudos
Reply