Uncategorized

Rpi 4 Uart

Asked 
Viewed 5 times
0

I open the port and set the UART

uart_fd = open("/dev/serial0", O_RDWR | O_NOCTTY | O_NDELAY);

if (uart_fd  < 0)
{
    printf("Failed to open UART\n");
    return -1;
}

config.c_cflag = UART_SPEED | CS8 | CLOCAL | CREAD;
config.c_iflag = IGNPAR;
config.c_oflag = 0;
config.c_lflag = 0;

if (tcsetattr(uart_fd, TCSANOW, &config) < 0)  
{
    printf("Error setting UART configuration\n");
    return -1;
}

And I send strings to terminal

void UART_WriteString(const char *str)
{
    write (uart_fd, str, strlen(str));

    //wait all chars are sent
    tcdrain(uart_fd);
}

now I get gibberish on terminal no matter what baud rate I choose. What could be a problem?

 New contributor
.END

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: