问题
I have a Raspberry Pi 3 with Android Things running on it, and I'm trying to write an application that makes use of UART serial. I used the sample code in Android Things documentation for sending data, and it worked perfectly, but the code supposed to receive data returns empty bytes.
while ((count = uart.read(buffer, buffer.length)) > 0) { Log.d(TAG, "Read " + count + " bytes from peripheral"); }
There's an interrupt for when the UART buffer gets some data in, and that gets triggered calling the reading function, but reading the buffer returns nothing but zeros. In fact the loop isn't even entered at all.
I'm using a 5V FTDI Cable with a 5/3.3V Level shifter to send and receive data from the Raspberry.
How can I fix this?
回答1:
Raspberry pi 3 has some issue with uart, check these answers:
UART peripherals on Android Things for Raspberry Pi 3
Uart / GPS driver sample buffer overflow
回答2:
Use Docklight to verify UART data with the help of USB-TTL Converter. Check all the Connections like
Tx -> Rx
Rx -> Tx
GND -> GND
.
Send data from Docklight.
来源:https://stackoverflow.com/questions/41497073/android-things-uart-not-receiving-data-rpi3