//Filename: uart.c // //Project : UART //Author : Jay Kothari //Contact : jaikothari10@gmail.com //Date : #include #include #include #include #include #include #include #include int pauseNanoSec(long nano); void pauseSec(int sec); int main(int argc, char *argv[]) { char buf[30] = "/dev/minettyO1"; //UART config using termios struct termios uart1,old; int fd; unsigned char buf2 = 0xA7; fd = open(buf, O_RDWR | O_NOCTTY); if(fd < 0) printf("port failed to open\n"); while(1) { write(fd,&buf2,1); pauseNanoSec(5000000); if(read(fd,&buf2,1) > 0) printf("%c",buf2); pauseNanoSec(5000000); } close(fd); return 0; } int pauseNanoSec(long nano) { struct timespec tmr1,tmr2; tmr1.tv_sec = 0; tmr1.tv_nsec = nano; if(nanosleep(&tmr1,&tmr2) < 0) { printf("Nano second pause failed\n"); return -1; } } void pauseSec(int sec) { time_t now,later; now = time(NULL); later = time(NULL); while((later - now) < (double)sec) later = time(NULL); }