Quantcast
Channel: Question and Answer » uart
Viewing all articles
Browse latest Browse all 57

BeagleBone Serial Communication

$
0
0

I have a problem seeing characters written in /dev/ttyS8 on my PC terminal with this C code:

void main (void)
{
    int file, i;
    unsigned char receive[100]; // declare a buffer for receiving data
    char buf[20];
    size_t nbytes;
    ssize_t bytes_written;

    if ((file = open("/dev/ttyS8", O_RDWR))<0)
    {
        printf("UART: Failed to open the file.n");
        return;
    }

    //
    struct termios options; // the termios structure is vital
    tcgetattr(file, &options); // sets the parameters associated with file

    // Set up the communications options:
    // 9600 baud, 8-bit, enable receiver, no modem control lines
    options.c_cflag = B9600 | CS8 | CREAD | CLOCAL;
    options.c_iflag = IGNPAR | ICRNL; // ignore partity errors, CR -> newline
    tcflush(file, TCIFLUSH); // discard file information not transmitted
    tcsetattr(file, TCSANOW, &options); // changes occur immmediately

    strcpy(buf, "This is a testn");
    nbytes = strlen(buf);

    while (1)
    {
        bytes_written = write(file, buf, nbytes);
        sleep(10);
    }
    close(file);
}

I tested if maybe type of serial cable is a problem, but it behaves the same.
/dev/ttyS8 is my UART output, but I cant determine what I’m doing wrong. Any idea what to test will be helpful, or on what to pay attention when trying to do something like this.

Thanks for your help!


Viewing all articles
Browse latest Browse all 57

Trending Articles