First Steps - UART

Pi and UARTs

The MDB Pi HAT interface provides a UART which our device uses for a very simple communication option.

However, with the recent additions to the RPi line, the use of the UART is not so trivial any more.

Generally the documentation on the Raspbian website is good and complete. Here we only provide a reasonable "shortcut" to explain how to quickly get the UART enabled on a Raspberry 3B+;

Warning

Older Raspbian versions work differently or need different settings to allow the use of UARTs. Please ensure you have the latest available version!

Info

Our MDB Pi Hat uses the serial interface on the Pi Hat Connector. Different Pi's and different operating systems will need specific configurations to make the interface accessible to the user. This is out of our scope, and is the responsibility of the buyer of the Pi Hat, NOT Qiba. The following information is without warranty and we cannot guarantee it will work on all variants.

If you are in doubt, please use the MDB-USB Interface instead. The USB drivers are standard across the board and no OS configurations will be necessary.

Setup Pi Hat - Raspbian

In order to connect the Pi Hat to the Raspberry Pi, first it is necessary to configure it and disable the console login on the GPIO serial port, disable hci uart and finally disable the bluetooth UART. To do that please follow these steps:

(a) Disable the console login on the Serial Port

This is done by reconfiguring or manually editing the /boot/cmdline.txt file.

Warning

On the Raspberry Pi 5 the path is: /boot/firmware/cmdline.txt

Either use:

sudo raspi-config

And select Interface Options (usually option 3, but on older versions, option5) and then Serial Port (P6) and the following prompts will be presented:

  • Would you like a login shell to be accessible over serial? Select "No"

  • Would you like the serial port hardware to be enabled? Select "Yes"

OR change these files:

(a)Find and remove the following text from /boot/cmdline.txt

Info

Make sure that after editing the file, the remaining contents are kept intact, and that the file has only one line, like before editing.

console=serial0,115200

(b) Disable the Bluetooth handler

That is quite simple - one command:

sudo systemctl disable hciuart

(c) Disable the Bluetooth UART assignment so it is used for the MDB Pi HAT

Note

On older Raspbian Versions (and some raspberries) the overlay is called " pi3-disable-bt " , but recent Raspbian usually use disable-bt.

To check the correct overlay, issue the command below.

When this command is run, either "disable-bt.dtbo" or "pi3-disable-bt.dtbo" , and the file name without ".dtbo" is the correct string to populate dtoverlay field on boot/config.txt . More information can be found here!** **

ls -la /boot/overlays/ | grep disable

Add these lines with the content below (with the correct dtoverlay value from previous command) to the end of the boot/config.txt file.

Warning

On the Raspberry Pi 5 the path is: /boot/firmware/config.txt

dtoverlay=disable-bt enable_uart=1
dtoverlay=disable-bt enable_uart=1 dtparam=uart0=on
Success

That's it ! After a reboot the default full UART (PL011) should be connected with the Pi Hat.


Setup Pi Hat - Ubuntu Server 18.04/20.04

(a) Override Console Login in /boot/firmware/config.txt

#indicates which kernel kernel=vmlinuz #overrides console login initramfs initrd.img followkernel # disables bluetooth overlay dtoverlay=disable-bt

(b) Disable serial console on /boot/firmware/nobtcmd.txt

console=ttyAMA0,115200 #Remove and leave the rest of the line intact

Serial Interface Parameters

The MDB Pi Hat communicates using the serial interface connected to the 40 pin header and its configured to :

  • Baudrate - 115200

  • Parity - None

  • Data Bits - 8

  • Stop Bits - 1

Testing Pi Hat on Raspbian

It is very easy to test the interface using a standard terminal program such as Minicom.

  • Make sure you have the UART configured correctly (as documented above)

  • Install a terminal program such as minicom (on pi, simple use the "sudo apt-get install minicom" command

  • Start your terminal program and access the /dev/ttyAMA0 device with 115200 baudrate with the following command:

  • sudo minicom -b 115200 -D /dev/ttyAMA0

  • To enable local echo, press CRTL+A then Z then E. This will allow you to see what you're typing.

  • Send the command V + CR (carriage return = Enter). Make sure that command is a capital V not v. Then you should see the response of the MDB Pi Hat.


I/O Lines Used by Pi Hat

IO 5: also called BCM5, is used to signal communication needs between STM and Pi. Will only be used once SPI communication is enabled

IO 6: also called BCM6, controls the reset of the Pi Hat microprocessor. It must be left open (input) or driven "high" to let the CPU run. Driving it "low" (0) will reset (and hold in reset) the CPU.

IO 13: also called BCM13, is used to signal communication needs between STM and Pi. Will only be used once SPI communication is enabled.

IO 8,9,10,11: those are used for the SPI interface and should currently be left uninitialized

The standard state of the IO lines in Raspbian is that they are not accessible to the user on the command line interface. However, there is a simple file interface (standard in Linux for GPIO) to access the IO.

Example - Reboot Pi Hat through GPIO Pins

echo "6" >/sys/class/gpio/export # make io6 available echo "out" >/sys/class/gpio/gpio6/direction # make io6 an output echo "0" >/sys/class/gpio/gpio6/value # set low to reset sleep 1 echo "in" >/sys/class/gpio/gpio6/direction # make io6 an input