Forum Discussion
Altera_Forum
Honored Contributor
14 years agoHow to read RS232 ?
Hello all, I have problem with UART, when i want to read serial data (hex byte message - something like bytes: 02,05,01,02,05 after this 10ms space and 03,05,xx,yy,zz etc.). I have deve...
Altera_Forum
Honored Contributor
14 years agoYes, you are right, i cancel stty command in linux and use
--------------------------------------------------- options.c_lflag &= ~(ICANON | ECHO | ISIG ); in open function: fd = open(S0_232, O_RDWR | O_NOCTTY | O_NDELAY ); // fd = open(S0_232, O_RDWR); // | O_NOCTTY | O_NDELAY ); if (fd > 0) { fcntl(fd, F_SETFL, FNDELAY); tcgetattr(fd, &options); options.c_cflag |= (CLOCAL | CREAD ); options.c_cflag &= ~PARENB; // set no parity, stop bits, data bits options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; options.c_cc[VMIN] = 1; options.c_cc[VTIME] = 0; options.c_lflag &= ~(ICANON | ECHO | ISIG ); tcsetattr(fd, TCSANOW, &options); } But when i read hex message (from PC to Altera NIOS2 system) 16,11,01,00,00,00,00,80,00,7B the linux read 16,01,00,00,00,00,80,00,7B and the second byte doesn't receive .... i read the termios on: http://slackware.osuosl.org/slackware-3.3/docs/mini/serial-port-programming and they say that 0x11 is DC1 which mean VSTART for XON and XOFF and i am not able to disable this software flow control. When i use setting options.c_cflag &= ~(IXON | IXOFF | IXANY); // no flow control or options.c_cflag &= ~CRTSCTS; it doesnt work. Read again:16,01,00,00,00,00,80,00,7B (and the 0x11 is missing). Do you have somebody program, which can read EVERY characters (hex - 00-FF) without any control meanings ? Is possible to disable control characters in options.c_cc[xxx] ? I retype options.c_cc[VSTART] = 0xFE; and the message is read ok, but echo was set ... why ? Where is error ? Jan, Czech Republic