How to setup the Beaglebone Black RS232 and UART for serial communications.
Today we are going to be setting up the Beaglebone Black RS232 and the UART ports, giving us the ability of serial communications. This method will work for Beaglebone’s running the Debian or Ubuntu Operating System. We will first set up the UART’s in the uEnv.txt boot file, so the UART’s will automatically be enabled during boot. Second, we will be installing a program called Minicom to test that our UART’s are functioning properly. Concurrently with installing Minicom, we will be wiring up the Beaglebone Black’s UART’s #1 and #2 to use with Minicom to test the functionality. Finally, we will incorporate a RS-232 Interface IC Dual EIA-232 Driver into our circuit, and wiring it up to the Beaglebone Black. The chip that we will be using in our example is a Texas Instruments MAX232IN chip. We will then run the same Minicom commands to ensure proper functionality and wiring of the MAX232 chip.
RS232 is a serial communications port used to connect devices to a computer. Today, many serial communication devices have been converted to the updated USB standard. However, there are still many devices and uses for the RS232 standard. The RS232 chip that we are using in this post works as a voltage converter. The chip takes in the voltage of your device (ie a 5V signal device), and steps it down to 3.3V, the voltage the UART port on your Beaglebone Black requires.
Parts Needed for this Tutorial
1. Beaglebone Black with Ubuntu or Debian OS.
2. Solderless Breadboard
2. MAX232 chip. I am using Texas Instruments P/N MAX232IN. You can find these online for less than 2 dollars each.
3. Jumper wire kit. We will be using a total of 8 wires in this tutorial.
4. (5) 1 uF capicitors.
5. MAX232 datasheet for reference. The Texas Instruments MAX232 datasheet I am using in this tutorial can be found here: http://www.ti.com/lit/ds/symlink/max232.pdf
Section 1: Setting up the UART’s on the Beaglebone Black
1. SSH onto your Beaglebone Black.
2. Using a text editor in your terminal (vi, nano, etc.), edit the following file: /boot/uboot/uEnv.txt
3. Scroll down until you see this section of lines:
NOTE: your line might look like this: #cape_disable=capemgr.disable_partno= . If this is the case, write the code in step 4 below underneath this line, or edit this line to be the exact same as the step 4 code.
4. You have 2 options for this step. They will both work, and it’s just a matter of your personal preference. Option 1. Edit the line of existing code above in step 3 as it is shown below. Option 2. copy and paste the line of code below, underneath the line of code in step 3. In either option, add the line of code below into your boot/uboot/uEnv.txt file.
NOTE: For this tutorial, we are only going to be using UART 1 and UART 2. We therefore do not need to include in the script BB-UART4 or BB-UART5. I just wanted to show how to turn on all 4 UARTs. Also, UART3 is a transmit only UART, and will not turn on via this method.
5. Save and quit the uEnv.txt file. Run the following command in the terminal: ls -l /dev/ttyO* #(Letter O, not zero)
crw-rw—- 1 root tty 248, 0 May 15 2014 /dev/ttyO0
You should get the return of only /dev/ttyO0. Now we are going to reboot the Beaglebone and run the ls -l /dev/ttyO* again. Once you do this, you should see this result:
crw-rw—- 1 root tty 248, 0 May 15 02:47 /dev/ttyO0
crw-rw—T 1 root dialout 248, 1 May 15 02:47 /dev/ttyO1
crw-rw—T 1 root dialout 248, 2 May 15 02:47 /dev/ttyO2
crw-rw—T 1 root dialout 248, 4 May 15 02:47 /dev/ttyO4
crw-rw—T 1 root dialout 248, 5 May 15 02:47 /dev/ttyO5
You have now successfully enabled your UART ports, which will automatically enable at boot, until you go into the uEnv.txt file and modify/delete/comment the line we just added.
Section 2: Installing Minicom and testing the functionality of the UARTs.
In this step, we are going to be using Minicom to test the Transmit and Receive UART ports. Minicom is a program that acts as a modem controller, and functions as a terminal emulation program. The first part of this step will be installing Minicom, and the second part will consist of wiring UART1 TXD to UART2 RXD, and UART2 TXD to UART1 RXD.
1. Install Minicom. Below is what you should see after entering the sudo-apt-get install minicom command:
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following extra packages will be installed:
The following NEW packages will be installed:
0 upgraded, 2 newly installed, 0 to remove and 95 not upgraded.
Need to get 422 kB of archives.
After this operation, 1,133 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://ftp.us.debian.org/debian/ wheezy/main lrzsz armhf 0.12.21-5 [101 kB]
Get:2 http://ftp.us.debian.org/debian/ wheezy/main minicom armhf 2.6.1-1 [321 kB]
Fetched 422 kB in 1s (289 kB/s)
Selecting previously unselected package lrzsz.
(Reading database … 61418 files and directories currently installed.)
Unpacking lrzsz (from …/lrzsz_0.12.21-5_armhf.deb) …
Selecting previously unselected package minicom.
Unpacking minicom (from …/minicom_2.6.1-1_armhf.deb) …
Processing triggers for man-db …
Setting up lrzsz (0.12.21-5) …
Setting up minicom (2.6.1-1) …
2. We are going to physically wire up the UART ports on the Beaglebone. we are going to connect UART1 TXD (P9_24) to UART2 RXD (P9_22) AND UART2 TXD (P9-21) to UART1 RXD (P9_26). I have included a picture below to visually depict what we are doing.
WARNING: Unplug your Beaglebone Black before plugging any wires into it. Inadvertently putting the wires in the wrong pinhole could lead to damaging your Beaglebone Black.
3. Now we are going to start Minicom. We will need to open up a second terminal so that we can communicate between the two UARTs. First though, we will have to configure Minicom. If you try to run Minicom for the first time, you will get this error:
minicom: cannot open /dev/modem: No such file or directory
We instead have to set up our UART devices in Minicom. In the first terminal, we are going to set up Minicom to be UART1. If you recall above, in Step 5 of Section 1, we ran the command ls -l /dev/ttyO* to list the available ttyO devices, aka the UARTs. After we set the device to UART1, we are going to set the baud rate to 9600. This rate can be anything, as long as it is the same rate for both Minicom terminals. On the command line, type the following command:
In the second terminal, we are going to run the same command, only changing the device from ttyO1 to ttyO2, as shown below:
Your screen should now resemble something like the screenshot below:
To test that your UART setup is working, type anything into the screen on the left Minicom screen. You should see it print out on the second terminal, such as the screenshot below:
Now try to type something into the right (second) terminal. You should see your text appear on the left (first) screen. If everything works, you have sucessfully set up and tested your UART ports. Next, we will incorporate the MAX232 chip, which you will need for many devices. I am currently using this chipset for the Garmin GPS 15xH/15xL.
Section 3: Incorporating a MAX232 chip into your UART design.
1. Once you have obtained a MAX232 chip, plug it into a breadboard. Make sure that the leads on each side of the chip goes on each side of the channel on the breadboard.
2. Pull up your MAX232 chip’s datasheet, and find the circuit schematic for your chip. The TI chips schematic is shown below. Be advised that I have come across MAX232 chips, made by different manufacturers, that have different pin layouts.
3. Set up the circuit on your breadboard according to your datasheet’s schematic. Note the orientation of your capacitors if you are using electrolytic capacitors. If you are using the TI MAX232IN, or have verified your chip’s pinout is the exact same as the one I am using, you can copy the breadboard layout design below.
3. Open two seperate terminals again, and run Minicom like we did in section 2; one with /dev/ttyO1 set as the device, and the other with /dev/ttyO2 as the set device. Run the same test as you did previously. If you get the same results as before, where you type in one terminal, and it prints in the second terminal, congratulations, you have successfully wired the circuit using a RS232 serial communication chip.
Section 4: Connecting your MAX232 circuit to a RS232 connector.
Now that we have successfully tested our MAX232 circuit, we need to connect it to a RS232 connector for use in a practical situation. For this section, we are going to use a DB9 connector. After searching online and locating the DB9 pinout, we see Pin 2 is the Receive pin (RXD), and Pin 3 is the Transmit pin (TXD). Therefore, we are going to connect pin 14 from the MAX232 chip (T1OUT) to the Transmit pin (Pin 3, TXD) on the DB9 connector, and connect pin 13 from the MAX232 chip (R1IN) to the Receive pin (Pin 2, RXD). Reference the following schematic for a pictorial depiction of how this should be wired up to the DB9 connector.
That’s all for now. You should be able to now plug your MAX232 circuit into a secondary device via the DB9 connector. In a later post, we will be connecting our Beaglebone Black to our HAM Radio via the RS232 communication port located in the back of our radios. Be sure to sign up and leave a comment below on what project you are using the MAX232 circuit on, or a project you would like to see us write a post on.
-Brian from TinkerNow