intro to msp430

Upload: karan-sodhi

Post on 05-Jan-2016

8 views

Category:

Documents


0 download

DESCRIPTION

Intro to MSP430

TRANSCRIPT

  • EE 4390 Laboratory # 1

    Introduction to the MSP-EXP430G2 LaunchPad and Energia

    Purpose

    In this lab, the student will gain rst exposure to programming an MSP430G2xxx microcontroller onthe Texas Instruments MSP-EXP430G2 LaunchPad evaluation kit. The Energia integrated developmentenvironment (IDE) is utilized to provide a C/C++ coding platform as well as a user-friendly interfacefor uploading the application code into the microcontroller. The student will also begin to utilize thebenchtop oscilloscope and logic analyzer to observe and record the timing of events associated with themicrocontroller embedded application.

    Background

    According to the Energia website, http://energia.nu/faqs,. . .

    \Energia is an open-source electronics prototyping platform developed by Robert Wessels withthe goal to bring the Arduino and Wiring framework to the Texas Instruments MSP430 Launch-Pad evaluation kit."

    What this means to us is that we have inexpensive (free) access to a well-tested tool-chain (compiler, assem-bler, linker, uploader, debugger) for implementing embedded microcontroller solutions with the MSP430.The Wiring (http://wiring.org.co) and Arduino (http://arduino.cc) software and hardware projectsform an excellent foundation for beginner through expert-level use. Extensive example projects and in-terface libraries make beginner-level implementation of even large systems quite achievable. In this class,we'll rst test the waters of system implementation at the beginner-level (this lab exercise) then plungedeeply into the bowels of advanced to expert-level use of the excellent tool-chain that underlies Energia .To download this software onto your personal computer, visit the Energia website and select appropriately(implementations are available for Mac OS X, Windows and Linux). No download is required for most ofour course needs if you are working on campus (we'll introduce and demonstrate in class how to utilizeEnergia from a networked drive for Windows machines). The most recent version of Energia available fordownload is 16. The computing labs you will work with this semester have everything from version 11 to16 available. You should see very little if any dierence across versions for our particular needs.

    When you run the Energia IDE, the user-interface window you view by default should appear similar tothat shown in Figure 1.1. The le edit window presents an empty \Sketch," which is simply a templateof the bare essential C++ functions that the designer must ll-in in order to describe their applicationprogram. The conceptual framework for the implementation is the following:

    (a) When the microcontroller powers up or responds to a system reset, all essential housekeeping initial-ization at the lowest levels is completed in a default manner.

    (b) Next, the user-specied setup() function is called to complete application specic initialization.

    (c) Finally, an innite loop is entered wherein the user-specied loop() function is called \forever" (thatis, if the execution of loop() ends, it will be recalled almost immediately to again execute).

    5

  • EE 4390 Laboratory Manual

    Figure 1.1 The Default Screen for the Energia User-Interface

    A large number of example Sketches can be accessed from the Energia File / Examples menu. Figure 1.2demonstrates the new Energia window which opens up when the menu item File /Examples / 1.Basics/ Blink is selected. The syntax shown is legal C++ and utilizes high-level Wiring functions and classesto provide the following actions within the microcontroller:

    (1) Conguration of the physical pin connected to the LaunchPad red LED as a digital output.

    (2) Driving the pin connected to the LaunchPad red LED with either a HIGH or LOW voltage in orderto turn the LED on or o respectively.

    (3) Execution of a programmable time delay, in units of milliseconds, in order to provide a desired LEDblink pattern.

    Figure 1.2 The Energia User-Interface Showing the Blink Example Sketch

    Compiling, assembling, linking and uploading this application to the LaunchPad MSP430G2553IN20 is asimple matter of pressing the right-arrow icon on the Energia toolbar (or via the File / Upload menu

    6

  • EE 4390 Lab 1: Introduction to the MSP-EXP430G2 LaunchPad and Energia

    item). The nitty-gritty details of this process appear in the lower dialog window for your amusement (andsoon, edication). Perhaps most importantly, error messages associated with these processes will appearin the dialog as well. For the rst few weeks, these steps will likely appear mysterious, but be assured,we'll unlock a lot of the mysteries.

    Procedure

    Task A (Prelab). This lab has only one minor Prelab step. Each student must obtain, likely throughpurchase across the Web, a Texas Instruments MSP-EXP430G2 LaunchPad evaluation kit. This device,with an MSP430G2553IN20 installed in the DIP socket, should be brought to lab along with the accom-panying USB cable. Document in your Lab Notebook the facts regarding where you obtained (or are inthe process of obtaining) your LaunchPad and how much it cost.

    The Prelab tasks must be done before you come to lab, and your completed solutions must be included inyour Lab Notebook. Your TA will gather your notebooks to grade your Prelab at the beginning of lab.

    Task B (In Lab, EN 5030). The goal of the lab procedure is program the microcontroller so thatthe red and green light-emitting diodes (LEDs), located on the bottom edge of the circuit board, ashrepeatedly in the following sequence whenever power is supplied to the LaunchPad:

    (a) Only the red LED should turn on for 0.2 seconds.

    (b) No LED should be on for 0.3 seconds.

    (c) Only the green LED should turn on for 0.5 seconds.

    (d) Repeat from step (a).

    Setting Up The Windows 7 computers in the Digital Design Lab, as well as the adjacent general com-puting labs on fth oor of the Engineering Building, have been congured to have the Energia integrateddevelopment environment installed (with accompanying USB drivers for future serial I/0). To connect yourboard, you should only have to log in, connect the small end of the USB cable to the Mini Type B jackon the LaunchPad, then nally plug the USB cable into the computer. The LaunchPad should power-up(indicated by a green LED on the EMULATION tab of the board, immediately below the USB jack).

    The Energia IDE can be run directly by utilizing the Windows File Explorer to navigate to the folder whichcontains the Energia download (for example, C:\ti\energia\energia-0101E0011 or C:\energia-0101E0011or maybe M:\energia-0101E0014, the latter case being if you've mounted \\warehouse\ece\ee4390 un-der drive M:) then double-clicking on the Energia application).

    Suggested Process for Task B: Once you've started the Energia IDE, ensure that the platform and de-vice shown on the bottom right corner of the Energia window is correct (it should read LaunchPad w/msp430g2553 (16MHz)). The accompanying COM port information will be USB port dependent. Thesesettings can be changed through the Tools / Board and Tools / Serial Port menu options. The COMports which might have a LaunchPad connected to them are the ones listed on the Serial Port sub-menu.Select one and try it for uploading as described below. In truth, the COM port assignment won't reallyaect us until we attempt to complete programmed serial I/O later in this semester.

    7

  • EE 4390 Laboratory Manual

    To begin with a simple template code which has much of the capability you need for this exercise, accessthe example projects available on the Files / Examples / 1.Basics menu. In particular, the Blinkproject should get you started.

    Uploading to the Microcontroller: To compile, link and nally upload your program to the LaunchPadand microcontroller, press the right-arrow icon just below the main menu ribbon of the Energia window.NOTE: If you'd like to see all of the gory details of what the IDE is doing for you in thebackground (and you should, we need to master these tasks), go to the File / Preferencesmenu and select both check-boxes for Show verbose output during (compilation) (upload). Themicrocontroller should reset automatically after upload and begin running your new code.

    Your task now is to modify the code from the Blink example in order to complete the specied task,lighting the red and green LEDs alternately. Good luck!

    To fully complete this lab exercise, you must test the timing of your code execution (hint, you'll wantto investigate use of the oscilloscope and logic analyzer at your bench to view the timing waveforms forthe digital output lines which are driving the LEDs on the LaunchPad). A smart-phone camera mightcome in handy for quickly documenting any measurements available on the scope-face! Be sure to obtainappropriate documentation for inclusion in your Lab Notebook.

    Finally, through some exploration with Windows File Explorer, you should be able to nd the source codeof your \Sketch" (that's Energia talk for the code you wrote). Hint, it should be a le with extension .ino,and you are likely to want to make a copy of this onto a USB drive or networked drive for later access.Don't forget to print a copy of it for inclusion in your notebook.

    Lab Report in your Lab Notebook

    During each regular lab session, your teaching assistant should return your Lab Notebook to you aftergrading the Prelab. In lab, maintain a \neat and clear" record of any procedure steps you take whichmight dier from what's described in the lab manual procedure. After lab, tape (strongly encouraged,and on all four sides) or glue (messy and prone to humidity concerns) a copy of your C/C++/assemblycode in your Notebook. Annotate your notebook pages, noting the correctness or signicanceof particular items in the printouts. Don't leave any loose pages in your notebook! You may need to\trim" your printouts down to t nicely onto the pages. Never, ever use staples to attach materialsto your notebook pages. Be sure to include a short (couple of paragraphs) \Lessons Learned" write-upfor each lab in your Lab Notebook!

    8