Lab 5: ARM Cortex M0 Connecting to the World

Duration: 1 week with 2 lab sessions

Note: Purchase a Bluetooth Module Like This Model for this lab, which will also be used in the Smart Lock Project.


This laboratory assignment will familiarize you with the one of the serial communications peripherals of the ARM Cortex M0.  The UART, or Universal Asynchronous Receiver/Transmitter, is a hardware peripheral that makes sending and receiving bytes of data between embedded components extremely fast and easy.  All of the overhead control, like start and stop bits, parity, and baudrate, are easily configurable through the hardware control registers as with other peripherals that you have previously worked with, and NXP provides a nice example project to help get us started.  Lastly, this lab is also important from the perspective of completing your final project, as in order to do so you will need to be able to stream collected data across Bluetooth from the embedded device you will build for real-time data processing in your Android phone.

The LPCXpresso
        Development Board
Figure 1.  The communication flow achieved during this laboratory.

Pre-lab (Hand in papercopy)

Describe how to use the UART Receiver Buffer Register and the UART Transmitter Holding Register. (Read chapter 13 carefully: UART in the user manual will be helpful!) For more information on UART, read through the lab below and see:

Part 1 (M0 --> UART --> Bluetooth --> Android, "Hello World!")

In this part, you will first need to modify your board once again in soldering connections between the LPCXpresso ports and the Bluetooth Module.  Once your board has been properly connected (see the next part below about connections), you will generate a simple "Hello World!" message to be sent across the UART to the Bluetooth Module, which will relay it across the Bluetooth channel to be seen on your Android's Bluetooth terminal program.

Bluetooth Module

The Bluetooth module is the device that you will leverage for both this lab as well as your final project (so treat it well!).  This Bluetooth device is a module, meaning that it is in actuality composed of more than one IC chip (a BlueCore chip with a separate microcontroller to operate it), although it is treated as one chip with one footprint.  This particular version comes with its own on board voltage regulator and convenient access to the UART Tx/Rx communication pins.

        Board Pin Map
Figure 2.  LPC1115 Board Pin Map

Step 1:  Solder wires connecting the Vcc, GND, Tx, and Rx pins from the LPCXpresso board to the Bluetooth Module--make sure that the Arm UART's Rx connects to the Bluetooth Module Tx (NOT Tx to Tx or Rx to Rx!).

Note: When connecting the Bluetooth Module to your phone for the first time, you need to "pair" the device with your phone.  This is only required for the first time, and can be done with the default password of "1234".

Your Personal Android Phone

You are going to leverage an Android phone/tablet to receive the serial communications from the embedded hardware. 

Step 2:  Using the Android Market app on your phone, download and install one of the two (or both) free Bluetooth Terminal applications for use in this project.

Or you can use CoolTerm to communicate with the Bluetooth module from a laptop, follow this tutorial to download and set it up.

The UART Example Project

For this project, you will utilize another NXP example project--"uart".  Please locate, open, and compile this project.  By coincidence, the BlueModule's default firmware is set to the same serial communications configuration (9600 baud, 8 bits, no Parity, 1 stop bit), however be aware that with other Bluetooth radios you may need to configure this portion yourself. (Note: Verify the Bluetooth module does in fact have its baudrate set at 9600 by looking into the documentation.)

Step 3:  Initiate a debugging session with the "uart" project, and connect your Android phone to your specific Bluetooth device (i.e., make sure not to connect to another group's device).  Test the example's functionality by sending some characters from your Android phone and seeing if they are echoed back by the Arm Cortex M0.

Step 4:  Modify the code in the "uart" example project such that you repeat a message of "Hello World!\n" at some fixed delay interval of your choosing.

Part 2 (Controlling Arm Peripherals from your Phone)

Now that you understand the fundamentals of using the Arm Cortex M0 to facilitate communication between Bluetooth module and the Serial Bluetooth Program, let's do something more useful.  For the second portion of the lab assignment, you are going to use your phone/tablet to control the Arm Cortex M0 peripherals, and namely, the GPIO and ADC ports (GPIO is required, ADC is optional and 10% extra credit).  To do this, you will have the Arm display a menu system to the Bluetooth terminal application, with which you can interact to set different parameters for the two peripherals.

Table 2 describes the expected overall flow of the menu system. You have already provided solutions for the control of the LED's blinking frequency and duty cycle in previous lab assignments, but the parametrization was set statically at compile time, and not dynamically accessible.  In this assignment, you remedy such inflexibility and provide a method of remote configuration for your embedded system your Android phone.

The end goal of this assignment is an ability to traverse these menus at will from your phone's Bluetooth terminal, and enact the desired changes in the peripheral's operation as indicated by the menu choices.  Only the first character of any string of characters sent from the Android phone should be considered, and the rest thrown away.  Each new menu with all options should be displayed in full upon reaching it.  You may select the meaning of 'Slow', 'Fast', etc, for both LED and ADC frequency setting.

ADC Reporting

You may find that the menu is rapidly displaced by the reported ADC values.  This is perfectly okay, as you can refer to this page for which number selections correspond to which menu options.   You will also need to devise a way to send the voltage values.  Remember, the ADC peripheral reports its voltage by a counting of the number of (3.3-0)/2^10 divisions that a measured voltage is closest to.  Keep in mind that even if you chose to just send this count number, that the Bluetooth terminal will interpret it as an ASCII value and print the corresponding characters to your Android screen.  There is no set or right way to handle this, but try to see if you can come up with some interesting solutions to this problem.

Arm Peripheral Control Menu
1.  Control LED
2.  Control ADC

LED Control Menu
1.  Blink ON
2.  Blink OFF
3.  Set Frequency
4.  Set Duty Cycle
5.  Go Back

LED Frequency Menu
1.  Slow
2.  Medium
3.  Fast
4.  Very Fast
5.  Go Back

LED Duty Cycle Menu
1.  10%
2.  25%
3.  50%
4.  75%
5.  90%
6.  Go Back

ADC Control Menu
1.  ADC Reporting ON
2.  ADC Reporting OFF
3.  Set Reporting Frequency
4.  Go Back

ADC Reporting Frequency Menu
1.  Slow
2.  Medium
3.  Fast
4.  Very Fast
5.  Go Back

                LPCXpresso Development Board
Figure 2.  The Arm peripheral configuration menu flow (blue parts are required, red parts are for extra credits (10%)).
Table 1.  The Arm peripheral control program requirements. 
Left column: the required menu functionality, 
Right column: a graphical representation of the menu transitions.

Reference Materials