S3C2440 GPS串口配置以及数据读写
参考文章:http://www.cnblogs.com/jason-lu/articles/3173988.html
http://www.cnblogs.com/chengmin/p/3818133.html
gps模块用串口线与S3C2440的ttyS1串口连接
串口操作需要的头文件:
<span style="font-size:18px;">#include <stdio.h> /*标准输入输出定义*/
#include <stdlib.h> /*标准函数库定义*/
#include <unistd.h> /*Unix 标准函数定义*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> /*文件控制定义*/
#include <termios.h> /*PPSIX 终端控制定义*/
#include <errno.h> /*错误号定义*/</span>
打开串口的方式:
<span style="font-size:18px;">int fd;
/*以读写方式打开串口*/
fd = open( "/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
if (-1 == fd){
/* 不能打开串口一*/
perror(" 提示错误!");
}</span>
设置串口参数:
串口参数使用termios结构体保存
struct termios
c_cflag | 控制选项 |
c_lflag | 行选项 |
c_iflag | 输入选项 |
c_oflag | 输出选项 |
c_cc | 控制字符 |
c_ispeed | 输入波特率(NEW) |
c_ospeed |