4
LAB 4: PC Communications In this lab, you will learn to setup the UART module on the MSP430 which allows sending and receiving bytes to/from a PC. 1 Lab Objectives Understand the use and the configuration of the UART Module Understand how data can be sent to the PC and interpreted on the PC side Use serial communication to control LEDs on the experimenter board using a PC 2 Pre-Lab Please read Chapter 24 Universal Serial Communication Interface UART Mode of the MSP430x5xx/MSP430x6xx Family User's Guide prior to the lab and get familiar with the general features of the UART module. Write a code to send data from MSP430 to PC. In order to control LEDs from PC, write a code that send data from PC to MSP430. 2.1 Requirements Hardware: An MSP430 Flash Emulation Tool (MSP-FET430UIF) and the Experimenter Board Software: Code Composer Studio v5 3 Lab Procedure Repeat all steps you learned in Lab0 to create a new project in CCSv5. You might need to add other resources to your projects. 3.1 Setting up PuTTY for Serial Communication with PC Using the Windows Control Panel, find the COM port number which corresponds to the USB connection for the Experimenter Board. In Windows XP, this can be found in the following: Start>Control Panel>System>Hardware>Device Manager. There should appear a MSP- EXP430F5438 USB Serial Port (COMxx) entry under "Ports (COM & LPT)" (the xx in COM identifies the enumeration of the COM port). Open Putty, and then select the Serial Tab and the dialog box shown in the figure below will appear. Configure Putty to use that port at a speed (baud rate) of 57600 with settings of 8N1 (8 data bits, one stop bit and no parity). Also disable hardware flow control.

Lab4 PC Communications Ver00

Embed Size (px)

DESCRIPTION

blah blah blah

Citation preview

  • LAB 4: PC Communications

    In this lab, you will learn to setup the UART module on the MSP430 which allows sending and

    receiving bytes to/from a PC.

    1 Lab Objectives

    Understand the use and the configuration of the UART Module

    Understand how data can be sent to the PC and interpreted on the PC side

    Use serial communication to control LEDs on the experimenter board using a PC

    2 Pre-Lab

    Please read Chapter 24 Universal Serial Communication Interface UART Mode of the MSP430x5xx/MSP430x6xx Family User's Guide prior to the lab and get familiar with the

    general features of the UART module. Write a code to send data from MSP430 to PC. In

    order to control LEDs from PC, write a code that send data from PC to MSP430.

    2.1 Requirements

    Hardware: An MSP430 Flash Emulation Tool (MSP-FET430UIF) and the Experimenter Board

    Software: Code Composer Studio v5

    3 Lab Procedure

    Repeat all steps you learned in Lab0 to create a new project in CCSv5. You might need to

    add other resources to your projects.

    3.1 Setting up PuTTY for Serial Communication with PC

    Using the Windows Control Panel, find the COM port number which corresponds to the USB

    connection for the Experimenter Board. In Windows XP, this can be found in the following:

    Start>Control Panel>System>Hardware>Device Manager. There should appear a MSP-

    EXP430F5438 USB Serial Port (COMxx) entry under "Ports (COM & LPT)" (the xx in COM identifies the enumeration of the COM port).

    Open Putty, and then select the Serial Tab and the dialog box shown in the figure below will

    appear. Configure Putty to use that port at a speed (baud rate) of 57600 with settings of 8N1 (8

    data bits, one stop bit and no parity). Also disable hardware flow control.

  • After finishing with this box press the Session Tab.

    The above dialog box will have the SSH radio button selected. Press on the Serial Button and the

    configuration from the Serial Tab will be copied here, then press open.

    3.2 Sending X and Y Acceleration to PC

  • The code for Lab 4 is based on Lab 2. The difference is that Lab 4 sets up the UART module and

    uses it to print the same text that is printed on the LCD. The USCI module of the MSP430 is

    connected to a TUSB3410 device. This device bridges the UART signal and converts it into a

    USB connection. No PC in fact has any UART connection and the usual method is to use these

    USB to UART converters.

    The UART module is part of USCI module. Like many other modules of the MSP430, requires a

    clock source to generate the baud rate. Note that this baud rate is one of the major parameters of

    the communications channel between the PC and the MSP430. Other parameters as you have

    configured them in PuTTY are the number of data bits, stop bits, and parity. 8N1, which

    represents 8 data bits, No polarity and 1 stop bits is likely the most common configuration. The

    baud rates supported are usually a common set, among them the most common are 9600, 57600,

    115200, and 230400. The clock that is selected for the module is taken and divided to generate

    the baud rate. This requires a stable clock of the appropriate frequency. Errors in clock selection

    result in error in the effective baud rate and can mean erroneous readings.

    Transmitting data is simply the transmission of bytes. The UART module includes a simple

    buffer that accepts one byte (8 bits) with values from 0 to 255.

    Download the package Lab4_code.zip. Create a project and run the code. You will see two lines

    representing the acceleration of the Experimenter Board in X and Y directions. Note that the

    gravity itself creates a force that will show up as 1g when the board is held sideways.

    Write a function to send the X and Y acceleration to PC. Add the function to main code and by

    calling the function in proper location in main code, send values to PC. By using this function

    Putty will begin printing the values that also appear at the LCD. You may use UCA1TXBUF and UCA1RXBUF buffers.

    Note: Putty interprets the bytes sent by the MSP430 as ASCII. ASCII maps a certain byte for

    each letter. For example, the letter a has the hex value 0x61 assigned. We do not need to worry about the actual hex value since the compiler interprets it correctly. There are single quotes

    around the letter. It is important to note that sending 0 is not the same as sending 0 since 0 with the single quotes is an ASCII letter with the hex value 0x30 (decimal value 48).

    3.3 Implementation of LED Control

    In many cases, it is the PC that needs to control the microcontroller. In this part, you will

    implement a simple program that will toggle the two LEDs. Pressing 1 should toggle one of the

    LEDs and pressing 2 on the keyboard in putty should toggle the other LED.

    The best approach to implement this is to enable the RX interrupt for the UART and

    implement the decision making part (checking which number was sent by the PC) in the

    Interrupt routing since it is simple. Put the MSP430 into a sleep state while waiting for

    commands.

    4 Lab Questions (to be answered in your report)

  • o What problems did you encounter in this Lab?

    o How many bits does the UART module send at one time (how many can you put in the

    buffer)?

    o What is the hex code for the ASCII symbol t ?

    5 Lab Report

    Include the following in your report:

    Answers to all questions.

    6 Documents There are many useful documents you will need as reference during the labs, these include: o MSP-EXP430F5438 Experimenter Board User's Guide This document contains all

    the information about the Experimenter board you will be using, some of which will be

    reproduced here. Designated slau263d and available at the following URL:

    http://focus.ti.com/lit/ug/slau263d/slau263d.pdf

    o MSP430F5438 Datasheet This documents contains much on the information about the MSP430 device itself and its specifications. Although you will not have to deal with

    the details since you are using a prebuilt board, it is useful to familiarize yourself with it.

    http://focus.ti.com/lit/ds/symlink/msp430f5438.pdf

    o MSP430x5xx/MSP430x6xx Family User's Guide A must have description of the MSP430 individual modules. This document describes them in detail including the

    registers and the module operation. It will answer many of your questions of how to use

    the modules of the MSP430F5438.

    http://focus.ti.com/lit/ug/slau208g/slau208g.pdf

    o MSP-EXP439F5438(A) Example Software - This software runs on the Experimenter board and demonstrates the various features such as LCD, Accelerometer, Microphone,

    etc.

    http://www.ti.com/litv/zip/slac227f