红联Linux门户
Linux帮助

Linux UART无法接受‘\r’即0X0D

发布时间:2017-03-09 09:33:02来源:linux网站作者:Homekit2015
1.问题
当uart接受到0x0d即‘\r’时,从驱动读出来却是0x0a
原因:UART配置问题
 
2.解决方法
参考下列配置方式:
options.c_cflag &= ~PARENB;
options.c_iflag &= ~INPCK;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_oflag &= ~(BSDLY|CRDLY|FFDLY|NLDLY|OFDEL|OFILL|OLCUC|ONLRET|ONOCR|OPOST|OCRNL|ONLCR);
options.c_lflag &= ~(FLUSHO|ECHOKE|PENDIN|TOSTOP|XCASE|ECHO|ECHOK|ECHONL|ISIG|IEXTEN|ECHOE);
options.c_lflag |= ICANON;
options.c_iflag &= ~(IXON|IXOFF|IXANY|IGNCR|ICRNL|INLCR|BRKINT|IGNPAR|IMAXBEL|IUCLC|PARMRK|IGNBRK|INPCK|ISTRIP);
options.c_cc[VKILL]= _POSIX_VDISABLE;
options.c_cc[VERASE] = _POSIX_VDISABLE;
options.c_cc[VEOL] = _POSIX_VDISABLE;
options.c_cc[VEOL2] = _POSIX_VDISABLE;
options.c_cc[VEOF] = _POSIX_VDISABLE;
options.c_cc[VWERASE] = _POSIX_VDISABLE;
options.c_cc[VREPRINT] = _POSIX_VDISABLE;
 
参考:
Linux UART无法接受‘\r’即0X0D
 
本文永久更新地址:http://www.linuxdiyf.com/linux/29024.html