I'm testing an UART application on the BeagleBone Black and when I try to read from the device it blocks forever. A write works fine. I hooked up a logic analyzer to inspect the line and I can see the data being transmitted and received, but it just always blocks on a read.

int main() {
  int res;
  struct termios tty;
  memset(&tty, 0, sizeof(tty));
  int serial = open("/dev/ser2", O_RDWR | O_NOCTTY);
  if (!isatty(serial))
    return false;
  // Setting the Baud rate
  cfsetispeed(&tty, B9600);
  cfsetospeed(&tty, B9600);
  // 8N1 Mode
  tty.c_cflag &= ~PARENB;
  tty.c_cflag &= ~CSTOPB;
  tty.c_cflag &= ~CSIZE;
  tty.c_cflag |= CS8;
  tty.c_cflag &= ~CRTSCTS;
  tty.c_cflag |= CREAD | CLOCAL;
  tty.c_iflag &= ~(IXON | IXOFF | IXANY);

  tty.c_iflag &= ~(ICANON | ECHO | ECHOE | ECHONL | ISIG);
  tty.c_oflag &= ~OPOST;

  tty.c_cc[VMIN] = 1;
  tty.c_cc[VTIME] = 0;
  if ((tcsetattr(serial, TCSANOW, &tty)) != 0)
    return false;
  if ((tcflush(serial, TCIOFLUSH)) != 0)
    return false;

  while (1)
  {
    uint8_t wrBuff[3] = {0xAA, 0xBB, 0xCC};
    uint8_t res = write(serial, wrBuff, 3);
    printf("Write = %d", res);
    res = read(serial, wrBuff, 3);
    printf("Read = %d", res);
  }
  return 0;
}

I attempted the fix mentioned in the comments below regards the incorrect flag set but this did not fix the issue.

0 Answers