Additionally, I've no hands on with exactly what you're doing here, yet. But the amount of code you have here for what seems( ? ) to be a really simple application is well . . . OK let me put this another way.
I do not know what's going on with your code there after the fcnt() call. You have a file descriptor opened to the serial device opened already. A serial device in this context is a character device. So why not just start sending / listening for text input / output from here ? Perhaps it's just that I've no hands on with code dealing with serial devices, but much of the code there seems superfluous. Baud rate for instance should already be set when the device is brought up . . . On Thu, Mar 10, 2016 at 3:37 PM, <[email protected]> wrote: > Hello! > > I'm having an issue with using UART1 in c. I've shorted the TX and RX pins > and I can echo back a series of two bytes I send from write. I'm using the > non-canonical code given on this page > <http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html>. > Everything works great the first two times I do this while running the > program, but the third time the BBB hangs during the read command. Anyone > have any idea what to do about this? Here's the relevant parts of my code > below, > > void SERIAL_Init(void) > { > /*******************************************************************/ > printf("\tSerial Port Initialization ..."); > SERIAL_fd = open(MODEMDEVICE,O_RDWR | O_NOCTTY /*| O_NDELAY*/); > if (SERIAL_fd < 0) > { perror(MODEMDEVICE); > exit(-1); > } > fcntl(SERIAL_fd,F_SETFL,0); > tcgetattr(SERIAL_fd,&newtio); > newtio.c_cflag |= CS8 | CLOCAL | CREAD ; > cfsetispeed(&newtio,BAUDRATE); > cfsetospeed(&newtio,BAUDRATE); > newtio.c_iflag = IGNBRK | IGNPAR; > newtio.c_oflag = 0; > newtio.c_lflag = 0; > newtio.c_cc[VTIME]=0; /* inter-character timer unused */ > newtio.c_cc[VMIN]=31; /* blocking read until 18 chars > received */ > tcflush(SERIAL_fd,TCIFLUSH); > tcsetattr(SERIAL_fd,TCSANOW,&newtio); > /****************************************************************/ > printf("Done\n"); > return; > } > > unsigned char test_data[2] = {0x00,0x00}; > > unsigned char read_command[2][2] = { > {0x1a,0x2b}, > {0x90,0x05}, > }; > > while(readTest == 0) > { > printf("Enter 0 to read from maestro pin, 1 to continue with testing\n"); > scanf("%d",&readTest); > write(SERIAL_fd,read_command[0],2); > printf("Wrote values...\n"); > num_bytes = read(SERIAL_fd,&test_data,2); > printf("Value read: %x %x\n",test_data[0],test_data[1]); > > } > > -- > 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 [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
