简体   繁体   中英

Raspberry Pi sends unwanted charater when opening the UART port

I am new to the Raspberry Pi and I need a little help with UART communication. I have followed this tutorial: http://www.raspberry-projects.com/pi/programming-in-c/uart-serial-port/using-the-uart

Overall it seems to work allright but the Raspberry Pi sends an unwanted character after the serial port has been opened. I have read in similar posts that this is a known problem and several people are linking to the this page: https://github.com/lp0/linux/commit/d5a48d1f54d2e736cdfa7d6e1602e69feb36c773 .

However I do not quite understand what is going on here.

My function to open the serial port is shown below:

int uart_open()
{
    uart0_filestream = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);      
    if (uart0_filestream < 0)
    {
         return 0;
    }
    else
    {
         return 1;
    }
}

After the port has been opened and the unwanted character has been send, the UART is operating as supposed to. Anyone who knows a solution to this?

If the driver is doing that (as shown in the GitHub link), there's probably very little you can do about it on the application level.

This is simply a bug in the serial port driver; serial ports shouldn't send spontaneous data.

UART is not synchronise with the clock since it is asynchronous. This means the clock on both ends are never exactly the same. Because of that some device don't receive properly the first start and stop bits. A dummy character should be send to ensure good communication.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM