Raspberry PI 3 - Enable Serial Communications to TtyAMA0 to BCM GPIO 14 and GPIO 15

by Novellus in Circuits > Raspberry Pi

13235 Views, 3 Favorites, 0 Comments

Raspberry PI 3 - Enable Serial Communications to TtyAMA0 to BCM GPIO 14 and GPIO 15

RS-232.jpg
RS-232_02.jpg

I recently had interest in enabling UART0 on my Raspberry Pi (3b) so that I could connect it directly to an RS-232 signal level device using a standard 9-pin d-sub connector without having to go through a USB to RS-232 adapter.

Part of the my interest here was to also be able to connect either an RS-232 level converter (MAX3232) or a RS-485 device (MAX485).

I did struggle a bit trying to make Pi configuration work. I don't have much experience with the Raspberry Pi, or it's operating system, so I was on a fairly steep learning curve.

Eventually, through Google searches along with "Trial and Error", I did manage to pull together all the details to make it work to my satisfaction, but the information was not in one concise document that contained all the steps to make this happen.

I'm listing here the steps I took to make this work for me.

Supplies

1 - Raspberry Pi. I used a model 3b.. but this procedure should work with most Pi's specially those wit the latest versions of Raspberry Pi IOS (formerly Raspian).

2 - An "mini" RS-232 Level Converter - TTL to RS-232 - I used a small PCB loaded with a MAX 3232 IC on it that I bought from eBay.. I also successfully tried this with a TTL to RS-485 converter - also purchased from eBay.

Once the Pi was configured, both converters worked to my satisfaction without any problems seen by me.

Install a FRESH Copy on Raspbian on Your Memory Card.

Raspberry_Pi_IOS_01.jpg

I started by installing a Fresh / Most Up-To-Date copy of Raspberry Pi IOS (formerly Raspian) on my Memory Card. I chose to not go the NOOBS route.

Download and install the Imager tool

https://www.raspberrypi.org/downloads/

Download, Unzip and install onto your memory card the Raspberry Pi IOS image.

After boot-up, check and update as required...

Enable the Raspberry Pi Serial Port - Using the GUI.

RPI_Config_01.jpg
RPI_Config_02.jpg

By default, on a new Raspberry Pi IOS installation UART0 is reserved for the "Logon Shell". That is meant to give you some access / control of the Pi via a Serial port / Terminal program combination.

In order to use UART0 for other applications, you need to "turn-off" that connection to the Logon Shell. This occurs in a couple of fairly easy steps.

The quickest way to enable the "Serial Port" is to do it through the GUI.

From the "Raspberry - Drop-down Menu", select "Preferences", and then "Raspberry Pi Configuration"

From there, go to the "Interfaces" tab, and "Enable" the Serial Port (by clicking on the appropriate radio button.

Click OK to exit, and then perform a reboot.

OR.. you can follow this method...

An Alternate Method to Enable the Serial Port (and Disable the Login Shell)

raspi-config_01.jpg
raspi-config_02.jpg
raspi-config_03.jpg
raspi-config_04.jpg
raspi-config_05.jpg
raspi-config_06.jpg
raspi-config_07.jpg

This method is for reference - not necessary but good to know about.

== == ==

An Alternate Method to Disable The Console Using UART0 at Boot-up.

use:

sudo raspi-config

Choose Option #5 - Interfacing Options ==> Select

Choose P6 Serial ==> Select

Answer NO to: Would you like a login shell to be accessible over the serial?

Answer YES to: Would you like the serial port hardware to be enabled?


The response will be:

The serial login shell is disabled

The serial interface is enabled

Select OK

Select Finish

Disable Bluetooth - Release UART0 and Free It Up for TtyAMA0

nano_config_txt_01.jpg
nano_config_txt_02.jpg
nano_config_txt_03.jpg

The second part of the process is to also disconnect the Bluetooth from UART0.

Per this "UART CONFIGURATION" page you'll need to disconnect the Bluetooth device from UART0, and free up UART0 for ttyAMA0 - If needed you can move the Bluetooth to the "mini-UART"

Proceed by editing the file named "config.txt" (located in the "boot" directory) and add ONE line at the very bottom of the page:

dtoverlay=disable-bt

Depending on your situation and desire to use Bluetooth, you may want to add the following line ( but it is not necessary for this tutorial to work correctly). This page also has valuable details on all this business. Please take the time to read the linked file (see above) to gain some understanding of this.

dtoverlay=miniuart-bt

Double check your spelling, then SAVE the file as you EXIT, and reboot.

At this point, you should be good to go.

RPI Pin-out for the UART Port

RasPi_UART0_Pinout.jpg

Per the website "pinout.xyz" the Raspberry Pi UART0 pins are accessible on the following pins.

UART pins in BCM mode are:
RPI Pin #8 / GPIO14 ==> TXD

RPI Pin #10 / GPIO15 ==> RXD

Remember that for these pins, they are "3.3 Volt TTL levels".. these CANOT be used to drive and receive from a RS-232 level or RS-422/RS-485 level device. Attempting to do so WILL cause your on-board UART to burn-out, and will most probably take the processor chip with it.

You MUST use a level converter.

To connect to a RS-232 level or RS-422/RS-485 level device you need an appropriate level converter.

Adding an RS-232 Level to TTL Level Converter Device to Your Raspberry Pi

MAX3232_01.jpg
MAX3232_02.jpg
MAX3232_03.jpg

For TTL to RS-232 levels conversions I use the following converter.

A MAX3232 based Mini RS232 to TTL level Converter.

This item can be powered by 3.3 VDC or even 5 VDC (both available from specific pins on your RPI) and actually use very little current.

The datasheet for the MAX3232 provides valuable details on it's operation, but in reality no coding is required to make this work

Refer to the attached photos, and take the time to carefully connect the Raspberry Pi pins to the appropriate pins on the module. Just know that this device will run on either 3.3VDC or on 5 VDC - both available on the RPI (refer to the Pin-out diagram).

WARNING:

I purchased a lot of 10 of these units from eBay, and I could NOT make any of them work. On the surface they seem like it should be easy enough to use these, but no. After struggling with them for a bit, I found lots of details on FAKE MAX3232 available on-line.

https://www.eevblog.com/forum/reviews/fake-max3232-any-additional-details/...

I do NOT recommend this item.

Adding an RS-485 Level to TTL Level Converter Device to Your Raspberry Pi

MAX485_03b.jpg
MAX485_01b.jpg
MAX485_02b.jpg

Similar on most ways to the previous step, adding an RS-485 level converter is just as easy - maybe even easier.

For TTL to RS-232 levels conversions I use the following converter.


A MAX485 bases RS485 level to TTL level Converter. Again this item can be powered by 3.3 VDC or even 5 VDC (both available from specific pins on your RPI) and actually use very little current. The datasheet for the MAX485 provides valuable details on it's operation, but in reality no coding is required to make this work

Refer to the attached photos, and take the time to carefully connect the Raspberry Pi pins to the appropriate pins on the module. Just know that this device will run on either 3.3VDC or on 5 VDC - both available on the RPI (refer to the Pin-out diagram).

Of note - unlike RS-232, RS-485 does not have a "standard" connector type associated with it. Nomenclature is typically "B-" and "A+", but be aware that not all suppliers follow this same nomenclature. RS-485 runs on "Differential Pair" signal scheme - More details on that is available here. The "wild west" lives on in the RS-485 valley..

Now, It's Your Turn..

You should now be able to connect your Raspberry Pi directly to an external device of your choice.. There are PLENTY of them still in use today.

How you do that is up to you...

For starters, check out "Minicom" or "CuteCom", or check-out the possibilities using "NodeRED".

Synopsys

Feel free to leave comments, or suggestions / corrections. I would appreciate that.