Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

ttyS0 data problem!

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!!!!!

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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");