1.连接方法

若debug板的RX/TX没有反转,开发板跟debug板连接方式如下:
                  RX - TX,TX - RX, GND - GND

若debug板的RX/TX有反转,开发板跟debug板连接方式如下:

RX - RX,TX - TX,GND - GND

2.测试开发板的TX功能

开发板通过debug板连接PC,PC打开uart调试工具

在开发板端echo "test" > /dev/ttyS2,PC端uart调试工具可以收到test字符

      需要注意的是PC端的uart调试工具选择的波特率需要跟开发板默认设置的波特率一致,否则字符无法正常显示。

3.测试开发板的RX功能

开发板通过debug板连接PC,PC打开uart调试工具

开发板跑如下读对应ttySx的测试程序:

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>int main(void)
{int fd, ret;fd = open("/dev/ttyS2", O_RDWR|O_NOCTTY|O_NONBLOCK);if (fd < 0){perror("open ttyS2");return 1;}fcntl(fd, F_SETFL, 0); //閲嶈涓哄牭濉炵姸鎬? 鍘绘帀O_NONBLOCK//struct termios opts;tcgetattr(fd, &opts); //鎶婂師璁剧疆鑾峰彇鍑烘潵锛屽瓨鏀惧湪opts//璁剧疆娉㈢壒鐜?cfsetispeed(&opts, B115200);cfsetospeed(&opts, B115200);opts.c_cflag |= CLOCAL|CREAD; //蹇界暐modem鎺у埗绾? 鍚姩鎺ユ敹鍣?// 8N1opts.c_cflag &= ~PARENB; opts.c_cflag &= ~CSTOPB;opts.c_cflag |= CS8;opts.c_cflag &= ~CRTSCTS; //鍏抽棴纭欢娴佹帶opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //raw inputopts.c_oflag &= ~OPOST; // raw output          tcsetattr(fd, TCSANOW, &opts);  //char data[1024];while(1){ret = read(fd, data, sizeof(data));if(ret > 0){data[ret] = 0;printf("got : %s\n", data);}else{printf("not got data ret: %d\n", ret);}memset(data,0,sizeof(data));//sleep(1);}close(fd);return 0;
}

PC通过uart调试工具发送字符,开发板可以正常收到字符:

uart设置波特率:

设置demo程序如下:

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <stdlib.h>int set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop)
{struct termios newtio,oldtio;if  ( tcgetattr( fd,&oldtio)  !=  0) { perror("SetupSerial 1");return -1;}bzero( &newtio, sizeof( newtio ) );newtio.c_cflag  |=  CLOCAL | CREAD; newtio.c_cflag &= ~CSIZE; switch( nBits ){case 7:newtio.c_cflag |= CS7;break;case 8:newtio.c_cflag |= CS8;break;}switch( nEvent ){case 'O':                     //奇校验newtio.c_cflag |= PARENB;newtio.c_cflag |= PARODD;newtio.c_iflag |= (INPCK | ISTRIP);break;case 'E':                     //偶校验newtio.c_iflag |= (INPCK | ISTRIP);newtio.c_cflag |= PARENB;newtio.c_cflag &= ~PARODD;break;case 'N':                    //无校验newtio.c_cflag &= ~PARENB;break;}switch( nSpeed ){case 2400:cfsetispeed(&newtio, B2400);cfsetospeed(&newtio, B2400);break;case 4800:cfsetispeed(&newtio, B4800);cfsetospeed(&newtio, B4800);break;case 9600:cfsetispeed(&newtio, B9600);cfsetospeed(&newtio, B9600);break;case 115200:cfsetispeed(&newtio, B115200);cfsetospeed(&newtio, B115200);break;case 1500000:cfsetispeed(&newtio, B1500000);cfsetospeed(&newtio, B1500000);break;default:cfsetispeed(&newtio, B9600);cfsetospeed(&newtio, B9600);break;}if( nStop == 1 ){newtio.c_cflag &=  ~CSTOPB;}else if ( nStop == 2 ){newtio.c_cflag |=  CSTOPB;}newtio.c_cc[VTIME]  = 0;newtio.c_cc[VMIN] = 0;tcflush(fd,TCIFLUSH);if((tcsetattr(fd,TCSANOW,&newtio))!=0){perror("com set error");return -1;}printf("set done!\n");return 0;
}int open_port(int fd,int comport)
{char *dev[]={"/dev/ttyS0","/dev/ttyS1","/dev/ttyS2"};long  vdisable;if (comport==1){    fd = open( "/dev/ttyS0", O_RDWR|O_NOCTTY|O_NDELAY);if (-1 == fd){perror("Can't Open Serial Port");return(-1);}else {printf("open ttyS0 .....\n");}}else if(comport==2){    fd = open( "/dev/ttyS1", O_RDWR|O_NOCTTY|O_NDELAY);if (-1 == fd){perror("Can't Open Serial Port");return(-1);}else {printf("open ttyS1 .....\n");}    }else if (comport==3){fd = open( "/dev/ttyS2", O_RDWR|O_NOCTTY|O_NDELAY);if (-1 == fd){perror("Can't Open Serial Port");return(-1);}else {printf("open ttyS2 .....\n");}}if(fcntl(fd, F_SETFL, 0)<0){printf("fcntl failed!\n");}else{printf("fcntl=%d\n",fcntl(fd, F_SETFL,0));}if(isatty(STDIN_FILENO)==0){printf("standard input is not a terminal device\n");}else{printf("isatty success!\n");}printf("fd-open=%d\n",fd);return fd;
}int main(void)
{int fd,fdtest;int nread,i;unsigned int ispeed,ospeed;//char buff[]="Hello\n";struct termios tmptio;if((fd=open_port(fd,2))<0){perror("open_port error");return;}if((i=set_opt(fd,1500000,8,'N',1))<0){perror("set_opt error");return;}
#if 0if((fd=open_port(fdtest,1))<0){perror("open_port error");return;}
#endifif( tcgetattr( fd,&tmptio)  !=  0) { perror("SetupSerial 1");return -1;}ospeed = cfgetospeed(&tmptio);ispeed = cfgetispeed(&tmptio);printf("ospeed: %d,ispeed: %d\n",ospeed,ispeed);//printf("fd=%d\n",fd);//nread=read(fd,buff,8);//printf("nread=%d,%s\n",nread,buff);close(fd);return;
}

可以用dump_stack();印出call flow如下:

tty_mode_ioctl->set_termios->tty_set_termios->ms_uart_set_termios

uart RX/TX测试方法相关推荐

  1. 串口流控 UART 中 CTS RTS RX TX (串口模组和MCU直接的通信)

    串口介绍 串口流控,顾名思义就是流量控制的意思.目的是协调收发双方,使数据不会丢失. 一.硬件介绍: 这个图是MCU和串口模组通信硬件,其中箭头方向为型号输出方向 二.引脚介绍 RTS:(Reques ...

  2. Verilog 实现 UART RX 接收器

    目录 1.简述 2.设计 3.实现 4.测试 1.简述 串口作为 CPU 最常使用的外设资源之一,常常出现在各种场合,既然最近在入坑 FPGA,那么先搞一个简单的串口接收机来玩玩: 串口相关的基本知识 ...

  3. MCU的CAN TX RX无数据问题 MCU的CAN TX无数据问题是由于TJA1050的5V供电没有接,我一直量的是TJA1050的脚是3V,这个电压不是外部供进去的,这是由于MCU和RX TX平时

    MCU的CAN TX RX无数据问题 MCU的CAN TX无数据问题是由于TJA1050的5V供电没有接,我一直量的是TJA1050的脚是3V,这个电压不是外部供进去的,这是由于MCU和RX TX平时 ...

  4. EdgeX(7)使用usb ttl 链接 RX TX 调试,输出乱码问题解决,没有想到最后居然是没有焊好。可以使用cuteCom或者putty 在linux上进行界面查询日志

    目录 前言 1,usb ttl 转串口 2,linux 上使用 cuteCom查看日志 3,也可以使用 linux 版本的putty 4,总结 前言 相关EdgeX Foundry 全部分类: htt ...

  5. 以太网 rx tx delay动态补丁测试

    参考源码:x3399_nougat_industry 内核版本4.4 diff --git a/kernel/drivers/net/ethernet/stmicro/stmmac/dwmac-rk. ...

  6. 从零学习VH6501(五) —— 指定对Rx/Tx的报文进行干扰

  7. Unity 自动创建材质球工具

    一个新的模型导入Unity,所有的材质都是绑定的不能修改,想调材质就只能一个个的去创建再拖贴图,想搞个工具一键创建材质并且上好贴图.百度了一下,这玩意靠谱的也是没几个,自己写一个吧. 这个稍微靠谱点, ...

  8. Cortex-A9 UART

    一.Exynos4412 UART 的特性 Exynos4412 中UART,有4 个独立的通道,每个通道都可以工作于中断模式或DMA 模式,即 UART 可以发出中断或 DMA 请求以便在UART ...

  9. 调试血泪经验之uart/ttl/rs232电平转换问题

    发现已经有前辈总结,感谢!http://blog.sina.com.cn/s/blog_6330c39b0102vrqm.html 芯片tx直接输入的是ttl电平 现象 我用usb转rs232的连接线 ...

最新文章

  1. KITTI数据集上MaskRCNN检测效果示例
  2. 怎么获取html的某个元素,MSHTML怎么获取一个网页元素对象
  3. 【深度学习】强化学习Q-Learning和DQN的应用(迷宫)
  4. 基于内存数据库的分布式数据库架构
  5. python 统计组合用什么库_Python数据科学,用这些库就够了
  6. 金山毒霸2012正式公测 首次实现新病毒99秒查杀
  7. jQuery deferred应用dom加载完毕详细源码分析(三)
  8. 可执行文件添加快捷方式_如何停止Windows向快捷方式文件名添加“-快捷方式”...
  9. .NET Core 3.0 可回收程序集加载上下文
  10. 比IETEST更好用的浏览器兼容性测试软件[绿色]
  11. Facebook图片存储架构技术全解析
  12. 怎么配置服务器php环境,配置PHP服务器环境步骤详解
  13. 昔日网瘾少年,现在用AI教你打守望先锋
  14. C++11 继承构造函数
  15. ssm教师教学评价系统(ssm教学评价系统教师ssm学生评教系统)JSP网上评教系统jsp评教系统
  16. TM中拒收自定义表情的设置方法(转)
  17. 如何指定网站内搜索关键字(借用已有搜索引擎)
  18. 中兴服务器车间,走进中兴通讯车间 探秘智能手机生产链(多图)
  19. VS2008与Office2007冲突解决办法
  20. unity中RectTransform的各个值得获取

热门文章

  1. 千人聚集一起看秀?刷爆魔都朋友圈的灯光秀里到底有什么?
  2. 【论文笔记】:Libra R-CNN: Towards Balanced Learning for Object Detection
  3. windows无法连接到wifi
  4. 学堂在线课程字幕下载
  5. 王佩丰excel学习笔记(二):第三——六讲
  6. i.MX 8M Mini Cortex-M4 Hello World
  7. Bad Request This combination of host and port requires TLS.解决记录
  8. c语言 拟合三角函数,根据相关数据进行三角函数拟合.PPT
  9. 《深入浅出 node.js 笔记》 - part3
  10. 空间数据索引RTree完全解析