Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I'm able to read, write, serial connection perfeclty stable.

Now, I bought a Raspberry PI3 in order to have more performances and wifi integrated. After a lot of time spent, I got the QT application working again but the serial communication wouldn't work. 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. Unfortunaltely, I receive only weird characters: enter image description here I tried different baudrate, for example 115200 and 9600 (expected baudrate!) but the result is different but equally wrong.

I would like to report what I did in my Raspberry P3: enter image description here I disabled the serial port for the console (as I understood on the web) This settings would modify automatically the option: enter image description here

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. enter image description here Then, I disable the bluetooth with this command: enter image description here I'm really not sure of that but.. something suggested in some posts. Finally, this is the setup in my QT c++ application: enter image description here Where I changed the name of the port to "ttyS0", (same "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. 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+: enter image description here

And the PINOUT of Raspberry B+ is: enter image description here

But I found one interesting thing: enter image description here It seems the configuration somehow is wrong because GPIO14 and GPIO15 are both INPUTS !!

like image 591
Andrea Guglielmi Avatar asked Oct 29 '22 22:10

Andrea Guglielmi


1 Answers

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.

1) Upgraded my system

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

2) Enabled the UART console

sudo raspi-config

Advanced options --> serial: enter image description here

Note: it will automatically set 1 the enable_uart in the file config.txt.

3) Edit config.txt

sudo nano /boot/config.txt

I added basically one line in order to disable the bluetooth port (not used in my case) enter image description here

I also removed the limitation of cpu frequency to 250, found many times as hint in forums, as you can see it's commented (#). You can also see the setup of "enable_uart=1" done with raspi-config interface.

4) Edit file cmdline.txt

sudo /boot/cmdline.txt

enter image description here

I removed the piece of string where there was something like:

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

5) Application refers to serial0

enter image description here

6) DONE !

I Hope this step-by-step guide works for someone else or in general will be helpful.

like image 158
Andrea Guglielmi Avatar answered Nov 09 '22 15:11

Andrea Guglielmi