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
-
Can you give us the tutorial your following? C programs are usually hard to debug. If you would like to try python, the following post might be helpful: (1) Serial Test Python Program raspberrypi.stackexchange.com/questions/96534/… (2) USB Serial Ports raspberrypi.stackexchange.com/questions/96697/… (3) Rpi3 to Arduino Serial UART Communication Tutorial raspberrypi.stackexchange.com/questions/96184/… – tlfong01 3 mins ago Edit
-
I would suggest to first do the UART loopback tests, to make sure the software and hardware setup are OK. Please feel free to ask me any newbie questions on python uart/serial programming. – tlfong01 just now Edit
.END
Categories: Uncategorized