零基础操作Linux串口(一)

本人一直在做stm32开发,少有接触Linux,最近需要用到Linux串口,特来记录一番学习过程怕今后忘了。

语言:c

平台:nvidia TX2+CTI接口板

环境:ubuntu16.04

第一步:看CTI接口板文档


如图所示为CTI接口板(CTIM-ASG003)文档,该板有2个串口,串口0和串口1地址分别为/dev/ttyS0和/devttyTHS2。

第二步:写C代码

#include <stdio.h>/*标准输入输出定义*/
#include <sys/types.h>/*数据类型*/
#include <sys/stat.h>/*返回值属性定义*/
#include <fcntl.h>/*文件控制定义*/
#include <unistd.h> /*Unix 标准函数定义*/
void main(){
	int fd;
	char *uart0 = "/dev/ttyS0";
	if((fd = open(uart0,O_RDWR|O_CREAT,0777))<0){
		printf("open %s failed!\n",uart0);
	}
	else{
		printf("open %s is success!\n",uart0);
	}	
	close(fd);
}

第三步:编译

gcc -o open open.c

备注:我的文件名为open.c

第四步:运行

./open.c

第5步:看结果






猜你喜欢

转载自blog.csdn.net/weixin_41012767/article/details/80309887