当前位置: 首页 > wzjs >正文

昌平建设网站包头市建设局网站

昌平建设网站,包头市建设局网站,asp.net网站开发案例教程,中级经济师考试成绩查询原理图 从上图可以看到RS232的串口接的是UART3,接下来我们需要使能UART3的收发功能。一般串口的驱动程序在内核中都有包含,我们配置使能适配即可。 设备树 复用功能配置 查看6ull如何进行uart3的串口复用配置: 设备树下添加uart3的串口复用…

原理图

         从上图可以看到RS232的串口接的是UART3,接下来我们需要使能UART3的收发功能。一般串口的驱动程序在内核中都有包含,我们配置使能适配即可。

设备树

复用功能配置

        查看6ull如何进行uart3的串口复用配置:

        设备树下添加uart3的串口复用配置:

pinctrl_uart3: uart3grp {fsl,pins = <MX6UL_PAD_UART3_RX_DATA__UART3_DTE_TX 0x1b0b1MX6UL_PAD_UART3_RX_DATA__UART3_DCE_RX 0x1b0b1>;};

添加设备树节点 

        设备树下添加uart3的设备树节点:

&uart3 {pinctrl-names = "default";pinctrl-0 = <&pinctrl_uart3>;status = "okay";
};

        重新编译设备树make dtbs,并拷贝到开发板对应位置替换之前的设备树文件。

查看串口功能配置

        重启开发板后,查看配置是否生效:

        由上图看出UART3功能配置已经生效。

串口应用编程

应用层代码参考

#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <errno.h>#define ttyname "/dev/ttymxc2"
int fd;
static char wbuff[128];
static char rbuff[128];void *read_handler(void * arg){int ret;while(1){memset(rbuff, 0, sizeof(rbuff));ret = read(fd, rbuff, sizeof(rbuff));if(ret == -1 ){perror("read");close(fd);pthread_exit(NULL);}else if(ret > 0){printf("RCV: %s\n", rbuff);fflush(stdout);}}pthread_exit(NULL);
}int main(int argc, char **argv){int ret;pthread_t thread;struct termios tty;fd = open(ttyname, O_RDWR | O_NOCTTY | O_NDELAY);if (fd == -1){// 打开端口失败perror("open_port: Unable to open /dev/tty ");}if(fcntl(fd, F_SETFL, 0)<0) /* 设置串口为阻塞状态*/{printf("fcntl failed!\n");close(fd);return -1;}// 获取当前串口配置memset(&tty, 0, sizeof(tty));if (tcgetattr(fd, &tty) != 0) {perror("Error from tcgetattr: ");}// 配置波特率cfsetispeed(&tty, B115200);cfsetospeed(&tty, B115200);// 配置数据位、停止位和校验tty.c_cflag &= ~CSIZE;tty.c_cflag |= CS8;     // 8数据位tty.c_cflag &= ~CSTOPB; // 1停止位tty.c_cflag &= ~PARENB; // 无校验位/*设置等待时间和最小接收字符*/tty.c_cc[VTIME]  = 1;tty.c_cc[VMIN] = 1;tty.c_cflag |= CREAD | CLOCAL; // 开启接收,忽略modem控制线// tty.c_iflag = IGNPAR | ICRNL; // 忽略校验错误,输入时将回车转换为换行tty.c_oflag = ~(ONLCR | ICRNL); //tty.c_iflag &= ~(INLCR | ICRNL |IGNCR); //tty.c_oflag &= ~OPOST;/*处理未接收字符*/tcflush(fd,TCIFLUSH);// 设置串口配置tcsetattr(fd, TCSANOW, &tty);pthread_create(&thread, NULL, read_handler, NULL);while(1){memset(wbuff, 0 , sizeof(wbuff));printf("请输入发送数据:\n");scanf("%s", wbuff);//printf("wbuff:%s\n", wbuff);strncpy(wbuff + strlen(wbuff) - 2, "\r\n", 2);ret = write(fd, wbuff, strlen(wbuff)+2);if(ret == -1){perror("write");close(fd);return EXIT_FAILURE;}printf("Write success %d\n",ret);}pthread_join(thread, NULL);close(fd);return 0;
}

编译没报错:

        最后拷贝到开发板进行验证

开发板验证

        开发板接好线,PC上开启串口助手进行功能验证:

 


文章转载自:

http://huoLbFla.Ldwxj.cn
http://t4XaXGpz.Ldwxj.cn
http://sVslTZZ3.Ldwxj.cn
http://dbW5hVOa.Ldwxj.cn
http://PSnQ3fUT.Ldwxj.cn
http://eriDKR4W.Ldwxj.cn
http://ktjSoV68.Ldwxj.cn
http://kEz0A2o8.Ldwxj.cn
http://IDRyR6uI.Ldwxj.cn
http://ZQ40PfXs.Ldwxj.cn
http://nB5zFD7n.Ldwxj.cn
http://xZMs5hKn.Ldwxj.cn
http://mqey4noV.Ldwxj.cn
http://cYjxIPUG.Ldwxj.cn
http://upyOBTmK.Ldwxj.cn
http://wLNmxJSW.Ldwxj.cn
http://nlxtIhgJ.Ldwxj.cn
http://EZuICAJl.Ldwxj.cn
http://yWCYyelO.Ldwxj.cn
http://RrhEY39n.Ldwxj.cn
http://uadcnrak.Ldwxj.cn
http://5NVodkO4.Ldwxj.cn
http://QEnrhDCk.Ldwxj.cn
http://r9vbhITJ.Ldwxj.cn
http://6trFIxz1.Ldwxj.cn
http://5R5HJHNH.Ldwxj.cn
http://cW6pTYh4.Ldwxj.cn
http://CtTd2Vuy.Ldwxj.cn
http://54E7Z0Cg.Ldwxj.cn
http://np6OfWkG.Ldwxj.cn
http://www.dtcms.com/wzjs/703107.html

相关文章:

  • 网站开发的收入网站上传的流程
  • 承德工程建设信息网站做网站的公司一年能赚多少钱
  • h5网站和传统网站区别宠物app页面设计
  • 云南SEO网站建设网页制作与设计教材
  • 南宁做网站哪家好asp.net网站安装顺序
  • 清远做网站的怎样进入公众号平台
  • 营销网站建站企业海口网红景点
  • 外卖网站怎么做域名搜索引擎入口
  • 顺德定制网站设计昆明官网seo服务
  • 广州网站建设网站托管运营长沙互联网企业
  • 潮州营销型网站建设推广几何背景生成器网站
  • 做订阅号要建立网站吗群辉做网站服务器python
  • uzi粉丝做的网站常用的北京文化馆设计公司
  • 做网站前后端的发布流程青岛代理记账公司有哪些
  • 景德镇建设局网站筑云网站投诉
  • 中小企业网站建设公司上海平台网站建设公司排名
  • 吉林系统建站怎么用php网站开发路线
  • 温州网站建设策划网站代备案管理系统
  • 末年人免费观看网站郴州网站建设哪里比较好
  • 做毕业设计哪个网站好广告传媒公司主要做什么
  • 网站外链软件班级网站设计模板
  • 有什么教做维c甜品的网站快速排名seo软件
  • 免费网站设计平台易语言网站批量注册怎么做
  • 中国中小企业网站网址导航下载到桌面
  • 宁波网站建设制作订做网络维护工资多少一个月
  • 住建部网站村镇建设管理平台社群营销
  • 做免费采集电影网站犯法吗高碑店做网站的公司
  • 怎么用阿里云服务器做淘客网站网站优化培训如何优化
  • 空包网站怎么做高端手机网站定制
  • 凡科做网站关键词wordpress插件pdf