The serial port of the Raspberry Pi 3: it's not easy!


had not seen that one coming! The Foundation we the swiped in talk on the Raspberry Pi 3: no information page on their blog, just answers in the forums…
The addition of Bluetooth to the Raspberry Pi 3 has brought designers of raspberry to divert the UART of the BCM2837 previously connected to terminals 8 and 10 of the GPIO to Bluetooth.



click for information about the levels.



the UART of the Raspberry Pi


a UART to Universal Asynchronous Receiver Transmitter , is a universal asynchronous transceiver. In common parlance, it is the component used to make the connection between the computer and the serial port. The computer sends data in parallel (as many sons as bits of data). Therefore, transform these data through a serial link that uses a single thread to get every bit of data. ( Wikipedia )


UART0 = PL011


the SoC of the Raspberry Pi is always based on the same hardware, the BCM2835 . Only the microprocessor has evolved. The BCM2835 has two UART for serial links. The first, the PL011 is a ‘real’ UART:


IE he is autonomous, with its own generator of Baud Rate, and all of the circuits necessary for its operation.


= ‘mini’ UART UART1


the second UART is a ‘mini’ UART:


it does not Baud Rate generator and uses the frequency of the heart of the CPU. This could be good, except the frequency of the CPU is likely to vary according to its 🙁 load


it does not support parity.


it was better before! The serial port of the Raspberry Pi 2



on the first generations of Raspberry Pi (model 1 B, B + and 2) the PL011 UART0 is used and it is connected to pins 8 and 10 of the GPIO. The starting system messages are sent to this port by default. Simply connect a terminal to read.


this series entry can also be connected to a terminal, which will then be used to connect to the Raspberry Pi after will be logged.


Finally, this series E/S is used in industrial applications or home automation, to read GPS data, connect two Raspberry Pi between them, a Raspberry Pi with an Arduino etc


the serial port of the Raspberry Pi 3: cata!


the SoC of the Pi 3 Raspberry is a SoC BCM2837. It is a BCM2836 with an ARMv8 quad-core CPU that can run in 32 or 64 bit. The 32-bit mode is currently selected by default the firmware of the VideoCore on Raspberry Pi 3.



another change occurs in the use of the UART. On all the Raspberry Pi previous, the PL011 was the one UART in service. The Raspberry Pi 3 hosts a Bluetooth module that uses a UART to connect to the SoC. By default, this is the PL011 which is used for Bluetooth because it has a stack greater than that of the ‘mini’ UART FIFO.


mini UART is related to the GPIO port (pins 8 and 10).


this major changes and undocumented “broken” applications that went well with the port series of Raspberry Pi 2 and refused to work on the ft3. Many articles from blogs that worked with previous generations of Raspberry Pi became inoperative. The authors do not necessarily think to revisit these old articles and it will be safe if you use them.


put it like that it sounds weird, but let me explain. The SNOC ( S company N ational O bjets C onnectes ) located in Saint-Sylvain-of Anjou out late January a prototyping for SIGFOX card. This BRKWS01 distributed by Yadom , connects… on the Raspberry Pi serial port (or any other serial 3, 3v). As I prepare an article on this card I needed the serial port of the Raspberry Pi 3.


that is, you have all inclusive.


to run in good conditions this SIGFOX card, I wanted to connect it to the serial port of the GPIO (8 and 10) but… it did not work and suddenly bin that’s this article 🙂


the first thing to do is a choice. Do I need the Bluetooth? My answer is no. It means that I can disable the Bluetooth and suddenly get the “kivabien” for my card SIGFOX UART.


you have 4 options


  • Option 1: use the UART (true!) by losing the Bluetooth function. Swap the two UART/O! To do this, add to [[19459036/boot/config.txt : dtoverlay = ft3-disable-bt
    then remove:
    console = serial0, 115200 in cmdline.txt

  • Option 2: run the serial interface and Bluetooth properly, but the clock speed of the processor will be set ([250MHz] low speed or high speed [500MHz?]).] Add enable_uart = 1 to /boot/config.txt. This will affect the performance of the processor because it controls the speed of the L2 cache, and also note a reduction in the analog audio quality (see here and here ).
    If you opt for the high clock speed (need really a fan and a heater) to keep the performance of the processor and the audio quality, add also force_turbo = 1 to /boot/config.txt.

  • option 3: have a ‘rotten’ serial on the GPIO (variable speed) but have a correct Bluetooth: do nothing. These are the settings default

  • Option 4: operate correctly the serial interface (UART), with a Bluetooth that works slowly. Swap the UART: Add dtoverlay = pi3-miniuart-bt /boot/config.txt file, then set the frequency to a fixed value (low) by adding, always to /boot/config.txt : core_freq = 250 .] This will affect the performance of the processor.  If you prefer to keep higher performance do not add the line core_freq = 250 but rather the line force_turbo = 1 but this requires to use a fan and a heatsink.

I chose the first.


serial ports


if all goes well by doing a ls-l/dev you should find a port serial0 pointing to ttyAMA0 .


of course not question to connect anything behind the serial port without first knowing if it works. You see me coming? So it is a question in the comments at the end of the article on map SIGFOX ( I guess, of course: it will not happen! []) (19459037] 😀):
Hello, I followed the tutorial but it doesn’t work!
answer: “ – what are you tested the serial port before connecting the SIGFOX card? “
no, but I follow the tutorial! It has to work!


Oh well no, dear reader (trice)! Point not enough to follow a tutorial to the letter! You have to check every step that the expected result is to the make you…


certainly tell me you, but how what I do me? to test the serial port?
Easy:
you’re going to connect the ports GPIO 8 and 10 corresponding to TXD and RxD (data-online data received).
When you send data on serial port TxD, they return through the RxD port… Hop here return to sender (this is called a loopback). And the program used to send the data will receive them and show 🙂
good before you get out the big guns we’ll pull out a little piece of Python, already to be aware of what is happening.




attention!


The loopback works well when the UART is connected to pins 8 and 10. Remember to disconnect the short circuit between these two terminals after the end of the test, otherwise you may damage your SoC!



a program in Python


 #! / usr/bin/env python #-*-coding: utf-8-*-# Test serial port import serial test_string = "I tested the serial port 1 2 3 4 5" port_list = ["/dev/ttyAMA0", "/dev/ttyAMA0", "/dev/ttyS0", "/dev/ttyS0",] for port in port_list: try: serialPort = serial. Serial(port, 9600, timeout = 2) print "Serial Port", port, "open for the test:" bytes_sent, bytes_sent = serialPort.write (test_string) print "Sent", "bytes" loopback = serialPort.read (bytes_sent) if loopback == test_string: print "Received", len (loopback), "identical bytes. The port", port,"works well! n"else: print" receipt of incorrect data: ", loopback,"series ", port" port, curly n"serialPort.close () except IOError: print" error on ", port," n"

this program ( adapted from a prog of the forum raspberrypi.org ) will send data output on the serial port and then get back them on the entry.” Here the test that interests us is/dev/ttyAMA0. You can put the ports you want to test in the list.


run the test program and you should get:


[$19459069]pi@raspberrypi:~ python tesTxRx.py Serial Port/dev/ttyAMA0 open for the test: sent 33 bytes received 33 identical bytes.] The/dev/ttyAMA0 port works fine!

Serial port/dev/ttyAMA0 open for the test: sent 33 bytes received 33 identical bytes. The/dev/ttyAMA0 port works fine!

Error on/dev/ttyS0 error on/dev/ttyS0

If you do not have confirmation that the ttyAMA0 port is working correctly, you don’t have to continue. First you have to keep this port to use.


Minicom a Linux terminal emulator mini


to use Minicom , first install it on your Raspberry Pi.


[$19459069]pi@raspberrypi:~ sudo apt – get install minicom

set the:


to adapt operations to the SIGFOX card who will join this Raspberry Pi, it must set the parameters of the serial port at 9600 bits per second, 8 bits data, no parity and one stop bit.] This translates to 9600 8N1.


choose also the serial port so that it matches the port connected to the GPIO: / dev/ttyAMA0 .


there are more test: type… anything on the keyboard and it should appear on the screen. If nothing appears… It’s that the serial port is not working or something is misconfigured.


is not the first time the Foundation Raspberry Pi done us it. We had already seen that with the introduction of systemd, little documented. The regulars of Linux fared as well as, but this had put many beginners in a bad position. Little or no info, no doc… D (😀) system mandatory.


well this is rebelotte. We modify the ports series, little or no info… Surprises in the key!


hey guys think users… The Raspberry Pi is made for education (also) and those who implement are not necessarily the old bearded Linux users! So is it you please a little info and doc, just a little 😉



3 comments:

  1. Did you know that you can shorten your urls with LinkShrink and earn cash for every visitor to your short urls.

    ReplyDelete
  2. Hi, do you have any library for the BRKWS01 for the Raspberry Pi ? (github ...), and have you managed to make it working with and without the BLE ? Thanks.

    ReplyDelete
  3. I tried disabling the Bluetooth function to access ttyAMA0. But even after reboot, it has still not swapped. Should i be using something else other than dtoverlay = ft3-disable-bt because it's a pi zero?

    ReplyDelete

Powered by Blogger.