/* * Program uses UART1 on the BBB to read/write 8 bit data * */ #include #include #include #include #include #include #include #include #define BAUD B115200 #define UART "/dev/ttyO1" int main(){ int fd,k,count; struct termios oldt,newt; char rtemp='m',txdata=0; //Setting variables to 0 memset(&newt,0,sizeof(newt)); fd=open(UART,O_RDWR|O_NOCTTY); if( fd < 0 ){ printf("--"); perror(UART); return 3; } newt.c_cflag = BAUD|CS8|CLOCAL|CREAD; newt.c_iflag = IGNPAR; newt.c_oflag = 0; newt.c_lflag = ICANON; tcflush(fd,TCIFLUSH); if (tcsetattr(fd,TCSANOW,&newt) < 0){ printf("cannot set device\n"); return 4; } k=0; txdata='a'; for(;;){ write(fd,&txdata,1); usleep(100000); count = read(fd,&rtemp,1); usleep(10000); printf("%c : %d\n",rtemp,count); txdata++; if(txdata > 'z'){ txdata='a'; k++; } if(k>2) break; } if(tcsetattr(fd,TCSANOW,&oldt)<0){ printf("can't restore old termios\n"); return 5; } close(fd); return 0; }