Embedded System Design Using MSP430 Launchpad Development Kit PDF
Embedded System Design Using MSP430 Launchpad Development Kit PDF
MSP430TM LaunchPadTM
Development Kit
Contents
Preface ........................................................................................................................................... 1
Introduction ................................................................................................................................... 2
Overview......................................................................................................................................... 3
MSP-EXP430G2 LaunchPad ......................................................................................................... 7
Code Composer Studio .................................................................................................................. 9
Using Tera Term ........................................................................................................................... 17
i Contents
www.ti.com Contents
ii Contents
Contents www.ti.com
Contents iii
www.ti.com Contents
iv Contents
www.ti.com
List of Figures
1 Functional Block Diagram of MSP430G2553 ....................................................................... 4
2 Pin Diagram of MSP430G2553 ............................................................................................ 5
3 MSP-EXP430G2 von-Neumann Architecture ....................................................................... 6
4 MSP-EXP430G2 LaunchPad ............................................................................................... 7
5 CCS Functional Overview .................................................................................................. 10
6 CCS Edit Perspective ......................................................................................................... 11
7 CCS Debug Perspective ..................................................................................................... 11
8 Workspace and Projects (as viewed in CCS) ..................................................................... 12
9 Workspace and Projects ..................................................................................................... 12
10 New CCS Project Creation ................................................................................................. 14
11 Debug Environment ............................................................................................................ 15
12 Tera Term New Connection Window .................................................................................. 17
13 Tera Term Serial Port Setup Window ................................................................................. 18
14 Tera Term Terminal Setup Window .................................................................................... 18
1-1 Functional Block Diagram .................................................................................................. 20
1-2 LaunchPad Schematics ...................................................................................................... 21
1-3 Flowchart to Blink the LED Using GPIO ............................................................................. 22
1-4 Watchdog Timer Control Register ...................................................................................... 23
1-5 Register values in CCS Watch Window for LED On .......................................................... 24
1-6 Register values in CCS Watch Window for LED Off .......................................................... 24
2-1 Functional Block Diagram .................................................................................................. 26
2-2 Launchpad Schematics ...................................................................................................... 27
2-3 Pull-up Resistor for Input Pin .............................................................................................. 27
2-4 Pull-down Resistor for Input Pin ......................................................................................... 27
2-5 Flowchart for Controlling LED with a Switch ...................................................................... 29
2-6 Green LED Turned On in MSP-EXP430G2 LaunchPad .................................................... 30
3-1 Typical Current Consumption for Various Operating Modes .............................................. 34
4-1 Functional Block Diagram .................................................................................................. 44
4-2 Flowchart for Interrupt Programming with GPIO ................................................................ 46
5-1 PWM Signal for Varying Duty Cycle ................................................................................... 50
5-2 PWM Output for Analog Signal ..........................................................................................51
5-3 Functional Block Diagram .................................................................................................. 51
5-4 Flowchart for PWM Generation ..........................................................................................53
5-5 Variation in Brightness of Green LED due to PWM ............................................................ 55
5-6 Register Values in CCS Watch Window for Duty Cycle Calculation .................................. 56
6-1 Functional Block Diagram .................................................................................................. 58
6-2 Flowchart for Interfacing the Potentiometer with MSP-EXP430G2 LaunchPad ................. 60
6-3 Hardware Setup ................................................................................................................. 63
6-4 ADC Conversion Register Values in CCS Watch Window ................................................. 64
7-1 PWM Signal for Varying Duty Cycle ................................................................................... 66
7-2 PWM Output for Analog Signal ..........................................................................................67
7-3 Functional Block Diagram .................................................................................................. 68
7-4 Flowchart for PWM Based Speed Control of Motor by Potentiometer ............................... 70
7-5 Connection Diagram for Potentiometer and DC Motor with MSP-EXP430G2XL ............... 72
7-6 Hardware Setup ................................................................................................................. 73
7-7 ADC Conversion Register Values in CCS Watch Window ................................................. 74
8-1 Importing the Project .......................................................................................................... 78
8-2 Selection of Build Configuration ......................................................................................... 79
8-3 Opening the Advice Window .............................................................................................. 80
8-4 Advice Window ................................................................................................................... 80
8-5 ULP Advisor Wiki Page ...................................................................................................... 81
List of Figures v
www.ti.com List of Figuresi
vi List of Figures
www.ti.com
List of Tables
1 Features of MSPEXP430G2553 and MSP430x5xx Series Processors .............................. 3
1-1 Components Required for the Experiment ........................................................................ 21
2-1 Components Required for the Experiment ........................................................................ 28
3-1 CPU and Clock States in Various Operating Modes ......................................................... 33
3-2 Components Required for the Experiment ........................................................................ 35
3-3 Current Consumption for MSP430G2553 ......................................................................... 41
4-1 Components Required for the Experiment ........................................................................ 45
5-1 Components Required for the Experiment ........................................................................ 52
5-2 Duty Cycle Calculation for Timer A Register Values ......................................................... 55
6-1 Components Required for the Experiment ........................................................................ 59
6-2 Configuration Parameters for ADC10 Registers ............................................................... 61
7-1 Components Required for the Experiment ........................................................................ 68
8-1 ULP Rule Violations .......................................................................................................... 76
8-2 Experiment Code Descriptions .......................................................................................... 77
8-3 Components Required for the Experiment ........................................................................ 77
9-1 Components Required for the Experiment ........................................................................ 85
10-1 Components Required for the Experiment ........................................................................ 94
10-2 Configuration Parameters for Registers of USCI_A0 ...................................................... 100
11-1 Components Required for the Experiment ...................................................................... 106
12-1 Microcontratoller State for Various Energy Trace++ modes ........................................... 113
12-2 Components Required for the Experiment ...................................................................... 113
12-3 Connection of Signals ..................................................................................................... 114
12-4 Analysis of Energy Trace Technology ............................................................................. 115
13-1 Components Required for the Experiment ...................................................................... 119
13-2 Connection of Signals ..................................................................................................... 120
13-3 Energy measurement and Estimated lifetime of a battery ............................................... 122
The MSP430 family of microcontrollers from Texas Instruments are ultra-low-power, mixed-signal
processors that are ideal for industrial and consumer application. These devices feature a power-
ful 16-bit, RISC (Reduced Instruction Set) CPU, 16-bit registers, and constant generators which
results in maximum code efficiency. The MSP430 family also consists of several devices featuring
different sets of peripherals targeted for various applications. The MSP430 architecture combined
with low-power modes is optimized to achieve an extended battery life in portable measurement
applications. The Digitally Controlled Oscillator (DCO) of the MSP430 allows wake-up from a low-
power mode to an active mode in less than 1 microsecond. In short, the MSP430 family of micro-
controllers offer the best balance between energy efficiency and performance.
In this manual, MSP430G2553, MSP430F5529 and MSP430FR5969 platforms are used. The
experiments take advantage of a wide range of parts and tools supported by Texas Instruments for
design with the MSP430 series of microcontrollers and wireless communication products. These
easily-available evaluation kits assist the users to get started with designing applications using
MSP430 series microcontroller.
Each experiment in this manual includes:
Experiments 1 to 8 are implemented using MSP430G2 Launchpad which includes typical applica-
tions like GPIO, PWM, ADC, Interrupt, Low Power Modes, UART. Experiments 9 and 10 are imple-
mented using MSP430F5529 Launchpad which includes SPI and WIFI applications. Experiment
11 is implemented using MSPEXP430FR5969 Launchpad which has an on-board Energy Trace
Technology Circuitry as the experimenter board and the MSP430G2 Launchpad as a target mod-
ule to achieve Energy Trace Technology. Experiment 12 is implemented using MSP430G2
Launchpad to test battery life.
On completion of all the experiments in this manual, the user will be able to build a variety of pro-
duction-ready applications with the MSP430 Series microcontrollers.
1 Preface
Introduction
Topics Page
Overview ............................................................................................................................ 3
MSP-EXP430G2 LaunchPad............................................................................................. 6
Code Composer Studio .................................................................................................... 9
Using Tera Term.............................................................................................................. 17
Overview
Introduction
The MSP microcontrollers (MCUs) from Texas Instruments (TI) are 16-bit and 32-bit RISC-based, mixed-
signal processors designed for ultra-low power applications. The MSP430 family of microcontrollers con-
sists of several devices featuring different sets of peripherals targeted for various applications. The
MSP430 device features a powerful 16-bit RISC CPU, 16-bit registers, and constant generators that con-
tribute to maximum code efficiency. The architecture, which includes five low-power modes, is optimized to
achieve extended battery life in portable measurement applications. The digitally controlled oscillator
(DCO) allows wake-up from low-power modes to active mode in less than 1second. The MSP430 instruc-
tion set consists of 27 core instructions that make it easy to program in assembler or in C, and provide
exceptional flexibility and functionality.
MSP low-power + performance microcontrollers from TI provide designers with enhanced performance
and more peripherals on chip while using less power. MSP ultra-low-power microcontrollers are ideal for
applications where the majority of the microcontroller life is spent in standby. Typical applications of these
processors include low-cost sensor systems that capture analog signals, convert them to digital values,
and then process the data for display or for transmission to a host system.
MSP430 Family
In this manual, MSP430G2553, MSP430F5529, MSP430FR5969 platforms are used. The MSP430G2553
series are ultra-low-power mixed signal microcontrollers with built-in, 16-bit timers; up to 24 I/O capacitive-
touch enabled pins; a versatile analog comparator; and built-in communication capability using the univer-
sal serial communication interface. In addition, the MSP430G2553 family members have a 10-bit Analog-
to-Digital Converter (ADC).
The features of MSP430G2553 and MSP430F5529 is shown in Table 1.
Low supply voltage range: 1.8 V to 3.6 V Programmable core voltage with integrated PWM
Memory Memory
• Up to 56 KB Flash • Up to 512 KB Flash
• Up to 4 KB SRAM • Up to 66 KB RAM
For reference, the functional block diagram, pin diagram, description of MSP430G2553 are discussed in
the sections that follow. For other references like MSP430F5529 and MSP430FR5969, refer the datasheet
link in the reference section.
USCI A0
Emulation
Watchdog Timer0_A3 Timer1_A3 UART/LIN,
Comp_A+ IrDA, SPI
Brownout WDT+
JTAG Protection 3 CC 3 CC
Interface 8 channels USCI B0
15-bit registers registers
2
SPI, I C
Spy-Bi-
Wire
RST/NMI
The functional block diagram for the MSP430G2553 is as shown in Figure 1. The architecture of the
MSP430 family is based on a memory-to-memory architecture, a common address space for all functional
blocks, and a reduced instruction set applicable for all functional blocks.
The MSP430G2553 CPU has a 16-bit RISC architecture integrated with 16 registers that provide reduced
instruction execution time. All operations, other than program-flow instructions, are performed as register
operations.
Memory of the MSP430G2553 is divided to program memory (ROM) and data memory (RAM). The pro-
gram memory is accessed by the 16-bit Memory Data bus. The data memory is accessed by the Memory
Address Bus (MAB) and the Memory Data Bus (MDB).
Peripheral modules such as Digital I/O, Analog-to-Digital Converter (ADC), Timers, Universal Asynchro-
nous Receiver Transmitter (UART), Universal Serial Communications Interface (USCI), Comparator_A+,
etc., are connected to the CPU via MAB, MDB and interrupt service and request lines. The operations of
the various peripherals are controlled by the contents of the Special Function Registers (SFRs).
The clock system is supported by the basic clock module that includes support for a 32768-Hz watch
crystal oscillator, an internal very-low-power, low-frequency oscillator and an internal Digitally Controlled
Oscillator (DCO).
The brownout circuit is implemented to provide the proper internal reset signal to the device during power
on and power off.
The Watchdog Timer (WDT+) module restarts the system on occurrence of a software problem or if a
selected time interval expires. The WDT can also be used to generate timely interrupts for an application.
The pin diagram for the MSP430G2553 is given in Figure 2 below.
MSP-EXP430G2
VCC GND
1 20
P1.0 / A0 2 19 P2.6 / XIN
P1.1 / RXD 3 18 P2.7 / XOUT
P1.2 / TXD 4 Test
17
P1.3 / A3 Reset
5 16
P1.4 / A4
6 15 P1.7 / A7
P1.5 / A5 7 14 P1.6 / A6
P2.0 P2.0
8 13
P2.1 P2.1
9 12
P2.2 P2.2
10 11
Access
1FFFFh
Flash/ROM Word/Byte
10000h
0FFFFh
Interrupt Vector Table Word/Byte
0FFE0h
0FFDFh
Flash/ROM Word/Byte
Data in memory can be accessed as either bytes (8-bit) or words (16-bit). The Flash (ROM) and RAM
memories can be used for both code and data. The peripheral modules of the processor are mapped into
the address space for read/write access. Hence, the address space from 0100 to 01FFh is reserved for 16-
bit peripheral modules that can be accessed with word instructions. The address space from 010h to 0FFh
is reserved for 8-bit peripheral modules that are accessed with byte instructions. SFRs control the opera-
tion of the various modules in the processor. Some peripheral functions are also configured in the SFRs.
MSP-EXP430G2 LaunchPad
Introduction
The MSP-EXP430G2 is a low-cost experimenter board, also known as LaunchPad. It provides a complete
development environment that features integrated USB-based emulation and all of the hardware and soft-
ware necessary to develop applications for the MSP430G2xx Value Line series devices.
The MSP430 LaunchPad kit box includes:
Embedded
Emulation
6-pin EZ430
Connector
Crystal Pads
Chip Pinouts
Part and Socket
Power
P1.3 Button
Connector
Hardware Setup
The LaunchPad experimenter board includes a pre-programmed MSP430 device which is already located
in the target socket. When the LaunchPad is connected to your PC via USB, the demo starts with an LED
toggle sequence. The on-board emulator generates the supply voltage and all of the signals necessary to
start the demo.
1. Connect the MSP430 LaunchPad to your PC using the included USB cable.
2. The driver installation starts automatically. If prompted for software, allow Windows to install the soft-
ware automatically.
At this point, the on-board red and green LEDs should toggle back and forth. This confirms that the hard-
ware is working and has been set up correctly.
• The C compiler converts C source code into assembly language source code.
• The assembler translates assembly language source files into machine language object files.
• The standard run-time libraries contain ANSI standard run-time-support functions, compiler-util-
ity functions, floating-point arithmetic functions and I/O functions that are supported by the C com-
piler.
• The linker combines object files, library files and system or BIOS configuration files into a single
executable object module. The .out file is the executable program for the target device.
• The debugger supports debug activities such as watching variables, graphing signals on the tar-
get, viewing the memory and call stack, etc. The .gel files initialize the debugger with address of
memory, peripherals and other hardware setup details.
• The program code can be debugged on the simulator or emulator or the target device based on
the target config file (.ccxml) that specifies the connection to the target.
Standard Target
SYS/BIOS Config
.asm Runtime
Compiler Libraries File Simulator
Libraries
.ccxml
.c .lib
LaunchPad
.asm .obj .out
Edit Assembler Linker Debug
EVM
Target
Board
CCS Perspectives
The Code Composer GUI has two perspectives:
The edit perspective has menus, buttons and editor window to edit the source code as shown in
Figure 6.
The debug perspective has menus, buttons and debug window related to debugging as shown in
Figure 7.
A project contains build and tool settings, as well as links to the input files - source files, header files and
library files as shown in Figure 9.
Hence, deleting projects from the workspace deletes the links, not the projects. Similarly, deleting files from
the project deletes the links, not the files.
5. Code Composer will add the named project to your workspace and display it in the Project Explorer
pane. Based on your template selection, it will also add a file called main.c/ main.asm and open it for edit-
ing.
6. Change the include header file statement from #include <msp430.h> to #include <msp430g2553.h>.
7. Type in your program code in the main.c / main.asm file and save it.
8. CCS can automatically save modified source files, build the program, open the debug perspective view,
connect and download it to the target (flash device), and then run the program to the beginning of the main
Debug Environment
After completion of target download, CCS enters the Debug perspective. Notice the Debug tab in the upper
right-hand corner indicating that we are now in the "CCS Debug" view (See Figure 7). Click and drag the
perspective tabs to the left until you can completely see both tabs.
The basic buttons that control the debug environment are located at the top of the Debug pane. If the pane
is closed accidentally, the Debug controls will disappear. To bring back the debug controls, click
View Debug on the menu bar.
You can explore each button by clicking on it to see its function. At this point, your code should be at the
beginning of main (). Look for a small blue arrow left of the opening brace of main() in the middle window
as shown in Figure 11. The blue arrow indicates where the Program Counter (PC) is pointing to.
To single-step into the code, click Step Into to help in debugging the program and check if each line
of code is producing the desired result.
Click Reset CPU and you should be back at the beginning of main().
The Terminate button will terminate the active debug session, close the debugger and return CCS to
the "CCS Edit" perspective. It also sends a reset to the LaunchPad board.
2. The port is opened with a default Baud Rate of 9600. Change the Baud Rate by selecting Setup
Serial Port. Change the required Serial Port Setup parameters like Baud Rate, Data Bits, Parity, Stop Bit
as shown in Figure 13.
3. Select Setup Terminal New Line Receive Auto to configure the new line char-
acter as shown in Figure 14.
Topics Page
1.1 Objective
The main objective of this experiment is to blink the on-board, red LED (connected to P1.0) using
GPIO. This experiment will help you to learn and understand the procedure for programming the
MSP-EXP430G2 LaunchPad digital I/O pins.
1.2 Introduction
The MSP430G2553 has two general-purpose digital I/O pins connected to green LED (P1.6) and
red LED (P1.0) on the MSP-EXP430G2 LaunchPad for visual feedback. In this experiment, the
code programmed into the MSP430G2553 processor toggles the output on Port P1.0 at fixed time
intervals computed within the code. A HIGH on P1.0 turns the LED ON, while a LOW on P1.0 turns
the LED OFF. Thus, the toggling output blinks the red LED connected to it. The functional block
diagram shown in Figure 1-1 illustrates the working principle of the experiment.
MSP-EXP430G2 MSP-EXP430G2
MSP430G2553
TMC123G MSP430G2553
CPU CPU
P1.0 P1.0
GPIO GPIO
HIGH LOW
LED R LED R
Figure 1-2 shows the Launchpad schematics for the connection of Digital I/O pins to the on-board
LEDs in the LaunchPad.
-
5
3
5
/('
*UHHQ
-
5
3
5
/('
5HG
*1'
2. USB cable
1.4 Software
The software for the experiment is written in C and developed using the CCS Integrated Develop-
ment Environment (IDE). Refer to “Project Creation and Build” in the Getting Started section of
this manual for project build and debug using CCS. The software is programmed into the target
device MSP430G2553 on the MSP-EXP430G2 LaunchPad using the USB interface.
1.4.1 Flowchart
The flowchart for the code is shown in Figure 1-3. The program code first disables the watchdog
timer to prevent a processor restart on expiry of the WDT count. The port pin P1.0 connected to
the red LED is configured as output. A HIGH on the pin turns the red LED on, while a LOW turns
the LED off. The P1.0 output is toggled using bit XOR function at regular intervals determined by
the software delay set in the program using variable ‘i’. Thus, the red LED on the MSP-EXP430G2
LaunchPad blinks at regular intervals.
START
Disable WDT
Toggle P1.0
Delay
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
while(1) {
volatile unsigned long i; // Volatile to prevent
//optimization
P1OUT ^= 0x01; // Toggle P1.0 using XOR
i = 50000; // SW Delay
do i--;
while(i != 0);
}
}
• WDTCTL: 16-bit Watchdog Timer Control Register - The Watchdog Timer (WDT) is typically
used to trigger a system reset after a certain amount of time. In most examples, the timer is
stopped during the first line of code to prevent a continuous restart loop and for ease of debug-
ging. In our program, the instruction WDTCTL = WDTPW | WDTHOLD sets the password
(WDTPW) and WDTHOLD bit to stop the timer.
7 6 5 4 3 2 1 0
• P1DIR: 8-bit Direction Register - Each bit in the direction register selects the direction of the
corresponding pin as an input or an output. Here, bit 0 is set to "1" directing the Port Pin 1.0 as
an output.
• P1OUT: 8-bit Output Register - Each bit in the output register is the value to be output on the
corresponding I/O pin when the pin is configured as an output. A bit 1 sets the pin HIGH, while
a 0 resets the pin to LOW.
1.5 Procedure
1. Connect the MSP-EXP430G2 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS to view the status of the red
LED.
3. In the CCS debug perspective, select View Registers.
1.6 Observation
While the code is running, pause it. In the Registers tab of CCS, expand and view the registers
P1OUT, P1DIR and WDTCTL. Compare the values with your code. The value of the registers
when the LED is ON appears in the CCS watch window as shown in Figure 1-5.
The value of the registers when the LED is OFF appears in the CCS watch window as shown in
Figure 1-6.
Figure 1-6 Register values in CCS Watch Window for LED Off
1.7 Summary
In this experiment, we have learnt to configure and program the digital I/O pins of MSP430G2553
and have successfully programmed the port P1.0 to blink the on-board green LED of MSP430G2
LaunchPad.
1.8 Exercise
1. Alter the delay with which the LED blinks.
2. Alter the code to make the green LED blink.
3. Alter the code to make the green and red LEDs blink:
i. Together
ii. Alternately
Topics Page
2.1 Objective
The main objective of this experiment is to control the on-board, green LED of MSP430G2
Launchpad by an input from the on-board switch of MSP430G2 Launchpad. This experiment will
help you to learn and understand the procedure for programming the MSP430G2553 GPIO pins
as input and output.
2.2 Introduction
The MSP-EXP430G2 LaunchPad has two general-purpose digital I/O pins connected to green and
red LEDs for visual feedback. It also has two push buttons for user feedback and device reset. In
this experiment, the input from the left push button switch (S2) connected to Port P1.3 is read by
the processor for LED control. If the switch is pressed, the green LED is turned OFF by output at
port P1.6 reset to ’0’. Else, the output at port P1.6 is set HIGH and the green LED is turned ON.
The LED is therefore controlled by the switch S2.
The functional block diagram shown in Figure 2-1 illustrates the working principle of the experi-
ment.
MSP-EXP430G2 MSP-EXP430G2
MSP430G2553
TMC123G MSP430G2553
CPU CPU
S2 S2
ON OFF
P1.3 P1.3
GPIO P1.6 GPIO P1.6
HIGH LOW
LED G LED G
Figure 2-2 shows the Launchpad schematics for the connection of Digital I/O pins to the on-board
LEDs in the LaunchPad.
-
5
3
5
/('
*UHHQ
-
5
3
5
/('
5HG
*1'
The input pins for the MSP430G2553 need to be either pulled-up or pulled-down with a resistor to
avoid floating inputs. The selection of a pull-up or pull down resistor for the inputs is performed in
software. A pull-up resistor enables a default hardware connection for the pin to VCC as shown in
Figure 2-3. Hence, when the switch is open, the VCC (logic HIGH) is available on the input pin of
the MCU.
Vcc
R1 MCU
Input Pin
Button
GND
Figure 2-3 Pull-up Resistor for Input Pin
Vcc
S1
Switch
MCU
R1 4.7k
GND
Figure 2-4 Pull-down Resistor for Input Pin
2. USB cable
2.4 Software
The software for the experiment is written in C and developed using the CCS Integrated Develop-
ment Environment (IDE). Refer to “Project Creation and Build” in the Getting Started section of
this manual for project build and debug using CCS. The software is programmed into the target
device MSP430G2553 on the MSP-EXP430G2 LaunchPad using the USB interface.
2.4.1 Flowchart
The flowchart for the code is shown in Figure 2-5. The program code first disables the watchdog
timer to prevent a restart on expiry of the WDT count. The port pin P1.6 connected to the green
LED is configured as output and port pin P1.3 connected to the left push button switch (SW2) is
configured as input with pull up resistor.
The push button input at P1.3 is read continuously using a while(1) infinite loop. When the push
button switch is open, input at P1.3 will be HIGH because of the pull up resistor, and when the but-
ton is pressed, the switch is closed and the input at pin P1.3 is LOW.
If the push button switch is open, the code turns the green LED ON with a HIGH on output pin
P1.6. Else, if the push button switch is closed, the code turns the green LED OFF with a LOW on
output pin P1.6.
START
Disable WDT
Set P1.6 as Output (LED) and
P1.3 as Input Pullup (Switch)
Button No
Turn ON LED
pressed?
Yes
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= 0x40; // Set P1.6 to output direction
P1REN |= 0x08;
P1OUT |= 0X08;
while(1) {
if ((P1IN & BIT3)) { // If button is open(P1.3 HIGH)
P1OUT = P1OUT | BIT6; // ... turn on LED
} // or P1OUT |= BIT0;
else {
P1OUT = P1OUT & ~BIT6; // ... else turn it off.
// or P1OUT &= ~BIT0
}
}
}
• WDTCTL: 16-bit Watchdog Timer Control Register - The Watchdog Timer (WDT) is typically
used to trigger a system reset after a certain amount of time. In most examples, the timer is
stopped during the first line of code to prevent a continuous restart loop.
• P1DIR: 8-bit Direction Register - Each bit in the direction register selects the direction of the
corresponding pin as an input or an output. Here, bit 6 is set to 1 directing the Port Pin 1.6 as an
output.
• P1REN: Resistor Enable Register - It is used to specify configuration of pull-up or pull-down to
the input pin. Here, bit 3 is set to enable a pull-up resistor on switch input pin P1.3.
• P1OUT: 8-bit Output Register - Each bit in the P1OUT register is the value to be output on the
corresponding I/O pin when the pin is configured as an output, and the pull-up/down resistor is
disabled. A bit 1 sets the pin HIGH, while a 0 resets the pin to LOW. In our program, since the
pull-up resistor is enabled on pin P1.3, the corresponding input pin on the P1OUT register is
set.
2.5 Procedure
1. Connect the MSP-EXP430G2 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS.
2.6 Observation
Initially, the green LED is ON as shown in Figure 2-6. When the left push button switch is pressed,
the green LED turns OFF.
2.7 Summary
In this experiment, we have learnt to configure and program the GPIO pins of MSP430G2553 as
input and output.We have successfully programmed to read input from the on-board switch of
MSP430G2 Launchpad connected to pin P1.3 to blink the on-board green led of MSP430G2
Launchpad connected to pin P1.6.
2.8 Exercise
1. Alter the code to turn the LED ON when the button is pressed and OFF when it is released.
2. Alter the code to make the green LED stay ON for around 1 second every time the button is
pressed.
3. Alter the code to turn the red LED ON when the button is pressed and the green LED ON when
the button is released.
Topics Page
3.1 Objective
The main objective of this experiment is to configure the MSP-EXP430G2 LaunchPad for Low
Power Mode (LPM3) and measure current consumption both in active and low power modes. This
experiment will help in learning the various low power modes of the MSP430G2553.
3.2 Introduction
The MSP430 family is designed for ultra low-power applications. The MSP430G2553 supports
one active mode and five software selectable low-power modes of operation. The operating
modes take into account three different needs:
• Ultra low-power
• Speed and data throughput
• Minimization of individual peripheral current consumption
The low power modes for the MSP430G2553 are configured in the status register. An interrupt
event can wake up the device from any of the low-power modes. It services the request and
restores back to the same low-power mode if the status register is not altered within the interrupt
service routine.
Power consumption of target device is directly related to the clock speed. Hence, the power con-
sumption is reduced by disabling the clock for a particular peripheral as per the application require-
ment. The state of the CPU and clocks for the different low power modes of the MSP430G2553 is
given in Table 3-1.
LPM1 CPU. MCLK disabled. DCO disabled if not used for SMCLK. ACLK active
The power consumption of MSP430G2553 is the maximum in active mode, where CPU clock and
related peripheral clocks are enabled. Stand by current consumption of the MSP430G2553 device
depends upon the particular low power mode as shown in the Figure 3-1.
315 300
270
Vcc = 3V
200
180
135
90
55
45 32
17 11 0.9 0.7 0.1 0.1
0
AM LPM0 LPM2 LPM3 LPM4
Operating Modes
In the current experiment, we are measuring the active current and standby current of the
MSP430G2553 for a given application.
The majority of the power used by the application is spent in the while (1) loop, waiting for an inter-
rupt. We can place the device in a low-power mode during that time and save a considerable
amount of power.
In this experiment, we will turn on interrupts and put the device in LPM3 mode. It is to be noted that
this mode will place restrictions on the resources available during the low-power mode. The CPU,
MCLK, SMCLK and DCO are off in LPM3 mode. Only the ACLK (sourced by the VLO in our code)
is still running. In MSP430G2553, all device pins must be configured to draw the lowest current to
demonstrate low power modes. MSP430G2553 port 1 defaults to GPIO, among them only P1.3 is
configured as an input to support push button switch SW2, and the rest are configured as outputs.
P2.6 and P2.7 default to crystal inputs, so in the current example program, they are configured as
GPIO.
2. USB cable
3. Multimeter
3.4 Software
The software for the experiment is written in C and developed using the CCS Integrated Develop-
ment Environment (IDE). Refer to “Project Creation and Build” in the Getting Started section of
this manual for project build and debug using CCS. The software is programmed into the target
device MSP430G2553 on the MSP-EXP430G2 LaunchPad using the USB interface.
3.4.1 C Program Code for Active and Low Power Operating Modes
Main_active.c:
#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
void FaultRoutine(void);
void ConfigWDT(void);
void ConfigClocks(void);
void ConfigPins(void);
void ConfigADC10(void);
void ConfigTimerA2(void);
void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigPins();
ConfigADC10();
ConfigTimerA2();
_BIS_SR(GIE);
while(1)
{
for (i = 100; i > 0; i--);
for (i = 5000; i > 0; i--); }
}
void ConfigWDT(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
}
void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine(); // If calibration data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG; // Clear OSCFault flag
BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3; // MCLK = DCO/8, SMCLK = DCO/8
}
void FaultRoutine(void)
{
P1OUT = BIT0; // P1.0 on (red LED)
while(1); // TRAP
}
void ConfigPins(void)
{
P1DIR = ~BIT3; // P1.6 and P1.0 outputs
P1OUT = 0;
P2SEL = ~(BIT6 + BIT7);
P2DIR |= BIT6 + BIT7;
P2OUT = 0; // LEDs off
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0; // Temp Sensor ADC10CLK
}
void ConfigTimerA2(void)
{
CCTL0 = CCIE;
CCR0 = 36000;
TACTL = TASSEL_1 + MC_2;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;
_delay_cycles(4); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
P1OUT |= BIT6; // P1.6 on (green LED)
_delay_cycles(100);
ADC10CTL0 &= ~ENC; // Disable ADC conversion
Main_standby.c:
#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
void FaultRoutine(void);
void ConfigWDT(void);
void ConfigClocks(void);
void ConfigPins(void);
void ConfigADC10(void);
void ConfigTimerA2(void);
void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigPins();
ConfigADC10();
ConfigTimerA2();
// _BIS_SR(GIE);
while(1)
{
_bis_SR_register(LPM3_bits + GIE); // Enter LPM3 with interrupts
}
}
void ConfigWDT(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
}
void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine(); // If calibration data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG; // Clear OSCFault flag
BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3; // MCLK = DCO/8, SMCLK = DCO/8
}
void FaultRoutine(void)
{
P1OUT = BIT0; // P1.0 on (red LED)
while(1); // TRAP
}
void ConfigPins(void)
{
P1DIR = ~BIT3; // P1.6 and P1.0 outputs
P1OUT = 0;
P2SEL = ~(BIT6 + BIT7);
P2DIR |= BIT6 + BIT7;
P2OUT = 0; // LEDs off
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0; // Temp Sensor ADC10CLK
}
void ConfigTimerA2(void)
{
CCTL0 = CCIE;
CCR0 = 36000;
TACTL = TASSEL_1 + MC_2;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;
_delay_cycles(4); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
P1OUT |= BIT6; // P1.6 on (green LED)
_delay_cycles(100);
ADC10CTL0 &= ~ENC; // Disable ADC conversion
ADC10CTL0 &= ~(REFON + ADC10ON); // Ref and ADC10 off
tempRaw = ADC10MEM; // Read conversion value
P1OUT &= ~BIT6; // green LED off
CCR0 +=36000; // add 1 second to the timer
_bic_SR_register_on_exit(LPM3_bits); // Clr LPM3 bits from SR on exit
}
3.5 Procedure
The experiment involves two phases:
Initially, connect the MSP-EXP430G2 LaunchPad to the PC using the USB cable supplied.
3.6 Observation
The current consumption in both the active and standby modes is measured while running the
same application code. In Main_standby.c, the processor enters into low power mode LPM3 and
waits for an ADC interrupt. The reading for both the cases for MSP430G2553 are tabulated in
Table 3-3.
3.7 Summary
In this experiment, we have learnt to configure the MSP430G2553 in low power mode (LPM3). We
have found that the current consumption of the processor is reduced in low power modes.
3.8 Exercise
1. How many Low power modes are supported by the MSP430G2553 platform?
2. Measure the Active and Standby Current consumption in LPM3 mode for the same application
using MSP430F5529 LaunchPad.
Topics Page
4.1 Objective
The main objective of this experiment is to configure GPIO and interrupts for the MSP430G2553.
This experiment will help to learn and understand the GPIO and interrupt peripherals and their
operation.
4.2 Introduction
The MSP430G2553 has one active mode and six software selectable low-power modes of opera-
tion. An interrupt event can wake up the device from any of the low-power modes, service the
request, and restore back to the low power mode on return from the interrupt program. And these
Interrupts may be generated from the GPIO of MSP430G2553.
Some GPIOs in the MSP430G2553 have the capability to generate an interrupt and inform the
CPU when a transition has occurred. The MSP430G2553 allows flexibility in configuring which
GPIO will generate the interrupt, and on what edge (rising or falling). MSP430G2553 devices typi-
cally have interrupt capability on Ports 1 and 2.
The registers controlling these options are as follows:
• PxIE - Each bit enables (1) or disables (0) the interrupt for the particular I/O pin.
• PxIES - Selects whether a pin will generate an interrupt on the rising-edge (0) or the falling-
edge (1) of input.
• PxIFG - Interrupt flag register indicating whether an interrupt has occurred on a particular pin (a
transition has occurred on the pin).
4.2.2 Interrupts
There are three types of interrupts:
• System Reset
• Non-Maskable Interrupt (NMI): NMIs are not masked by the General Interrupt Enable bit (GIE)
in the status register but are enabled by individual interrupt enable bits.
• Maskable Interrupt: Maskable interrupts are caused by peripherals with interrupt capability.
Each maskable interrupt can be disabled individually by an interrupt enable bit or all maskable
interrupts can be disabled by the GIE in the status register.
When an interrupt is requested from a peripheral and the peripheral interrupt enable bit and GIE
bit are set, the interrupt service routine is requested. The interrupt service routine involves the fol-
lowing execution steps:
1. Any currently executing instruction is completed.
2. The Program Counter (PC), which points to the next instruction, is pushed onto the stack.
3. The Status Register (SR) is pushed onto the stack.
4. If multiple interrupts occurred during the last instruction and are pending for service, the inter-
rupt with the highest priority is selected.
5. The interrupt request flag resets automatically on single-source flags. Multiple source flags
remain set for servicing by the software.
6. The SR is cleared. This terminates any low-power mode. Because the GIE bit is cleared, further
interrupts are disabled.
7. The content of the interrupt vector is loaded onto the PC. The program continues with the inter-
rupt service routine at that address.
The interrupt handling routine terminates with the instruction RETI (return from an interrupt service
routine)
On return from the interrupt:
1. The SR with all previous settings pops from the stack. All previous settings of GIE, CPUOFF,
etc., are now in effect, regardless of the settings used during the interrupt service routine.
2. The PC pops from the stack and begins execution at the point where it was interrupted.
The current experiment makes complete use of the GPIO interrupts. In this experiment P1.3 is
configured as an input pin with a falling edge interrupt. The general interrupts are enabled so that
the pin will make the CPU to call the Interrupt Service routine. This routine sets a flag that causes
toggling of the green LED which is connected to P1.6 of the MSP_EXP430G2XL Launchpad.The
functional block diagram shown in Figure 4-1 illustrates the working principle of the experiment.
MSP-EXP430G2
MSP430G2553
CPU
P1.6
GPIO HIGH
LED G
P1.3
SW2
2. USB cable
4.4 Software
The software for the experiment is written in C and developed using the CCS Integrated Develop-
ment Environment (IDE). Refer to “Project Creation and Build” in the Getting Started section of
this manual for project build and debug using CCS. The software is programmed into the target
device MSP430G2553 on the MSP-EXP430G2 LaunchPad using the USB interface.
4.4.1 Flowchart
The flowchart for the code is as shown in Figure 4-2. The program code first disables the watch-
dog timer to prevent a restart on expiry of the WDT count. The port pin P1.6 connected to the
green LED on the MSP-EXP430G2 LaunchPad is configured as output. The port pin P1.3 con-
nected to switch S2 on the LaunchPad is configured as GPIO input with falling edge interrupt. The
global interrupt is enabled with low power mode 4 enabled during interrupt. On each interrupt, the
green LED connected to P1.6 is toggled.
START A
B
Yes
Select P1.3 as GPIO
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1 (void)
{
P1OUT ^= BIT6; // Toggle P1.6
P1IFG &= ~BIT3; // P1.3 IFG Cleared
}
• WDTCTL: 16-bit Watchdog Timer Control Register - The Watchdog Timer (WDT) is typically
used to trigger a system reset after a certain amount of time. In most examples, the timer is
stopped during the first line of code to prevent a continuous restart loop.
• P1DIR: 8-bit Direction Register - Each bit in the direction register selects the direction of the
corresponding pin as an input or an output. Here, bit 6 is set to 1 directing the Port Pin 1.6 as an
output.
• P1OUT: 8-bit Output Register - Each bit in the P1OUT register is the value to be output on the
corresponding I/O pin when the pin is configured as an output, and the pull-up/down resistor is
disabled. A bit 1 sets the pin HIGH, while a 0 resets the pin to LOW.
• P1REN: Resistor Enable Register - It is used to specify configuration of pull-up or pull-down to
the input pin. Here, bit 3 is set to enable a pull-up resistor on switch input pin P1.3.
• P1IES: Interrupt Edge Select Register - Each bit of the register selects the interrupt edge for
the corresponding I/O pin. When the bit is set, the PxIFGx flag is set with a high-to-low transi-
tion. Here, the bit is set to interrupt on high to low transition.
• P1IFG: Interrupt Flag Register - Each PxIFGx bit is the interrupt flag for its corresponding I/O
pin and is set when the selected input signal edge transition occurs at the pin.
• P1IE: Interrupt Enable - Each PxIE bit enables the associated PxIFG interrupt flag. Here P1.3
is interrupt enabled.
4.5 Procedure
1. Connect the MSP-EXP430G2 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS.
4.6 Observation
The port pin P1.3 of MSP430G2 Launchpad is configured as an input pin with a falling edge inter-
rupt. On pressing on-board switch S2 of MSP430G2 Launchpad, an interrupt occurs and Interrupt
Service Routine (ISR) blinks the on-board green led of MSP430G2 Launchpad which is connected
to P1.6.
4.7 Summary
In this experiment, we have learnt to configure and program the GPIO pins of MSP430G2553 as
interrupt and have successfully programmed the GPIO port P1.3 as falling edge interrupt to blink
the on-board green led of MSP430G2 Launchpad.
4.8 Exercise
1. Write the code to enable a Timer interrupt for the pin P1.1.
2. Write the code to turn on interrupts globally.
Topics Page
5.1 Objective
The main objective of this experiment is to implement Pulse Width Modulation to control the bright-
ness of the on-board, green LED. This experiment will help you to learn and understand the con-
figuration of PWM and Timer peripherals of the MSP430G2553.
5.2 Introduction
5.2.1 PWM
Pulse Width Modulation (PWM) is a method of digitally encoding analog signal levels. High-resolu-
tion digital counters are used to generate a square wave of a given frequency, and the duty cycle
of the square wave is modulated to encode the analog signal. The duty cycle determines the time
during which the signal pulse is HIGH. For example, Figure 5-1 shows the different waveforms for
varying duty cycles of a signal.
Period
Pulse
Duty Cycle 50% Width
In PWM, a large analog voltage results in increased pulse width and vice versa. Hence, the duty
cycle of the wave changes with the analog voltage that is encoded as shown in Figure 5-2.
The Timer A and Timer B of the MSP430G2553 are capable of PWM outputs in compare mode.
In this experiment, the brightness of the on-board, green LED is altered by varying the voltage on
pin P1.6 which is connected to the green LED. The MSP430G2553 does not have a digital-to-ana-
log (DAC) module; therefore, Pulse Width Modulation is used to achieve this.
The device is kept in low power mode zero till it is woken up by the Timer interrupt. In the Timer
ISR, the brightness of the LED is varied by varying the duty cycle of the signal supplied to the out-
put from the predefined array. The brightness of the LED will be gradually increased as per the
array declared.
The functional block diagram shown in Figure 5-3 illustrates the working principle of the experi-
ment.
MSP-EXP430G2
MSP430G2553
CPU
P1.6
Timer A
PWM
LED G
2. USB cable
5.4 Software
The software for the experiment is written in C and developed using the CCS Integrated Develop-
ment Environment (IDE). Refer to “Project Creation and Build” in the Getting Started section of
this manual for project build and debug using CCS. The software is programmed into the target
device MSP430G2553 on the MSP-EXP430G2 LaunchPad using the USB interface.
5.4.1 Flowchart
The flowchart for the code is shown in Figure 5-4.The program code first disables the watchdog
timer to prevent a restart on expiry of the WDT count. The port pin P1.6 connected to the green
LED is configured as PWM output of Timer A. The Timer A is configured with the required period
(TA0CCR0) and the PWM duty cycle (TA0CCR1) is set to first value in the predefined array. The
Timer is configured in Set/Reset output mode 7. The Timer A control register is set to use SMCLK
as clock source for up counting. The global interrupt is enabled, and the processor is switched to
low power mode 0 (LPM0).
On interrupt by the Timer, the PWM duty cycle (TA0CCR1) is set to the next value from the pre-
defined array. An increase in PWM duty cycle increases the brightness of the LED connected to its
output. On reaching the last element of the array, maximum brightness is reached and the duty
cycle is reset to the first value in the array.
A
START
Interrupt No
B B
occurred?
Stop Watchdog Timer
Yes
i=0
A
B
• WDTCTL: 16-bit Watchdog Timer Control Register - The Watchdog Timer (WDT) is typically
used to trigger a system reset after a certain amount of time. The register is set to WDT_MD-
LY_32 for 32ms interval interrupt.
• IE1: Interrupt Enable Register 1 - This register enables the NMI interrupts and WDT interrupt.
Here, the Watchdog timer interrupt is enabled.
• P1DIR: 8-bit Direction Register - Each bit in the direction register selects the direction of the
corresponding pin as an input or an output. Here, bit 6 is set to 1 directing the Port Pin 1.6 as
an output.
• P1SEL: Function Select Register - Each bit in the function select register is used to select the
pin function - I/O port or peripheral module function. Here, the pin used as PWM output(P1.6) is
specified.
• TA0CTL: Timer A Control Register - Each bit in this register configures Timer A operation.
Here, SMCLK is used as clock source and the count up mode (MC_1) is selected for timer con-
figuration.
• TA0CCR0: Timer A Capture/Compare Register - It holds the data for comparison to the timer
value in compare mode. Here, the PWM period is set using this register.
• TA0CCR1: Timer A Capture/Compare Register - It holds the data for comparison to the timer
value in compare mode. Here, this register set is used to the PWM duty cycle. This value will be
equal to the reading taken from the potentiometer at any time instant and will alter the LED’s
brightness.
• TA0CCTL1: Timer A Capture/Compare Control Register - The Timer capture/compare regis-
ter configures the capture/compare modes of the timer. Here, the PWM output mode is set to
PWM Reset/Set mode (OUTMODE_7).
5.5 Procedure
1. Connect the MSP-EXP430G2 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS.
5.6 Observation
The green LED on our LaunchPad board starts off glowing very dimly and gradually gets brighter
till it reaches a maximum. It then, goes back to its minimum brightness and the process repeats.
We can suspend and resume the running code at different instances to view the value of our duty
cycle for different brightness levels.
The register values for three different cases of the duty cycle are tabulated in Table 5-2.
Figure 5-6 shows the register values displayed in CCS watch window.
Figure 5-6 Register Values in CCS Watch Window for Duty Cycle Calculation
5.7 Summary
In this experiment we have learnt to configure and program the GPIO pins as PWM pins of
MSP430G2553 and have successfully programmed the GPIO port P1.6 as PWM pin to blink the
on-board green led of MSP430G2 Launchpad.
5.8 Exercise
1. Observe the PWM waveform on a particular pin using CRO.
2. What is the maximum resolution of PWM circuitry in MSP430G2 LaunchPad?
3. Change the above code to create a PWM signal of 75% duty cycle on particular PWM pin.
Topics Page
6.1 Objective
The main objective of this experiment is to control the on-board, red LED by the analog input from
a potentiometer. This experiment will help you to learn and understand how to configure an ADC to
interface with a potentiometer.
6.2 Introduction
The MSP430G2553 consists of ADC10, 10-bit analog-to-digital converter which converts the ana-
log input into a maximum of 1024 discrete levels. The ADC10 module is capable of 8 external
inputs and 4 internal analog sources. The ADC10 can be configured to convert a single channel or
a block of contiguous channels and can optionally repeat its conversions automatically. Each con-
version takes multiple cycles. The timing is controlled by an ADC clock. While a conversion is in
progress, the busy flag set. After conversion, the result is stored in the ADC10MEM register. There
is a possible interrupt signaled when a conversion is complete. There is also a data transfer con-
troller that can steal cycles from the CPU and store a block of conversion results directly in mem-
ory.
The block diagram for the experiment is as shown in Figure 6-1. In this experiment, the analog
input is provided by the potentiometer on analog channel A3 which is the same pin as P1.3. The
resistance of the potentiometer is varied by turning its knob, thereby resulting in a varying analog
voltage on A3.
This voltage is converted into 1024 discrete levels from 0V to 3V DC (since the Vref is set to Vcc).
The red LED turns on when the voltage crosses the threshold of Vcc/2 (or the digital level 512).
063(;3* 063(;3*
D^WϰϯϬ'Ϯϱϱϯ D^WϰϯϬ'Ϯϱϱϯ
0HPRU\
0HPRU\
Wh $'&0(0
Wh $'&0(0
!
21
2))
3 3
$'& *3,2 $'&
WŽƚĞŶƚŝŽŵĞƚĞƌ *3,2
/('5
WŽƚĞŶƚŝŽŵĞƚĞƌ
/('5
3 $ 3 $
1. MSP430G2 MSP-EXP430G2XL
LaunchPad
2. USB cable
6.4 Software
The software for the experiment is written in C and developed using the CCS Integrated Develop-
ment Environment (IDE). Refer to “Project Creation and Build” in the Getting Started section of
this manual for project build and debug using CCS. The software is programmed into the target
device MSP430G2553 on the MSP-EXP430G2 LaunchPad using the USB interface.
6.4.1 Flowchart
The flowchart for the code is as shown in Figure 6-2. The program code first disables the watch-
dog timer to prevent a restart on expiry of the WDT count. The GPIO port pin P1.0 connected to
the red LED is configured as output. ADC10 is configured by two control registers, ADC10CTL0
and ADC10CTL1 with reference voltage as Vcc and input channel as A3 connected to pin P1.3.
The ADC converter is enabled, to start sampling and conversion of analog input. If the converted
value is greater than 512, the red LED is turned ON. Else, it is turned OFF.
START
Disable WDT
Set P1.0 as output (Red LED)
Configure ADC10
Select Channel A3 as output
Analog
Reading No
Turn OFF LED
>
512
Yes
Turn ON LED
while(1)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
• WDTCTL: 16-bit Watchdog Timer Control Register - The Watchdog Timer (WDT) is typically
used to trigger a system reset after a certain amount of time. The register is set to WDT_MD-
LY_32 for 32ms interval interrupt.
• ADC10CTL0:ADC10 Control Register 0 - The ADC10 core is configured by the ADC10CTL0
and ADC10CTL1 registers.
• ADC10CTL1:ADC10 Control Register 1 - The ADC10 core is configured by the ADC10CTL0
and ADC10CTL1 registers.
• ADC10AE: Analog (Input) Enable Control Register 0 - The bits of this register enable the
corresponding pin for analog input.
• P1DIR: 8-bit Direction Register - Each bit in the direction register selects the direction of the
corresponding pin as an input or an output. Here, bit 0 is set to 1 directing the Port Pin 1.0 as
an output.
• ADC10MEM: Conversion Memory Register - The 10-bit conversion results are stored in this
register.
The various configuration parameters related to the various registers of the ADC10 used in the
current program are tabulated in Table 6-2.
Start Conversion ADC10SC ADC10CTL0, bit 0 Start conversion (writing a 1 starts sam-
pling and conversion), returns to 0 auto-
matically.
Analog Enable ADC10AE0 Bit flags. A set bit enables the corre-
sponding analog input.
Reference Genera- REFON, ADC10CTL0 bits Enable optional internal reference volt-
tor REF2_5V 5,6 age
of either 1.5 or 2.5V
Sample and hold ADC10SHT ADC10CTL0 bits Time used for sample and hold.
time 12-11 Depends on circuit time constants (see
data sheet).
Default is 4 ADC clock cycles
6.5 Procedure
1. Connect the MSP-EXP430G2 LaunchPad to the PC using the USB cable supplied.
2. Connect the positive lead of the potentiometer to the Vcc pin on the MSP-EXP430G2 Launch-
Pad and the negative lead of the potentiometer to the GND pin.
3. Connect the output lead of the potentiometer to pin P1.3 or Analog Channel A3.
4. Connect the jumpers on the MSP-EXP430G2 LaunchPad for RXD and TXD horizontally.
The setup appears as shown in Figure 6-3.
9&& *1'
.ȍ3RWHQWLRPHWHU
5. Build, program and debug the code into the LaunchPad using CCS.
6. Vary the potentiometer and observe the on board red LED.
6.6 Observation
The LED is initially OFF, when the resistance is at its maximum. As we turn the potentiometer, the
LED turns ON after a certain point. This point is the ADC voltage level of 512.
The potentiometer reading can be viewed by watching the ADC10MEM register on CCS Debug
Perspective as shown in Figure 6-4.
6.7 Summary
In this experiment, we have learnt to configure and program the ADC to control the red LED based
on the analog input from the potentiometer.
6.8 Exercise
1. Alter the threshold to 75% of Vcc for the LED to turn on.
2. Modify the code to change the Reference Voltage from Vcc to 2.5V.
Topics Page
7.1 Objective
The main objective of this experiment is to control the speed of a DC Motor using the potentiome-
ter. This experiment will help to learn and understand how to configure the PWM and ADC mod-
ules of the processor to control the DC motor using potentiometer input.
7.2 Introduction
Period
Pulse
Duty Cycle 50% Width
A large analog voltage results in increased pulse width and vice versa. Hence, the duty cycle of
the wave changes with the analog voltage that is encoded as shown in Figure 7-2.
The Timer A and Timer B of the MSP430G2553 are capable of PWM outputs in compare mode.
• CPU is disabled
• ACLK and SMCLK remain active, MCLK is disabled
The block diagram for this experiment is shown in Figure 7-3. In this experiment, the analog signal
from potentiometer connected to P1.3 is read by the ADC10, and the converted digital value is
used to vary the duty cycle of the PWM output. The PWM output in turn controls the speed of the
DC motor which is connected to PWM pin P1.6. The PWM period is set to 1024 in the Timer A cap-
ture/compare register 0 (TA0CCR0). The digital value after conversion is stored in ADC10MEM
which is passed to the TA0CCR1 register to set the PWM duty cycle. This value can vary from 0 to
1024 based on the position of the potentiometer. The timer interrupt is set to sample and convert
the analog input to digital output. The device is kept in low power mode, until it is woken up by the
interrupt.
MSP-EXP430G2
MSP430G2553
Memory
CPU (ADC10MEM)
P1.6
Potentiometer ADC Timer A ULN2003 Motor
PWM
P1.3
2. USB cable
4. DC Motor
7.4 Software
The software for the experiment is written in C and developed using the CCS Integrated Develop-
ment Environment (IDE). Refer to “Project Creation and Build” in the Getting Started section of
this manual for project build and debug using CCS. The software is programmed into the target
device MSP430G2553 on the MSP-EXP430G2 LaunchPad using the USB interface.
7.4.1 Flowchart
The flowchart for the code is shown in Figure 7-4. The program code first disables the watchdog
timer to prevent a restart on expiry of the WDT count. The ADC10 core is configured by two control
registers, ADC10CTL0 and ADC10CTL1 with reference voltage as Vcc and input channel as A3
connected to pin P1.3.
The port pin P1.6 connected to the DC motor is configured as PWM output of Timer A that is con-
figured in Set/Reset output mode 7 with period 1024 (TA0CCR0) and required PWM duty cycle
(TA0CCR1). Initially, the PWM duty cycle is set to 0.1%. Timer A control is set to use SMCLK as
clock source for up counting. The global interrupt is enabled, and the processor is switched to low
power mode 0.
On interrupt by the Timer, the ADC converter is enabled and sampling and conversion of analog
input is started. The ADC converted value stored in ADC10MEM is copied to TA0CCR1 to set the
PWM duty cycle for the output to the DC motor.
Timer
START Interrupt
TA0CCR1 = ADC10MEM
Set P1.6 to PWM output
Configure Timer 0 for PWM
Return from Interrupt
Figure 7-4 Flowchart for PWM Based Speed Control of Motor by Potentiometer
int pwmDirection = 1;
void main(void){
WDTCTL = WDTPW|WDTHOLD; // Stop WDT
ADC10CTL0 = SREF_0 + ADC10SHT_2 + ADC10ON;
ADC10CTL1 = INCH_3; // input A3
ADC10AE0 |= 0x08; // PA.3 ADC option select
P1DIR |= BIT6; // Green LED for output
P1SEL |= BIT6; // Green LED Pulse width modulation
TA0CCR0 = 1024; // PWM period
TA0CCR1 = 1; // PWM duty cycle,on 1/1000 initially
TA0CCTL1 = OUTMOD_7; // TA0CCR1 reset/set-high voltage
// below count,low voltage when past
TA0CTL = TASSEL_2 + MC_1 + TAIE +ID_3;
• WDTCTL: 16-bit Watchdog Timer Control Register - The Watchdog Timer (WDT) is typically
used to trigger a system reset after a certain amount of time. The register is set to WDT_MD-
LY_32 for 32ms interval interrupt.
• IE1: Interrupt Enable Register 1 - This register enables the NMI interrupts and WDT interrupt.
Here, the Watchdog timer interrupt is enabled.
• P1DIR: 8-bit Direction Register - Each bit in the direction register selects the direction of the
corresponding pin as an input or an output. Here, bit 6 is set to 1 directing the Port Pin 1.6 as
an output.
• P1SEL: Function Select Register - Each bit in the function select register is used to select the
pin function - I/O port or peripheral module function. Here, the pin used as PWM output(P1.6) is
specified.
• TA0CTL: Timer A Control Register - Each bit in this register configures Timer A operation.
Here, SMCLK is used as clock source and the count up mode (MC_1) is selected for timer con-
figuration.
• TA0CCR0: Timer A Capture/Compare Register - It holds the data for comparison to the timer
value in compare mode. Here, the PWM period is set using this register.
• TA0CCR1: Timer A Capture/Compare Register - It holds the data for comparison to the timer
value in compare mode. Here, this register set is used to the PWM duty cycle. This value will be
varied to alter the LED’s brightness.
• TA0CCTL1: Timer A Capture/Compare Control Register - The Timer capture/compare regis-
ter configures the capture/compare modes of the timer. Here, the PWM output mode is set to
PWM Reset/Set mode (OUTMODE_7).
• ADC10AE: Analog (Input) Enable Control Register 0 - The bits of this register enable the
corresponding pin for analog input. Here, input channel A3 is enabled.
• ADC10CTL0:ADC10 Control Register 0 - The ADC10 core is configured by the ADC10CTL0
and ADC10CTL1 registers. The voltage reference, sample and hold times are configured in this
register.
• ADC10CTL1:ADC10 Control Register 1 - The ADC10 core is configured by the ADC10CTL0
and ADC10CTL1 registers. Here, input channel A3 is enabled.
• ADC10MEM: Conversion Memory Register - The 10-bit conversion results are stored in this
register. The value in this register is used to set the duty cycle value for PWM output of Timer
A.
7.5 Procedure
U1 ULN2003
IN1 1 16 OUT1
GND
IN2 OUT2
IN3 OUT3 DC
IN4 OUT4 MOTOR
M
IN5 OUT5 +5V
IN6 OUT6
IN7 OUT7
GND 8
9 COM
GND
IN1 OUT1
1 16
IC
J1 VCC 3.3V ULN20
03
GND COM
8 9
J1
J2
P1.3 P1.6 5V DC
GND Signal
GND
10KΩ DC
Potentiometer Motor
7.6 Observation
We see the speed of the DC motor varies as we change the position of the potentiometer knob.
If we suspend the program and simultaneously watch the registers ADC10MEM and TA0CCR1,
we will find their values to be identical, as desired.
To watch specific registers, right-click on those registers in the Registers tab and select the Watch
option. The watch window shows the values of the registers as shown in Figure 7-6.
7.7 Summary
In this experiment, we have learnt to configure and program the ADC to control the speed of the
DC motor based on the analog input from the potentiometer.
7.8 Exercise
1. Interface a Stepper motor with MSP-EXP430G2 LaunchPad to run it in a predetermined uniform
speed.
2. Describe the applications of PWM in a digital power supply control.
3. Create Switch case code from the example code to run the DC Motor in 3 set of speeds.
Topics Page
8.1 Objective
The main objective of this experiment is to optimize the power efficiency of an application on MSP-
EXP430G2 LaunchPad using ULP Advisor in CCS Studio. This experiment will help to learn and
understand the ULP Advisor capabilities and usage of ULP Advisor to create optimized, power-effi-
cient applications on the MSP-EXP430G2 LaunchPad.
8.2 Introduction
(ULP 1.1) Detected no uses of low-power mode state changes using LPMx
or _bis_SR_register( ) or __low_power_mode_x( ) in this project
This experiment explains in detail how to use ULP Advisor on MSP430G2553. Three code files are
used in this experiment and one file is included in the build at a time. Each file performs the same
function: every second an Analog-to-Digital Converter (ADC) temperature measurement is taken,
the degrees Celsius and Fahrenheit are calculated, and the results are sent through the back
channel Universal Asynchronous Receiver/Transmitter (UART) at 9600bps.
The first code file - Inefficient.c, begins with an inefficient implementation of this application. The
ULP Advisor is used to observe the extreme inefficiency of this version. Based on the feedback
from the ULP Advisor, improvements are made for the somewhat efficient second version of the
code - Efficient.c. The process is repeated, and ULP Advisor is used to compare this improved ver-
sion with the original. Finally, steps are taken to improve the code even further in the very efficient
third version of the code - MostEfficient.c.
Table 8-2 briefs the descriptions of the experiment code.
*The codes above are written for MSP430FR5969 LaunchPad. ULP Advisor tool helps us in eval-
uating the code for optimizing power and energy before debugging and is a feature of CCS.
2. USB cable
8.4 Software
This experiment uses the ULP_Case_Study example in the CCS Integrated Development Envi-
ronment (IDE). Refer to “Project Creation and Build” in the Getting Started section of this manual
for project build and debug using CCS.
8.5 Procedure
1. Connect the MSP-EXP430G2 LaunchPad to the PC using the USB cable supplied.
2. Download the CCS example project ULP_Case_Study from http://www.ti.com/lit/zip/slaa603
and extract using 7zip.
3. Import the project into your CCS workspace as shown in Figure 8-1.
a. Click Project Import Existing CCS Eclipse Project.
b. Browse the directory for the downloaded file.
c. Check the box next to the ULP_Case_Study project in the Discovered projects window.
d. Uncheck the check box Copy projects into workspace.
e. Click Finish.
4. To set as active project, click on the project name. The active build configuration should be Inef-
ficient. If not, right click on the project name in the Project Explorer, then click Build Configura-
tions Set Active Inefficient as shown in Figure 8-2.
6. The Advice window shows suggestions from the ULP Advisor under the Power (ULP) Advice
heading. Click View Advice as shown in Figure 8-3.
7. Click the link #1532-D, which corresponds to the first ULP violation (for using sprintf()), to open
the ULP Advisor wiki page in a second Advice tab. All the information for this particular rule viola-
tion is provided as shown in Figure 8-5.
8. Scroll down to the Remedy section. Here, the first suggestion is to avoid using sprintf() alto-
gether and work with the raw data.
8.6 Observation
In the ULP Advisor of Inefficient.c, the first suggestion given is to avoid using sprintf(). The ULP
Advisor implements the advice for the next version of code i,e., Efficient.c as shown in Figure 8-6.
There are no advices related to Power optimization in ULP Advisor of MostEfficient.c, as shown in
Figure 8-7 below.
8.7 Summary
In this experiment we have learnt to optimize the power efficiency of an application on MSP-
EXP430G2 LaunchPad using ULP Advisor in CCS Studio.
8.8 Exercise
1. How does the ULP Advisor software help in designing power optimized code?
2. Which ULP rule violation helps us to detect a loop counting violation?
Topics Page
83 Serial Communication
www.ti.com Objective
9.1 Objective
The main objective of this experiment is to use UART of the MSP430G2553 to communicate with
the computer. This experiment will help to learn and understand the configuration of Universal
Serial Communication Interface (USCI) module of MSP430G2553 for UART based serial commu-
nication.
9.2 Introduction
Serial communication can be divided into two categories:
Synchronous serial communication uses a dedicated communication channel to send a clock sig-
nal which provides the timing between the transmitter and receiver. While in asynchronous com-
munication, the timing is encoded within the signal. There are several versions of both
synchronous and asynchronous serial communication. The MSP430G2553 supports 3 different
types of communications using its USCI peripheral: Serial Peripheral Interface (SPI), Inter-Inte-
grated Circuit Interface (I2C) and UART.
The MSP430G2553 is an ultra-low power device and has one active mode and five software
selectable low-power modes of operation. An interrupt event can wake up the device from any of
the low-power modes, service the request, and restore back to the low-power mode on return from
the interrupt program.
In UART mode, the USCI transmits and receives characters at a bit rate asynchronous to the
paired device. Timing for the transmission of each character is based on the selected baud rate of
the USCI. The transmit and receive functions use the same baud rate frequency.
The block diagram for the experiment is as shown in Figure 9-1. The UART baud rate is set to
9600. The UART specifies two pins, a TX pin (located at P1.2) and an RX pin (P1.1) for communi-
cation. The USCI-UART module is configured to transmit a preset message on an interrupt. An
interrupt provided within the program code transmits the message to be displayed on the UART
terminal of the computer.
063(;3*
D^WϰϯϬ'Ϯϱϱϯ
60&/.
&/.6RXUFH
&38 86%
&RQQHFWRU
3
86&,8$57
3
3HUVRQDO&RPSXWHU
Figure 9-1 Functional Block Diagram
84 Serial Communication
Component Requirements www.ti.com
In our program, we configure our device to stay in Low power mode 1 (LPM1) for power optimiza-
tion until it is woken up by the interrupt. The features of Low power mode 1 (LPM1):
• CPU is disabled
• ACLK and SMCLK remain active, MCLK is disabled
• DCO's DC generator is disabled if DCO not used in active mode
2. USB cable
9.4 Software
The software for the experiment is written in C and developed using the CCS Integrated Develop-
ment Environment (IDE). Refer to “Project Creation and Build” in the Getting Started section of
this manual for project build and debug using CCS. The software is programmed into the target
device MSP430G2553 on the MSP-EXP430G2 LaunchPad using the USB interface.
2. When the terminal window opens, click on the Settings icon and set the values as shown in
Figure 9-2.
Serial Communication 85
www.ti.com Softwarei
This Terminal will allow you to view the serial information received by the computer and will also
allow you to type in the information that you wish to transmit to the MSP430G2553 via the UART.
9.4.2 Flowchart
The flowchart for the code is shown in Figure 9-3. The program code first disables the watch dog
timer to prevent a restart on expiry of the WDT count. The port pins P1.1 and P1.2 are configured
as Rx and Tx of UART respectively. The USCI SMCLK is selected as clock source, and the clock
prescaler value in the baud rate control register is set to 104 to have 1MHz frequency and baud
rate of 9600. The USCI-UART module is initialized, and the transmit interrupt is enabled. The
global interrupt is enabled, and the processor is switched to low power mode 0.
The transmission of the received character is carried out using the USCI0RX interrupt. Interrupt
vector addresses and further details about the various involved registers can be found in the Data-
sheet.
The interrupt service routine is defined as follows:
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
86 Serial Communication
Software www.ti.com
The interrupt service routine for serial transmission transmits the received character from the key-
board which is stored in the receiver buffer UCA0RXBUF to the transmitter buffer UCA0TXBUF.
UCA0TXBUF=UCA0RXBUF
Serial Communication 87
www.ti.com Procedure
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF;
}
• WDTCTL: 16-bit Watchdog Timer Control Register - The Watchdog Timer (WDT) is typically
used to trigger a system reset after a certain amount of time. The register is set to WDT_MD-
LY_32 for 32ms interval interrupt.
• IE2: Interrupt Enable Register 2 - This register enables the USCI transmit and receive inter-
rupts.Here, the USCI interrupts are enabled.
• P1SEL1 and P1SEL2: Function Select Register - Each bit in the function select register is
used to select the pin function - I/O port or peripheral module function. Here, the UART function
on Pins P1.1 and P1.2 are enabled.
• UCA0CTL0: USCI_A0 Control Register 0 - This register configures the USCI module. Here
the configuration is: No parity, LSB first, 8-bit data, 1 stop bit, UART, Asynchronous.
• UCA0CTL1: USCI_A0 Control Register 1 - This register is used to configure clock source and
enable software interrupts. Here, SMCLK is used as clock source.
• UCA0BR0 & UCA0BR1: USCI_A0 Baud Rate Control Register 0 and 1 - These 16-bit regis-
ters are configured the clock prescaler setting of the baud rate generator. Here, the registers
are configured to have 1MHz frequency and 9600 baud rate.
• UCA0MCTL: USCI_A0 Modulation Control Register - This register selects the modulation
stages which determine the modulation pattern for BITCLK. Here, the 2nd Stage modulation =
1, and oversampling is turned off.
• IFG2: Interrupt Flag Register 2 - This register consists of the transmit and receive interrupt
flags. Here, the flags are cleared.
9.5 Procedure
1. Connect the MSP-EXP430G2 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS.
88 Serial Communication
Observation www.ti.com
9.6 Observation
After compiling and running the program the Serial Terminal displays - Echo Output:. As the char-
acters are typed in, they will be displayed on the terminal. The input entered from the keyboard is
echoed back and shown on the terminal window. The keyboard entries in Tera Term are generally
streamed only to the serial port and not to the display. Only the characters received via the serial
port are displayed on this window. To confirm this, hold the RESET key after terminating debug
session on the MSP430G2 Launchpad and try typing the input string. You will observe no display
of the characters typed. We can thus infer that the program in the MSP-EXP430G2 LaunchPad is
doing the echo operation.
On running the program you will be able to view a continuous loop of messages on the UART dis-
play as shown in Figure 9-4.
Suspend the code and view the various USCI-UART registers.The watch window appears as
shown in Figure 9-5.
Serial Communication 89
www.ti.com Summaryi
9.7 Summary
In this experiment, we have learnt to use UART to communicate with the computer.
9.8 Exercise
1. Modify the above code to transmit the set of strings to the serial terminal via UART as shown
below:
char str1[]="MSP430G2 launchpad"
char str2[]= "Ultra low power mixed signal processing applications"
90 Serial Communication
Experiment 10
Master Slave Communication Using SPI
Topics Page
10.1 Objective
The main objective of this experiment is to establish the SPI master-slave communication using 3-
wire mode in MSP430F5529 Launchpad. This experiment will help understand the configuration of
USCI_A0 SPI 3-Wire Master Incremented Data in MSP430F5529.
10.2 Introduction
• UART mode
• Pulse shaping for IrDA communications
• Automatic baud rate detection for LIN communications
• Synchronous SPI mode
• I2C mode
• Synchronous SPI (Serial Peripheral Interface) mode
In synchronous SPI mode, the USCI connects the MSP430F5529 to an external system via three
or four pins as shown in Figure 10-1.
SCLK
MOSI
SPI SPI
Master MISO Slave
SSN
SPI mode is selected when the UCSYNC bit is set and SPI mode (3-pin or 4-pin) is selected with
the UCMODEx bits.
The features of MSP430F5529 SPI are:
The block diagram for the experiment is as shown in Figure 10-2. In this experiment the SPI mas-
ter talks to SPI slave using 3-wire mode. The USCI_A0 module is configured as a SPI interface.
Master sends the data starting at 0x01 to the slave mode. The slave will receive the data which is
expected to be same as the previous data transmission.
In the master, USCI_RX ISR is used to handle communication with the CPU, normally in LPM0. In
the slave, USCI_ RX ISR is used to handle communication with the CPU, normally in LPM4.
MSP-EXP430F5529LP MSP-EXP430F5529LP
Master Slave
MSP430F5529 MSP430F5529
CPU CPU
SPI
USCI_A0 USCI_A0
MASTER SLAVE
UCA0SIMO
Data Out P3.3 P3.3 Data Out
UCA0SOMI P3.4 Data In
Data In P3.4
Serial clk
P2.7 P2.7 Serial clk out
out
P1.1 RST
1. 2 MSP430F5529 MSP-EXP430F5529LP
LaunchPads
2. USB cable
10.4 Software
The software for the experiment is written in C and developed using the CCS Integrated Develop-
ment Environment (IDE). Refer to “Project Creation and Build” in the Getting Started section of
this manual for project build and debug using CCS. The software is programmed into the target
device MSP430F5529 on the MSP-EXP430F5529 using the USB interface.
10.4.1 Flowchart
Master:
The flowchart for the code of the master is shown in Figure 10-4. The program code first disables
the watch dog timer to prevent a processor restart on expiry of the WDT count. The port pin P1.1 is
set as slave reset and port pin P1.0 is configured for the red LED. The port pins P3.3, P3.4 and
P2.7 are configured for SPI communication. The USCI logic is held in reset state and the 3-pin, 8-
bit synchronous SPI master is enabled. The SMCLK is selected as clock source and the USCI
logic initiated. The USCI_RX interrupt is enabled in low power mode and the slave is reset via out-
put pin P1.1 and allowed to initialize. The data values to be transmitted to the slave is also initial-
ized and transmitted via the transmit buffer UCA0TXBUF. On receiving data from the slave, the
USCI_RX interrupt occurs. If the data received is same as the data transmitted, the red LED is
turned on and the data transmission is continued.
START A C
B
USCA0TXB No
Ready? If
No
Set P1.0 - 2 to Output USCIA0TXBUF LED OFF
direction ==SLV_DATA
Yes
B
Select the USCI clock as SMCLK
Initialize the USCI state machine END
Slave:
The flow chart for the code of the slave is shown in Figure 10-5. The program code first disables
the watch dog timer to prevent a processor restart on expiry of the WDT count. Since, the connec-
tion is synchronous, the slave receives the clock source from the master on port pin P2.7. If a
clock signal is detected from the master, the port pins P3.3, P3.4 and P2.7 are configured for SPI
communication and the USCI logic is held in reset state. The 3-pin, 8-bit synchronous SPI master
is then enabled. The USCI logic is initiated and the USCI Rx interrupt is enabled in low power
mode 4. When the slave receives data from the master, the USCI Rx interrupt occurs. The
received data is copied into the transmit buffer UCA0TXBUF for echo transmission to the master.
B
START
A
Is No Yes
clock sig
from Copy RX buffer value to
Master high? USCI_A0 TX buffer
Yes
END
P3.3, 4 option select
P2.7 option select
A
Figure 10-5 Flowchart for the Code of Slave
int main(void)
{
volatile unsigned int i;
#else
#error Compiler not supported!
#endif
{
volatile unsigned int i;
switch(__even_in_range(UCA0IV,4))
{
case 0: break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
int main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
// Echo character
{
switch(__even_in_range(UCA0IV,4))
{
case 0:break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF;
break;
case 4:break; // Vector 4 - TXIFG
default: break;
}
}
• WDTCTL: 16-bit Watchdog Timer Control Register - The Watchdog Timer (WDT) is typically
used to trigger a system reset after a certain amount of time. The register is set to WDT_MD-
LY_32 for 32ms interval interrupt.
• P3SEL and P2SEL: Function Select Register - Each bit in the function select register is used
to select the pin function - I/O port or peripheral module function. Here, the pins P3.3, P3.4 and
P2.7 are configured for SPI communication.
• UCA0CTL0: USCI_A0 Control Register 0 - This register configures the USCI module. Here
the master and slave are configured for 3-bit synchronous SPI.
• UCA0CTL1: USCI_A0 Control Register 1 - This register is used to configure clock source and
enable software interrupts. The master uses SMCLK as clock source.
• UCA0BR0 & UCA0BR1: USCI_A0 Baud Rate Control Register 0 and 1 - These 16-bit regis-
ters configure the clock prescaler setting of the bit rate. In the master, the registers are config-
ured to have clock prescaler of 2.
• UCA0IE: USCI_A0 Interrupt Enable Register - This register enables the USCI transmit and
receive interrupts.Here, the USC RxI interrupt is enabled.
• UCA0TXBUF: USCI Transmit Buffer Register - This register contains the data to be transmit-
ted by the USCI module.
• UCA0RXBUF: USCI Receive Buffer Register - This register contains the data received by the
USCI module.
• UCA0IFG: USCI_A0 Interrupt Flag Register - This flag is set when UCA0TXBUF is empty.
The various configuration parameters related to the various registers of the USCI_A0 used in the
current program are summarized in Table 10-2.
Controls the direction of UCMSB UCA0CTL0, bit 5 1 - The inactive state is high
the receive and trans-
0 - LSB first
mit shift register
1 - MSB first
10.5 Procedure
1. Connect the MSP430 LaunchPads to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS.
10.6 Observation
A successful SPI communication has been established between 2 MSP430 devices. This fact is
verified by the blinking red LED in the master after receiving the exact echo data from the slave
that the master had previously transmitted.
10.7 Summary
In this experiment, we have learnt to use the SPI communication to establish a connection
between two MSP430 devices. We have also learnt to configure the USCI_A0 SPI 3-Wire Master
Incremented Data in MSP430F5529.
10.8 Exercise
1. Which port pins of MSP430 can be configured for SPI communication?
2. What is the data transfer rate supported by MSP430 for SPI communication?
Topics Page
11.1 Objective
The main objective of this experiment is to configure CC3100 Booster Pack as a Wireless Local
Area Network (WLAN) Station to send Email over SMTP. This experiment will help you understand
the WLAN concepts and CC3100 configuration to send Email over SMTP.
11.2 Introduction
A wireless local area network (WLAN) is a wireless computer network that connects two or more
devices without wires within a confined area, for example: within a building. This stay connected
without physical wiring constraints and also access Internet. WiFi is based on IEEE 802.11 stan-
dards including IEEE 802.11a and IEEE802.11b.
All nodes that connect over a wireless network are referred to as stations (STA). Wireless stations
can be categorized into Wireless Access Points (AP) or clients. Access Points (AP) work as the
base station for a wireless network. The Wireless clients could be any device such as computers,
laptops, mobile devices, smart phones, etc.
The Simplelink WIFI CC3100 device is the industry's first Wi-Fi Certified chip used in the wireless
networking solution that simplifies the implementation of Internet connectivity. This device supports
WPA2 personal and enterprise security and WPS 2.0 and Embedded TCP/IP and TLS/SSL
stacks, HTTP server, and multiple Internet protocols. The functional block diagram for the CC3100
is shown in Figure 11-1.
Vcc
32 kHz
nHIB
CC3100
MCU
Network Processor
HOST_INTR
SPI / UART
The software overview of the Simplelink WiFi CC3100 is shown in Figure 11-2. The SimpleLink
Host Driver includes a set of six simple Application Program Interface (API) modules:
• Device API – Manages hardware-related functionality such as start, stop, set, and get device
configurations.
• WLAN API – Manages WLAN, 802.11 protocol-related functionality such as device mode (sta-
tion, AP, or P2P), setting provisioning method, adding connection profiles, and setting connec-
tion policy.
• Socket API – The most common API set for user applications, and adheres to BSD socket APIs.
• NetApp API – Enables different networking services including the Hypertext Transfer Protocol
(HTTP) server service, DHCP server service, and MDNS client\server service.
User Application
SimpleLink Driver
SPI or UART Driver
External Microcontroller
Internet Protocols
TLS/SSL Embedded Internet
TCP/IP
Supplicant
Wi-Fi Driver
Wi-Fi MAC Embedded Wi-Fi
Wi-Fi Baseband
Wi-Fi Radio
• NetCfg API – Configures different networking parameters, such as setting the MAC address,
acquiring the IP address by DHCP, and setting the static IP address.
• File System API – Provides access to the serial flash component for read and write operations
of networking or user proprietary data.
The CC3100BOOST and the MSP430F5529 are connected via the SPI interface as shown in
Figure 11-3.
HOST_SPI_CLK SPI_CLK
HOST_SPI_nCS SPI_nCS
HOST_SPI_MISO SPI_MISO
HOST_SPI_MOSI SPI_MOSI
HOST_INTR INTR
nHIB GPIO
The block diagram of Email application using CC3100 is as shown in Figure 11-4. This experiment
demonstrates the configuration of CC3100 as AP to send an email over SMTP (Simple Mail Trans-
fer Protocol). The application configures CC3100 to connect with an SMTP server and sends
email to it. The SMTP server forwards it to the recipient's email-server and the recipient receives
the email from his email-server using IMAP/POP3 and/or other proprietary protocol.
MSP-EXP430F5529LP
MSP430F5529 Wi-Fi
Connectivity
Access Point
CPU CC3100 Internet
Static IP address
configuration
SMTP
Server
alice@ti.com
bob@ti.com
Internet
1. MSP430F5529 MSP-
LaunchPad EXP430F5529LP
2. USB cable
11.4 Software
The software for the experiment is written in C and developed using the CCS Integrated Develop-
ment Environment (IDE). Refer to “Project Creation and Build” in the Getting Started section of
this manual for project build and debug using CCS. The software is programmed into the target
device MSP430F5529 on the MSP-EXP430F5529LP using the USB interface.
11.4.1 Flowchart
The flowchart for the experiment is as shown in Figure 11-5. The CC3100 BoosterPack is pow-
ered up in the default state. The CC3100 is started as a station and a static IP address is config-
ured to the device. On successful configuration of an IP address, the device is connected to the
access point, and communication is established. Then, it checks for LAN and Internet connectivity.
Once the connection is established, an email is sent through the SMTP.
START
No
Success? Forever Loop
Yes
No
Success? Forever Loop
Yes
No
Success? Forever Loop
Yes
No
Success? Forever Loop
Yes
Figure 11-5 Flowchart to Configure CC3100 as LAN Station to Send Email over SMTP
11.5 Procedure
1. Connect MSP430F5529 Launchpad and CC3100 BoosterPack as shown below in Figure 11-6.
2. Build, program and debug the code into the LaunchPad using CCS.
11.6 Observation
Open Tera Term Terminal Software on the PC where the MSP-EXP430 LaunchPad is connected.
The serial port parameters to be set are 9600 baud rate, 8 bits, No parity and 1 stop bit.The serial
window outputs the debug messages received from the MSP-EXP430 Hardware as shown in
Figure 11-7.
11.7 Summary
The CC3100 device is configured as a station and successfully connected to Internet to send an
email over the SMTP server.
11.8 Exercise
1. In the terminal output window, we have received a debug message “Pinging…!”. Search in the
code and change the message to “Pinging the website”. Repeat the experiment to observe this
change in the Serial Window.
2. Design an experimental set up to communicate between two MSP430 based sensor nodes
using Peer-to-peer communication.
Topics Page
12.1 Objective
The main objective of this experiment is to enable Energy Trace and Energy Trace++ modes in
MSP-EXP430G2 LaunchPad by using MSP430FR5969. This experiment will help you learn how
to analyze the Energy and Power graphs by enabling the Energy Trace Technology of MSP430 in
CCS studio.
12.2 Introduction
Energy Trace Technology, a software controlled DC-DC converter generates the target power sup-
ply (1.2 V - 3.6 V). The time density of the DC-DC converter charge pulses equals the energy con-
sumption of the target microcontroller. A built-in calibration circuit in the debug tool defines the
energy equivalent for a single charge pulse. The width of each charge pulse remains constant.
The debug tool counts every charge pulse, and the sum of the charge pulses are used in combina-
tion with the time elapsed to calculate an average current. Since this measurement technique con-
tinually samples the energy supplied to the microcontroller, even the shortest device activity that
consumes energy contributes to the overall recorded energy. This is a clear benefit over shunt-
based measurement systems, which cannot detect extremely short durations of energy consump-
tion.
Energy Trace technology is included in Code Composer Studio version 6.0 and newer. It requires
specialized debugger circuitry, which is supported with the second-generation on-board eZ-FET
flash emulation tool and second-generation standalone MSP-FET JTAG emulator. Target power
must be supplied through the emulator when Energy Trace is in use.
The two modes of Energy Capture are:
Energy Trace:
This mode allows the standalone use of the energy measurement feature with all MSP430 micro-
controllers, even unsupported devices (meaning there is no built-in Energy Trace++ technology
circuitry in the target microcontroller). The supply voltage on the target microcontroller is continu-
ously sampled to provide you with energy and power data. This mode can be used to verify the
energy consumption of the application without accessing the debugger.
Energy Trace++:
When debugging with devices that contain the built-in EnergyTrace++ technology support, the
EnergyTrace++ mode yields information about energy consumption as well as the internal state of
the microcontroller as given in Table 12-1.
Type State
This experiment explains in detail how to use Energy Trace technology on MSP-EXP430G2
LaunchPad. For demonstration purpose, the code from Experiment 7: PWM Based Speed Control
of Motor by Potentiometer is used.
2. MSP430FR5969 MSP-EXP430FR5969
Launchpad
12.4 Software
Any MSP430 evaluation module (EVM), experimenter's board (EXP), target socket module (TS),
or application board can utilize the Energy Trace component despite the fact that the Energy
Trace++ on-board circuitry is not present. To do this, the on-board emulation of a LaunchPad that
contains the Energy Trace technology circuitry is used to program and debug the intended target.
In this example, the MSPEXP430FR5969 which is having a Energy Trace technology on board cir-
cuitry is used as experimenter board and the MSP430G2553 is used as a target module to
achieve Energy Trace Technology.
12.5 Procedure
RST RST
TST TEST
V+ VCC
GND GND
4. Target power must be supplied through the MSP-EXP430FR5969 LaunchPad that has the
Energy Trace technology included in the on-board emulation. Plug-in the micro-USB to the MSP-
EXP430FR5969.
5. Initialize the debug session for the MSP430G2553 to enable the Energy Trace mode.
If the window does not open automatically, click View Others MSP430 Energy Trace
Energy Trace Technology
4. Run the code. The Energy Trace Technology window will update the real time data.
12.6 Observation
Complete analysis of Energy Trace Technology for Experiment 7:PWM Based Speed Control of
Motor by Potentiometer in terms of Energy, Power, Current, Voltage are given in Table 12-4.
The power and energy graph analyzed from Energy trace technology for Experiment 7: PWM
Based Speed Control of Motor by Potentiometer are shown in Figure 12-1.
The power graph shown in Figure 12-1 highlights the time density of the DC-DC converter charge
pulses which is equal to the energy consumption of the target microcontroller for a particular appli-
cation. The width of each charge pulse remains constant. The debug tool counts every charge
pulse and the sum of the charge pulses are used in combination with the time elapsed to calculate
an average current. The complete Energy profile for the application is shown in Figure 12-2.
.
12.7 Summary
In this experiment, we have learnt to enable Energy Trace and Energy Trace++ modes in MSP-
EXP430G2 LaunchPad by using MSP430FR5969.
12.8 Exercise
1. What is the difference between the Energy Trace and Energy Trace ++?
2. What hardware options available that supports Energy Trace++?
Topics Page
13.1 Objective
The main objective of this experiment is to compute the total energy of MSP-EXP430G2 Launch-
pad running an application and to estimate the life time of a battery.
13.2 Introduction
To measure the total energy of the MSP-EXP430G2XL and estimated life time of a battery the
Energy Trace Technology is must and should. Energy Trace Technology is an energy-based code
analysis tool that measures and displays the application's energy profile and helps to optimize it
for ultra-low power consumption. MSP430 devices with built-in Energy Trace+ [CPU State]+
[Peripheral States] (or in short, Energy Trace++™) technology allow real-time monitoring of many
internal device states while user program code executes. Energy Trace++ technology is supported
on selected MSP430 devices and debuggers.
The MSP-EXP430G2 LaunchPad does not support Energy Trace Technology. But it can utilize the
Energy Trace component despite the fact that the Energy Trace++ on board circuitry is not pres-
ent. To achieve this, the on-board emulation of a Launchpad that contains the Energy Trace tech-
nology circuitry is used to program and debug the intended target.
In this experiment, to program and debug the target device MSP-EXP430G2 LaunchPad, we use
the MSP-EXP430FR5969 Launchpad which contains the Energy Trace Technology on-board cir-
cuitry. When the Energy Trace mode is enabled in the target device, the profile window shows
some statistical data about the application that has been profiled.
The following are the parameters shown in the profile window:
• Captured time
• Total energy consumed by the application (in mJ)
• Minimum, mean, and maximum power (in mW)
• Mean voltage (in V)
• Minimum, mean, and maximum current (in mA)
• Estimated life time of the selected battery (in days) for the captured energy profile
2. USB cable
3. MSP-EXP430FR5969 MSP430FR5969
Launchpad plugged into
your PC via the USB
cable
4. Jumper Wires
13.4 Software
In this experiment, we have used the example code of Experiment 4: Interrupt Programming
Through GPIO.
13.5 Procedure
RST RST
TST TEST
V+ VCC
GND GND
4. Target power must be supplied through the MSP-EXP430FR5969 LaunchPad that has the
Energy Trace technology included in the on-board emulation. Plug-in the micro-USB to the MSP-
EXP430FR5969.
5. Initialize the debug session for the MSP430G2553 to enable the Energy Trace mode.
13.6 Observation
The Energy trace profile for active and stand by code is analyzed using Energy Trace technology.
The Energy Trace profile window of the application in active mode provides us the estimated life-
time of a battery of 46.6 days. If the same application run in standby mode, the estimated lifetime
of a battery exceeds to 106.7 days.
The formula to calculate the battery lifetime assumes an ideal 3-V battery and does not account for
temperature, aging, peak current and other factors that could negatively affect battery capacity.
Figure 13-1 and Figure 13-2 show the Energy Trace Profile windows for the application in active
and standby modes respectively.
The energy measurement and estimated lifetime of a battery for the application in both active and
standby modes are tabulated in Table 13-3.
Table 13-3: Energy measurement and Estimated lifetime of a battery
13.7 Summary
In this experiment, we have learnt the computation of total energy and estimated life time of a bat-
tery in terms of days by Energy Trace technology of MSP-EXP430G2 LaunchPad with the help of
MSP-EXP430FR5969.
13.8 Exercise
Compute the energy measurement and the estimated life time of a battery for Experiments 4 to 7.
Glossary
DCO Digitally Controlled Oscillator
DHCP Dynamic Hypertext Control Protocol
EVM Evaluation Module
GIE General Interrupt Enable
GPIO General Purpose Input Output
HTTP Hyper Text Transfer Protocol
Glossary cxxiii