c - 树莓派无法通过串口通信向PC发送数据

标签 c linux raspberry-pi uart raspberry-pi2

我正在尝试通过 Raspberry Pi 2(raspian wheezy) 和 STM32F4 板之间的串行连接(GPIO UART 引脚)发送/接收数据。我正在使用链接中的示例代码:http://www.raspberry-projects.com/pi/programming-in-c/uart-serial-port/using-the-uart

当我将板上的 TX 和 RX 引脚连接在一起时,它可以工作。然而,当我通过USB-TTL PL2303模块将RPI连接到我的笔记本电脑并使用 super 终端查看结果时,接收到的字符是垃圾字符。我不明白为什么。有什么我错过的吗? 您能给我一些我可以寻找的建议吗?谢谢!

最佳答案

很可能您使用的波特率不正确。它应该是 115200 (115200-8-N-1)(您可以使用 else,但需要将两个端点设置为相同的波特率)。使用 stty 检查串行连接的波特率

stty -F/dev/ttyX

setserial 。如果出现波特率错误,您可以尝试作者所说的:

Try using a slower BAUD rate (or a single 0xFF byte which only has the start bit low) and see if it works. We had a problem using 115k2 baud rate where our microcontroller communicating with the RPi could hit 113636baud or 119047baud. 113636baud had the lowest error margin so we used it and TX from the RPi being received by the microcontroller worked fine. However when transmitting to the RPi nothing was ever received. Changing the microcontroller to use 119047baud caused RX to work.

关于c - 树莓派无法通过串口通信向PC发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33279227/

相关文章:

c - 重新定义结构

c - 通过管道将 C 程序输入传递给 system() 函数 fuinput

linux - GNUWin32 和 cygwin 的区别

c# - Raspberry PI - I2C 不写入数据

node.js - MongoDb 聚合出现错误

c - (;;) 和 while(); 的作用是什么? C中的意思

c - 如何知道 Eclipse 库位置

linux - 如何禁用(关闭)tripwire

python - 遍历我的数据结构,并为其输入随机值

raspberry-pi - 树莓派 SD 卡可以在 RPi 单元之间互换工作吗?