简体   繁体   English

Raspberry pi3:C ++串口通讯无法正常工作(Raspberry pi正在运行!)

[英]Raspberry pi3: C++ serial communication not working properly (Raspberry pi was working!)

I have a Raspberry PI B+ with a C++ application that is able to communicate with an Arduino. 我有一个带有C ++应用程序的Raspberry PI B +,可以与Arduino进行通信。 I'm able to read, write, serial connection perfeclty stable. 我能够读,写,串行连接perfeclty stable。

Now, I bought a Raspberry PI3 in order to have more performances and wifi integrated. 现在,我买了一个Raspberry PI3,以便有更多的性能和wifi集成。 After a lot of time spent, I got the QT application working again but the serial communication wouldn't work. 花了很多时间后,我让QT应用程序再次运行,但串行通信无法正常工作。 I connected the serial monitor of Arduino IDE and checked that with RPI 1 it is working fine, and I saw all messages sent following my protocol, so I'm sure that I can analyze what I'm writing out of Raspberry P3. 我连接了Arduino IDE的串口监视器并检查了它与RPI 1它工作正常,我看到所有消息都按照我的协议发送,所以我确信我可以分析我用Raspberry P3编写的内容。 Unfortunaltely, I receive only weird characters: 不幸的是,我只收到奇怪的字符: 在此输入图像描述 I tried different baudrate, for example 115200 and 9600 (expected baudrate!) but the result is different but equally wrong. 我尝试了不同的波特率,例如115200和9600(预期的波特率!),但结果不同但同样错误。

I would like to report what I did in my Raspberry P3: 我想报告我在Raspberry P3中所做的事情: 在此输入图像描述 I disabled the serial port for the console (as I understood on the web) This settings would modify automatically the option: 我禁用了控制台的串口(正如我在网上所理解的)这个设置会自动修改选项: 在此输入图像描述

enable_uart=0

it's strange because in the web I found who is suggesting to enable, who clearly write that it should be disabled because refers to "console over serial". 这很奇怪,因为在网络上我发现谁建议启用,谁清楚地写道它应该被禁用,因为它指的是“控制器串行”。 Then, I added some lines (you can see into red shape) in order to move the bluetooth handling in the miniuart, fixing the cpu frequency to 250 and fixing the default baudrate to 9600. 然后,我添加了一些线(你可以看到红色的形状),以便在miniuart中移动蓝牙处理,将cpu频率固定为250并将默认波特率固定为9600。 在此输入图像描述 Then, I disable the bluetooth with this command: 然后,我用这个命令禁用蓝牙: 在此输入图像描述 I'm really not sure of that but.. something suggested in some posts. 我真的不确定,但在某些帖子中建议的东西。 Finally, this is the setup in my QT c++ application: 最后,这是我的QT c ++应用程序中的设置: 在此输入图像描述 Where I changed the name of the port to "ttyS0", (same "serial1"). 我将端口名称更改为“ttyS0”,(相同的“serial1”)。

So.. what I would like to achieve is setup my pi3 serial communication as was working with piB+, connected on same pins GPIO14 and GPIO15. 所以..我想要实现的是设置我的pi3串行通信,就像使用piB +一样,连接在相同的引脚GPIO14和GPIO15上。 Doesn't matter to bluetooth, I will not use it. 对蓝牙无关紧要,我不会用它。

What I miss or made wrongly? 我错过了什么或做错了什么?

The PINOUT of Raspberry PI3 seems equal to PINOUT of Raspberry PI B+: Raspberry PI3的PINOUT似乎等于Raspberry PI B +的PINOUT: 在此输入图像描述

And the PINOUT of Raspberry B+ is: 而Raspberry B +的PINOUT是: 在此输入图像描述

But I found one interesting thing: 但我发现了一件有趣的事: 在此输入图像描述 It seems the configuration somehow is wrong because GPIO14 and GPIO15 are both INPUTS !! 似乎配置有点错误,因为GPIO14和GPIO15都是INPUTS !!

I finally fixed! 我终于修好了! As I wrote, I found many suggestions on the web but quite often discordant.. so I will report here how I setup my Raspberry p3 in order to work fine. 正如我写的那样,我在网上发现了很多建议,但经常是不和谐的......所以我会在这里报告如何设置我的Raspberry p3以便正常工作。

1) Upgraded my system 1)升级了我的系统

sudo apt-get update
sudo apt-get dist-upgrade

2) Enabled the UART console 2)启用UART控制台

sudo raspi-config

Advanced options --> serial: 高级选项 - >序列: 在此输入图像描述

Note: it will automatically set 1 the enable_uart in the file config.txt. 注意:它会自动在config.txt文件中设置1 enable_uart

3) Edit config.txt 3)编辑config.txt

sudo nano /boot/config.txt

I added basically one line in order to disable the bluetooth port (not used in my case) 我基本上添加了一行以禁用蓝牙端口(在我的情况下不使用) 在此输入图像描述

I also removed the limitation of cpu frequency to 250, found many times as hint in forums, as you can see it's commented (#). 我还将cpu频率的限制删除到250,在论坛中发现很多次,因为你可以看到它被评论(#)。 You can also see the setup of "enable_uart=1" done with raspi-config interface. 您还可以看到使用raspi-config接口完成的“enable_uart = 1”设置。

4) Edit file cmdline.txt 4)编辑文件cmdline.txt

sudo /boot/cmdline.txt

在此输入图像描述

I removed the piece of string where there was something like: 我删除了一些字符串,其中包括:

.... console=serial0,115200 ....

5) Application refers to serial0 5)应用程序指的是serial0

在此输入图像描述

6) DONE ! 6)完成!

I Hope this step-by-step guide works for someone else or in general will be helpful. 我希望这个循序渐进的指南适用于其他人或一般会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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