Hardware Reference
In-Depth Information
Header Files
Programs involved in altering TTY settings will want to include the following include
files:
#include <termios.h>
#include <unistd.h>
open(2)
Most of the serial operations in this section require an open file descriptor to the TTY
device being used. For the Raspberry Pi UART, you'll want to specify /dev/ttyAMA0 .
int fd;
fd = open("/dev/ttyAMA0",O_RDWR); /* Open for reading and writing */
if ( fd < 0 ) {
perror("Opening/dev/ttyAMA0");
You may need to take special measures to gain access to the device, since by default
it will be protected. Note the permissions and user/group ownership:
$ ls -l /dev/ttyAMA0
crw-rw---1 root tty 204, 64 Feb 9 13:12 /dev/ttyAMA0
struct termios
Many of the serial port configuration options require the use of the structure termios :
struct termios {
tcflag_t c_iflag; /* input mode flags */
tcflag_t c_oflag; /* output mode flags */
tcflag_t c_cflag; /* control mode flags */
tcflag_t c_lflag; /* local mode flags */
cc_t c_line; /* line discipline */
cc_t c_cc[NCCS]; /* control characters */
speed_t c_ispeed; /* input speed */
speed_t c_ospeed; /* output speed */
};
The tables in the following sections describe the C language macros used for the
members of the termios structure:
9-7 lists the macros for member c_iflag .
Table
 
Search WWH ::




Custom Search