I have enabled UART2 on my Beaglebone Black using the device tree overlay method. I am able to communicate with minicom but not in C. I used termios to setup UART2, I have no issues writing data but I do when I try to read. I don't understand why in minicom reading works and not in my C program. What could be the reason? ps- I've attached my code just in case.
Best Regards, Marco Vazquez -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
/* * Program uses UART1 on the BBB to read/write 8 bit data * */ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <stdlib.h> #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; }