0% found this document useful (0 votes)
8 views

ES Lab Manual

Uploaded by

uvineeth352
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

ES Lab Manual

Uploaded by

uvineeth352
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 73

ES Lab (16BT70432) Manual

SREE VIDYANIKETHAN ENGINEERING


COLLEGE
(AUTONOMOUS)
Sree Sainath Nagar, A. Rangampet, Tirupathi -
517102.

Department of Electronics and


Communication Engineering

IV B. Tech. I Sem.

EMBEDDED SYSTEMS LAB


(16BT70432)

LAB MANUAL

PREPARED BY

Mr. P. Madhu Kumar,


Asst. Prof (SL),
Dept. of ECE Page 1
ES Lab (16BT70432) Manual

Dept. of ECE

TABLE OF CONTENTS
EXP.N
O NAME OF THE EXPERIMENT PAGE.NO.
1. Introduction to MSP430 Launch Pad and Programming Environment:
a) Investigation of MSP430G2553 & MSP430F5529 Launch pad details
b) Familiarization with MSP430 based Integrated Development 3-13
Environment: CCS V6.1& Energia
c) Flash on-board LED/s
2. Read input from switch and automatic control/flash LED (Software delay): 14-18
Read Status of on-board Push button switch and operate LED using Polling
3. Interrupts Programming using GPIO: 19-22
Activate and configure Interrupts associated with GPIO pin associated with on-
board push button and define ISR to operated on-board LED/s
4. Configure Watchdog timer in watchdog and Interval Modes: 23-26
Using WDT in interval mode to operate on-board LED/s at different frequencies
5. Configure Timer for signal generation (with given frequency): 27-32
a) Using TimerA in up-mode – generate 1Hz symmetric square wave of
1Hz frequency (Sourcing TimerA from ACLK and polling TAIF)
b) Configuring TimerA interrupt to generate – generate 1Hz symmetric
square wave of 1Hz frequency
6. PWM Generator: Generate PWM using Timer A in compare mode to change 33-38
the light Intensity of on-board LED
7. Configuring MSP430 on-board ADC :
a) Configure ADC10 to read temperature of launch pad using on-chip 39-42
temperature sensor
b) Configure ADC12 to use potentiometer as Sensor 43-47
8. Speed Control of Motor:
a) Configure ADC to interface potentiometer to control the speed of DC 48-51
Motor using CCS
b) Configure ADC to interface potentiometer to control Servo Motor using 52-53
Energia
9. Use Comparator to compare the signal threshold level:
Configure Comparator_A to detect a voltage threshold-Using an external
potentiometer, an unknown voltage is applied to P1.1. and compared with 54-55
internal reference
10. Test Various Power down modes in MSP430: Analyze current drawn /Power
Consumed by the MSP430G2553 launch pad in different modes of operation 56-61
(AM, LPM0, LPM1, LPM2, LPM3 & LPM4)
11. Serial Peripheral Interface: Establish communication between Master & 62-69
Slave launch pads using SPI
12. Networking MSP using WiFi Module ( CC3100 Booster Pack): Scan 70-73
available networks for enabling MSP as IOT to print the Wifi MAC address,

Dept. of ECE Page 2


ES Lab (16BT70432) Manual

and scans for available Wifi networks. Every ten seconds, it scans again.

Experiment No.:1

INTRODUCTION TO MSP430 LAUNCH PAD/S AND PROGRAMMING


ENVIRONMENT

AIM
a) To Investigation Features of MSP430G2553 & MSP430F5529 Launch pads
b) To Familiarize with MSP430 based Integrated Development Environment: CCS V6.1& Energia
c) To Develop High level code and use IDE to Flash on-board LED/s

APPARATUS
 PC Installed with CCSV6 & Energia
 Launch pads: MSP-EXP430G2553 & MSP-EXP430F5529LP
 USB Cable to interconnect Launch pad to windows enabled PC

Theory
a) Comparison of two launch pads
Feature MSP430G2553 MSP430F5529
Pinout 20 pin DIP 80 Pin QFP
Supply Voltage range 3.6 down to 1.8V
Low power modes 1 Active and 5 Low power modes 1 active and 6 software
(LPM0 to LPM4) selectable low power modes

Parallel ports 3-8bit ports 8-8bit ports


Wakeup from low power/ <1micro second <3.5 micro seconds
standby mode
Capacitive touch enabled pins 24 63
ADC 10 bit, 8-channel with auto scan
Instruction set 51 instructions (3 formats) with
7 source operand addressing
modes and 4 destination
operand addressing modes
RAM 512 bytes 8KB

Flash Information Memory:256B 128KB


Mem: IVT + Code Mem: 16KB

Dept. of ECE Page 3


ES Lab (16BT70432) Manual

Timers (16-bit) 2: Timer0_A & Timer1_A with 3 3: TA05, TA13, TA23,TB07


capture compare registers RTC module
USCI Module (Serial Synchronous: SPI (3/4 Wire) + USB-PHY 2.0
Communication) I2C 2 USCI
Asynchronous: UART + LIN 4 SPI
(Advanced UART with automatic
Baud rate detection) +IrDA
Comparator Comparator_A+: 8-bit
comparison
ADC ADC10: 8-channel auto scan 12-bit SAR ADC
DMA 3-channel internal DMA
Hardware Multiplier 32-bit
Clock 16 MHz 25MHz

b) Working with CCS IDE: Guidelines

1. Open Code Composer Studio V6.1.1.2.


2. Now select a Workspace and then click Ok.

3. Now select project and then select New CCS project.

Dept. of ECE Page 4


ES Lab (16BT70432) Manual

4. In CCS project
 Select Target as MSP430G2553.
 Select Connection as TIMSP430 USB1 (default).
 Give project name as per requirement. (Ex. LED_BLINK).
 Select Compiler version as TIv4.4.5.
 Select empty project (with main .c).
 Click Finish.

5. Now connect the MSP-EXP430G2 Launch pad to the system by using USB cable.

6. Now in main .c write the program.

Digital I/O

MSP430G2553 devices have up to eight digital I/O ports (P1 to P8). Each port has up to eight
I/O pins that are configured with user software. Every I/O pin is individually configurable as
input or output, and can be individually read or written to.

The features of the digital I/O are:

• Independently programmable individual I/Os


• Any combination of input or output
• Individually configurable P1 and P2 interrupts
• Independent input and output data registers

Dept. of ECE Page 5


ES Lab (16BT70432) Manual

• Individually configurable pull-up or pull-down resistors


• Individually configurable pin-oscillator function in some MSP430 devices

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 Launch Pad 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.

Dept. of ECE Page 6


ES Lab (16BT70432) Manual

Code for Toggling Red LED

#include <msp430g2553.h>

volatile unsigned int i=0;


/*
* main.c
*/
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P1DIR |= BIT0;

for (;;)
{
P1OUT |= BIT0;
__delay_cycles(1000000);
P1OUT &= ~BIT0;
__delay_cycles(1000000);

}
}

7. Then Save the program.

8. Now compile the program by clicking on compiler icon as shown below .By this the program
building (compiling) will be finished and hence we can check for errors if any.

Dept. of ECE Page 7


ES Lab (16BT70432) Manual

9. Now debug the program by clicking on the debug icon as shown below.

10. Then click on proceed.

11. Now run the program by clicking on the run button.

Dept. of ECE Page 8


ES Lab (16BT70432) Manual

12. Now we can watch the output on the launch pad as per the program.

13. We can terminate the process by clicking on the terminate button.

This ends the process of using the MSP430G2553 Launch pad for performing various
operations in Embedded Systems.

c) Working with ENERGIA: Guidelines

1. Open Energia software.

2. Select Tools—Board---Launch pad w/ msp430f5529 (25MHz).

Dept. of ECE Page 9


ES Lab (16BT70432) Manual

3.Go to Tools and select the required serial port(decide it based on the serial port in “device
manager—port—MSP application UART1 “).

4. Go to file—Examples or write your own sketch

Dept. of ECE Page 10


ES Lab (16BT70432) Manual

Energia Sketch is composed of two loops namely

 void setup ( )
 void loop ( )

Energia uses macrofunctions such as

 pinMode ( )
 pinOut ( )

using which the sketch has to be edited.

Code for Toggling Green LED

#define LED GREEN_LED

// the setup routine runs once when you press reset:

void setup() {

// initialize the digital pin as an output.

pinMode(LED, OUTPUT);

// the loop routine runs over and over again forever:

void loop() {

digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)

Dept. of ECE Page 11


ES Lab (16BT70432) Manual

delay(1000); // wait for a second

digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second

6. Now verify the program.

7. Then upload the program.

8. Now go to Tools and select Update Programmer.

Dept. of ECE Page 12


ES Lab (16BT70432) Manual

9. Now we can observe the required output on the launch pad

Dept. of ECE Page 13


ES Lab (16BT70432) Manual

Experiment No.:2

READ INPUT FROM SWITCH AND AUTOMATIC CONTROL/FLASH


LED USING SOFTWARE DELAY.

AIM
To Read input from on-board push button switch and by polling its status in P1IN SFR control/
flash on-board LED by using the CCS and Energia

APPARATUS
 PC Installed with CCSV6 & Energia
 Launch pads: MSP-EXP430G2553 & MSP-EXP430F5529LP
 USB Cable to interconnect Launch pad to windows enabled PC

THEORY
Digital I/O

MSP430 devices have up to eight digital I/O ports (P1 to P8). Each port has up to eight I/O pins
that are configured with user software. Every I/O pin is individually configurable as input or
output, and can be individually read or written to.

The features of the digital I/O are:

• Independently programmable individual I/Os


• Any combination of input or output
• Individually configurable P1 and P2 interrupts
• Independent input and output data registers
• Individually configurable pull-up or pull-down resistors
• Individually configurable pin-oscillator function in some MSP430 devices

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
experiment.

Dept. of ECE Page 14


ES Lab (16BT70432) Manual

Figure 2-2 shows the Launchpad schematics for the connection of Digital I/O pins to the on-
board LEDs in the LaunchPad.

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

Similarly, a pull-down resistor defaults a hardware connection to ground, 0V as shown in


Figure 2-4. When the switch is open, 0V GND (logic LOW) is available on the input pin of the
MCU.

Dept. of ECE Page 15


ES Lab (16BT70432) Manual

Dept. of ECE Page 16


ES Lab (16BT70432) Manual

PROGRAM

a) CCS

//The below code turns on green LED until switch is in on state else turns red LED
//on.
#include <msp430g2553.h>
volatile unsigned int i;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR = BIT0+BIT6;
P1REN = BIT3;
P1OUT = BIT3;//pull up
while(1)
{
if ( !(P1IN & BIT3))
{
for (i=0; i<=255;i++)
P1OUT | =BIT6;
P1OUT & = ~BIT0;

}
else
{
for (i=0; i<=255;i++)
P1OUT | =BIT0;
P1OUT & = ~BIT6;
}
}
}

b) Energia

// constants won't change. They're used here to set pin numbers

const int buttonPin = PUSH2; // the number of the pushbutton pin


const int ledPin = GREEN_LED; // the number of the LED pin

// variables will change:

int buttonState = 0; // variable for reading the pushbutton status

Dept. of ECE Page 17


ES Lab (16BT70432) Manual

void setup( )
{

pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:


pinMode(buttonPin, INPUT_PULLUP); // initialize the pushbutton pin as i/p

void loop( ){
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value

if (buttonState == HIGH)
{

digitalWrite(ledPin, HIGH); // turn LED on:


}
else
{
digitalWrite(ledPin, LOW); // turn LED off:

}
}

Experiment No.:3 :

Dept. of ECE Page 18


ES Lab (16BT70432) Manual

INTERRUPTS PROGRAMMING USING GPIO


AIM
Activate and configure Interrupts associated with GPIO pin associated with on-board push button and
define ISR to operated on-board LED/s

APPARATUS
 PC Installed with CCSV6 & Energia
 Launch pads: MSP-EXP430G2553 & MSP-EXP430F5529LP
 USB Cable to interconnect Launch pad to windows enabled PC

THEORY:
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
following 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
interrupt 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
interrupt service routine at that address.
The interrupt handling routine terminates with the instruction RETI (return from an interrupt
service routine)

Dept. of ECE Page 19


ES Lab (16BT70432) Manual

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.

Dept. of ECE Page 20


ES Lab (16BT70432) Manual

Active high: Active Low:

Program
a) CCS
#include <msp430G2553.h>
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= BIT6; // Set P1.6 to output direction
P1REN |= BIT3; // Enable P1.3 internal resistance
P1OUT |= BIT3; // Set P1.3 as pull up resistance
P1IES |= BIT3; // P1.3 High/Low Edge
P1IFG &= ~BIT3; // P1.3 IFG Cleared
P1IE |= BIT3; // P1.3 Interrupt Enabled
_bis_SR_register(LPM4_bits + GIE); // Enter LPM4 w/ interrupt
_no_operation(); // For debugger

#pragma vector=PORT1_VECTOR
__interrupt void Port_1 (void)
{
P1OUT ^= BIT6; // Toggle P1.6
P1IFG &= ~BIT3; // P1.3 IFG Cleared
}

b) Energia

Dept. of ECE Page 21


ES Lab (16BT70432) Manual

volatile bool led_state = LOW;


void setup()
{

pinMode(RED_LED, OUTPUT);
pinMode(PUSH2, INPUT_PULLUP);
attachInterrupt(PUSH2,blink,FALLING);
}
void loop()
{
noInterrupts();
/* critical, time-sensitive code here */
digitalWrite(RED_LED, Led_state)
interrupts();
/* other code here */
}
/* ISR */
void blink() {
led_state = !led_state; /* Toggle state value of LED */
}

Experiment No.:4

Dept. of ECE Page 22


ES Lab (16BT70432) Manual

USING WATCHDOG TIMER AS INTERVAL TIMER


AIM
To operate/blink on-board LEDs at different frequencies by using WDT in interval mode.

APPARATUS
 PC Installed with CCSV6 & Energia
 Launch pads: MSP-EXP430G2553 & MSP-EXP430F5529LP
 USB Cable to interconnect Launch pad to windows enabled PC

THEORY:
Watchdog Timer+ (WDT+) Introduction:
The primary function of the WDT+ module is to perform a controlled system restart after
a software problem occurs. If the selected time interval expires, a system reset is generated. If the
watchdog function is not needed in an application, the module can be configured as an interval
timer and can generate interrupts at selected time intervals.

Features of the watchdog timer+ module include:

• Four software-selectable time intervals


• Watchdog mode
• Interval mode
• Access to WDT+ control register is password protected
• Control of RST/NMI pin function
• Selectable clock source
• Can be stopped to conserve power
• Clock fail-safe feature

Watchdog Timer+ Operation:


The WDT+ module can be configured as either a watchdog or interval timer with the
WDTCTL register. The WDTCTL register also contains control bits to configure the RST/NMI
pin. WDTCTL is a 16-bit, password-protected, read/write register. Any read or write access must
use word instructions and write accesses must include the write password 05Ah in the upper
byte. Any write to WDTCTL with any value other than 05Ah in the upper byte is a security key
violation and triggers a PUC system reset regardless of timer mode. Any read of WDTCTL reads
069h in the upper byte. The WDT+ counter clock should be slower or equal than the system
(MCLK) frequency.

Dept. of ECE Page 23


ES Lab (16BT70432) Manual

Watchdog Timer+ Counter:


The watchdog timer+ counter (WDTCNT) is a 16-bit up-counter that is not directly
accessible by software.The WDTCNT is controlled and time intervals selected through the
watchdog timer+ control register WDTCTL.The WDTCNT can be sourced from ACLK or
SMCLK. The clock source is selected with the WDTSSEL bit.
.

Watchdog Timer+ Registers:


The WDT+ registers are listed in Table

WDTCTL, Watchdog Timer+ Register:

Assuming the MSP430 system clock has a frequency of 1Mhz and the watchdog timer is clocked
by the sub-master clock (SMCLK), the following intervals are available:

Dept. of ECE Page 24


ES Lab (16BT70432) Manual

Constant Interval Clocks/Interval Intervals/Second (@1Mhz)


(@1Mhz)

WDT_MDLY_32 32ms 32000 1000000/32000 = 31.25


(default)

WDT_MDLY_8 8ms 8000 1000000/8000 = 125

WDT_MDLY_0_5 0.5ms 500 1000000/500 = 2000

WDT_MDLY_0_064 0.064ms 64 1000000/64 = 15625

PROGRAM

#include "MSP430G2553.h"
#include "intrinsics.h"

volatile uint16_t delay1,delay2;

void main(void)
{
WDTCTL = WDT_MDLY_0_5; // WDT as interval timer (period 0,5 ms)
IE1 |= WDTIE; // Enable WDT interrupt
P1DIR |= BIT0+BIT6; // Set P1.0 & P1.6 as output
P1OUT |= BIT0+BIT6; // P1.0 & P1.6 are ON at start
delay1 = 5000; // LED1 toggle period = 509 ms
delay2 = 10000; // LED1 toggle period = 1717 ms
__low_power_mode_1(); // Enable interrupt and enter LPM1 mode
}

// Watchdog Interval Timer interrupt service


#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
if(--delay1==0)

Dept. of ECE Page 25


ES Lab (16BT70432) Manual

{ // Countdown of intervals
P1OUT ^= BIT0; // Toggle LED1 (P1.0) state
delay1 = 5000; // Reload delay counter 1.
}
if(--delay2==0)
{
P1OUT ^= BIT6; // Toggle LED2 (P1.6) state
delay2 = 10000; // reload delay counter 2.
}
}

Experiment No.:5

CONFIGURE TIMER FOR SIGNAL GENERATION


(FOR GIVEN FREQUENCY)

Dept. of ECE Page 26


ES Lab (16BT70432) Manual

.
AIM
a) Using TimerA in up-mode – generate 1Hz symmetric square wave of 1Hz frequency
(Sourcing TimerA from ACLK and polling TAIF)
b) Configuring TimerA interrupt to generate – generate 1Hz symmetric square wave of 1Hz
frequency

APPARATUS
 PC Installed with CCSV6 & Energia
 Launch pads: MSP-EXP430G2553 & MSP-EXP430F5529LP
 USB Cable to interconnect Launch pad to windows enabled PC

THEORY:
Inside Timer_A

• Timer_A Control Register: TACTL

Timer Mode

• MCx=00: Stop mode

– The timer is halted

Dept. of ECE Page 27


ES Lab (16BT70432) Manual

• MCx=01: Up mode

– The timer repeatedly counts from 0 to TACCR0

• MCx=10: Continuous mode

– The timer repeatedly counts from 0 to 0FFFFh

• MCx=11: Up/down mode

– The timer repeatedly counts from 0 to TACCR0 and back down to 0.

UP MODE:
The up mode is used if the timer period must be different from 0FFFFh counts.

1. Timer period 100 à store 99 to TACCR0

2. When TACCR0 == 99, set TACCR0 CCIFG interrupt flag

3. Reset timer to 0 and set TAIFG interrupt flag

CONTINUOUS MODE:

• In the continuous mode, the timer repeatedly counts up to 0FFFFh and restarts from zero

• The TAIFG interrupt flag is set when the timer resets from 0FFFFh to zero

UP/DOWN MODE:
The up/down mode is used if the timer period must be different from 0FFFFh counts, and if a
symmetrical pulse generation is needed.

Dept. of ECE Page 28


ES Lab (16BT70432) Manual

à The period is twice the value in TACCR0.

• MSP430 addresses the conflicting demands for high performance, low power, precise
frequency by using 3 internal clocks, which can be derived from up to 4 sources

– Master clock (MCLK): for CPU & some peripherals, normally driven by digitally
controlled oscillator (DCO) in megahertz range

– Subsystem master clock (SMCLK): distributed to peripherals, normally driven by


DCO

– Auxiliary clock (ACLK): distributed to peripherals, normally for real-time


clocking, driven by a low-frequency crystal oscillator, typically at 32 KHz

• Low- or high-frequency crystal oscillator, LFXT1:

– External; used with a low- or high frequency crystal; an external clock signal can
also be used; connected to MSP430 through XIN and XOUT pins

• High-frequency crystal oscillator, XT2:

– External; similar to LFXT1 but at high frequencies

• Very low-power, low-frequency oscillator, VLO:

– Internal at 12 KHz; alternative to LFXT1 when accuracy of a crystal is not


needed; may not available in all devices

• Digitally controlled oscillator, DCO:

– Internal; a highly controllable RC oscillator that starts fast

• Typical sources of clocks:

– MCLK, SMCLK: DCO (typically at 1.1 MHz)

– ACLK: LFXT 1 (typically at 32 KHz)

Dept. of ECE Page 29


ES Lab (16BT70432) Manual

CALCULATIONS
Consider f=1 HZ i.e. T = Ton +Toff = 1 Sec.

For symmetrical square wave Ton = Toff = 0.5 Sec.

So, driving an on-board LED with such a square wave is equivalent to toggle state of LED once
for every 0.5 sec.

Generation of 0.5 sec using Timer

If Timer is sourced from ACLK ~=32KHz i.e. Taclk * (2^16) gives max delay = 2 Sec. If Timer
is operated in up-mode with can stop timer by ¼ th of 2 Sec. delay i.e. 0.5 sec by loading CCR0
with corresponding count.

PROGRAM

a) By Polling TAIFG toggle on-board LED once for every 0.5 Sec.
Dept. of ECE Page 30
ES Lab (16BT70432) Manual

#include <msp430g2553.h>
#define LED1 BIT0
void main (void)
{
WDTCTL = WDTPW|WDTHOLD; // Stop watchdog timer
P1OUT = ~LED1;
P1DIR = LED1;
TACCR0 = ¼ * 65536;
TACTL = MC_1|ID_0|TASSEL_1|TACLR; //Setup Timer_A
//up mode, divide clk by 1, use ACLK, clr timer
for (;;) { // Loop forever

while (!(TACTL&TAIFG)) { // Wait time up


} // doing nothing

TACTL &= ~TAIFG; // Clear overflow flag


P1OUT ^= LED1; // Toggle LEDs

} // Back around infinite loop


}

b) Using Timer_A ( sourced by ACLK = 32KHz) with CCR0 in Up Mode


define ISR to toggle P1.0 once for every 0.5 Sec.

;---------------------------------------------------------------
.cdecls C,LIST, "msp430.h"
;---------------------------------------------------------------------
----------
.def RESET ; Export program entry-
point to
; make it known to linker.

;---------------------------------------------------------------------
---------
.text ; Progam Start
;---------------------------------------------------------------------
---------
RESET mov.w #0280h,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT
SetupP1 bis.b #001h,&P1DIR ; P1.0 output
SetupC0 mov.w #CCIE,&CCTL0 ; CCR0 interrupt enabled
mov.w #1000-1,&CCR0 ; CCR0 counts to 1000
SetupTA mov.w #TASSEL_1+MC_1,&TACTL ; ACLK, upmode
;

Mainloop bis.w #LPM3+GIE,SR ; Enter LPM3, interrupts


enabled
nop ; Required for debugger

Dept. of ECE Page 31


ES Lab (16BT70432) Manual

;
;---------------------------------------------------------------------
----------
TA0_ISR; Toggle P1.0
;---------------------------------------------------------------------
----------
xor.b #001h,&P1OUT ; Toggle P1.0
reti ;
;
;---------------------------------------------------------------------
---------
; Interrupt Vectors
;---------------------------------------------------------------------
---------
.sect ".reset" ; MSP430 RESET Vector
.short RESET ;
.sect ".int09" ; Timer_A0 Vector
.short TA0_ISR ;
.end

Experiment No.:6

PULSE WIDTH MODULATION GENERATION


Dept. of ECE Page 32
ES Lab (16BT70432) Manual

AIM
Generate PWM using Timer A in compare mode to change the light Intensity of on-board LED
using CCS and Energia.

APPARATUS
 PC Installed with CCSV6 & Energia
 Launch pads: MSP-EXP430G2553
 USB Cable to interconnect Launch pad to windows enabled PC

THEORY:
PWM

Pulse Width Modulation (PWM) is a method of digitally encoding analog signal levels. High-
resolution 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.

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.

Dept. of ECE Page 33


ES Lab (16BT70432) Manual

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-
analog (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 output
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 experiment.

Dept. of ECE Page 34


ES Lab (16BT70432) Manual

Modes of Capture/Compare Block :

• Compare mode:

– Compare the value of TAR with the value stored in TACCRn and update an
output when they match

• Capture mode: used to record time events

– Records the “time” (value in TAR) at which the input changes in TACCRx

– The input, usually CCIxA and CCIxB, can be either external or internal from
another peripheral or software, depending on board connections

Dept. of ECE Page 35


ES Lab (16BT70432) Manual

Dept. of ECE Page 36


ES Lab (16BT70432) Manual

PROGRAM
a) CCS
#include <msp430g2553.h>
unsigned int i=0;
int a[5]= {0,32,64,128,255,320,450,512};
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= BIT6;
P1SEL |= BIT6;
TA0CCR0 =512-1 ; //Period
TA0CCR1 = a[0]; // Ton = 0 initially
TA0CCTL1 = OUTMOD_7; // PWM Set-Reset Mode
TA0CTL = TASSEL_2 + MC_1 + TAIE + ID_3;
_bis_SR_register (LPM0_bits + GIE);
while(1); }

Dept. of ECE Page 37


ES Lab (16BT70432) Manual

#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer (void)
{
TA0CTL &=~TAIFG;
while(1)
{
for( i=0;i<7;i++)
{
TA0CCR1 = a[i];
__delay_cycles(1000000);
}
for(i=7;i>1;i--)
{
TA0CCR1 = a[i];
__delay_cycles(1000000);

}
}
}

b) Energia

int brightness = 0; // how bright the LED is


int fadeAmount = 5; // how many points to fade the LED by
void setup() {
pinMode(GREEN_LED, OUTPUT);
}
void loop() {
analogWrite(GREEN_LED, brightness);
brightness = brightness + fadeAmount; // change the brightness for next time through the loop:
if (brightness == 0 || brightness == 255) {
// reverse the direction of the fading at the ends of the fade:
fadeAmount = -fadeAmount ;
}
delay(30); // wait for 30 milliseconds to see the dimming effect
}

Dept. of ECE Page 38


ES Lab (16BT70432) Manual

Experiment No.:7 (a)

USING ADC-10 ON CHIP SENSOR TO TRACK THE


LAUNCHPAD TEMPERATURE
AIM
To Read Temperature of MSP430 using on-board ADC
a) Configure ADC to read temperature of launch pad using on-chip temperature sensor
b) Configure ADC12 to use potentiometer as Sensor

APPARATUS
 PC Installed with CCSV6
 Launch pads: MSP-EXP430G2553 & MSP-EXP430F5529LP
 USB Cable to interconnect Launch pad to windows enabled PC

THEORY
ADC10 Introduction

The MSP430G2553 has ADC10 - a 10-bit analog-to-digital converter which converts the analog
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
conversion takes multiple cycles. The timing is controlled by an ADC clock. While a conversion
is in progress, the busy flag is 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 controller' that can steal cycles from the CPU and store a block of conversion
results directly in memory.

ADC10 features include:


• Greater than 200-ksps maximum conversion rate
• Monotonic 10-bit converter with no missing codes
• Sample-and-hold with programmable sample periods
• Conversion initiation by software or Timer_A
• Software selectable on-chip reference voltage generation (1.5 V or 2.5 V)
• Software selectable internal or external reference
• Up to eight external input channels (twelve on MSP430F22xx devices)
• Conversion channels for internal temperature sensor, VCC, and external references
• Selectable conversion clock source
• Single-channel, repeated single-channel, sequence, and repeated sequence conversion modes
• ADC core and reference voltage can be powered down separately

Dept. of ECE Page 39


ES Lab (16BT70432) Manual

• Data transfer controller for automatic storage of conversion results

There is an on-chip Temperature Sensor connected to A10 input of ADC10. This Sensor can
track the launch pad temperature and we can display the value of ADC10MEM using Watch
window.
The SFRs available to program ADC10 are

ADC10CTL0 & ADC10CTL1 can be programmed for converting Temperature to display in the
watch window.

Dept. of ECE Page 40


ES Lab (16BT70432) Manual

Refer Appendix for bit by bit details of these SFRs.

PROGRAM

#include <msp430.h>
long temp;
long IntDegC;

int main(void)
{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT


ADC10CTL1 = INCH_10 + ADC10DIV_3; // Temp Sensor ADC10CLK/4
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;
__enable_interrupt(); // Enable interrupts.

Dept. of ECE Page 41


ES Lab (16BT70432) Manual

TACCR0 = 30; // Delay to allow Ref to settle


TACCTL0 |= CCIE; // Compare-mode interrupt.
TACTL = TASSEL_2 | MC_1; // TACLK = SMCLK, Up mode.
LPM0; // Wait for delay.
TACCTL0 &= ~CCIE; // Disable timer Interrupt
__disable_interrupt();

while(1)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
// oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278

temp = ADC10MEM;
IntDegC = ((temp - 673) * 423) / 1024;
__no_operation(); // SET BREAKPOINT HERE
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void)
{
TACTL = 0;
LPM0_EXIT; // Exit LPM0 on return
}

Working with Breakpoints and Watch Expressions:


Right click on ADC10MEM0 line and choose watch expression o view.
Right click on Breakpoint and select break point properties and refresh all windows.

Dept. of ECE Page 42


ES Lab (16BT70432) Manual

Experiment No.:7(b)

CONFIGURE ADC-12 TO USE POTENTIOMETER AS A


SENSOR
AIM To Configure ADC12 to use potentiometer as a sensor

APPARATUS
 PC Installed with CCSV6 & Energia
 Launch pad : MSP-EXP430F5529LP
 USB Cable to interconnect Launch pad to windows enabled PC

THEORY

The pin out of MSP-EXP430F5529LP is given below:

The ADC12_A module supports fast 12-bit analog-to-digital conversions (SAR type).

Dept. of ECE Page 43


ES Lab (16BT70432) Manual

ADC12_A features include:


• Greater than 200-ksps maximum conversion rate
• Monotonic 12-bit converter with no missing codes
• Sample-and-hold with programmable sampling periods controlled by software or timers
• Conversion initiation by software or timers
• Software-selectable on-chip reference voltage generation (MSP430F54xx (non-A only): 1.5 V
or 2.5 V,
all other devices: 1.5 V, 2.0 V, or 2.5 V)
• Software-selectable internal or external reference
• Up to 12 individually configurable external input channels
• Conversion channels for internal temperature sensor, AVCC, and external references
• Independent channel-selectable reference sources for both positive and negative references
• Selectable conversion clock source
• Single-channel, repeat-single-channel, sequence (autoscan), and repeat-sequence (repeated
autoscan) conversion modes
• ADC core and reference voltage can be powered down separately
• Interrupt vector register for fast decoding of 18 ADC interrupts
• 16 conversion-result storage registers

CONNECTIONS
1.Connect Launchpad to the PC using the USB cable supplied.
2. Connect the positive lead of the potentiometer to the 3.3V pin on the Launchpad and the
negative lead of the potentiometer to the GND pin.
3. Connect the output lead of the potentiometer to pin P6.0 or Analog Channel A0.

SFRs for programming

Dept. of ECE Page 44


ES Lab (16BT70432) Manual

Refer Appendix for details regarding SFRs.

Set-up for reading potentiometer and driving on-board LED

PROGRAM

a) CCS

#include <msp430f5529.h>
unsigned int ADC_result =0;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12IE = 0x01; // Enable interrupt
ADC12CTL0 |= ADC12ENC;
P6SEL |= 0x01; // P6.0 ADC option select

Dept. of ECE Page 45


ES Lab (16BT70432) Manual

P1DIR |= 0x01; // P1.0 output


while (1)
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion
__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
__no_operation(); // For debugger
}
}
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
ADC_result = ADC12MEM0;
/*if (ADC12MEM0 >= 0x7ff) // ADC12MEM = A0 > 0.5AVcc?
P1OUT |= BIT0; // P1.0 = 1
else
P1OUT &= ~BIT0; */ // P1.0 = 0
__bic_SR_register_on_exit(LPM0_bits); // Exit active CP
}
b) Energia

This program drives LED with value sensed by reading potentiometer

int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}

void loop() {

Dept. of ECE Page 46


ES Lab (16BT70432) Manual

// read the value from the sensor:


sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}

Dept. of ECE Page 47


ES Lab (16BT70432) Manual

Experiment No.:8 (a)

SPEED CONTROL OF DC MOTOR BY USING ON-CHIP PWM


AND ADC
AIM To control the speed of dc motor by using on-chip PWM and ADC Modules

APPARATUS
 PC Installed with CCSV6 & Energia
 Launch pad : MSP-EXP430F5529LP
 USB Cable to interconnect Launch pad to windows enabled PC

THEORY:
PWM

Pulse Width Modulation (PWM) is a method of digitally encoding analog signal levels. High-
resolution 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.

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.

Dept. of ECE Page 48


ES Lab (16BT70432) Manual

The Timer A and Timer B of the MSP430G2553 are capable of PWM outputs in compare mode.

Analog-Digital Converter

The MSP430G2553 has ADC10, a 10-bit analog-to-digital converter which converts the analog
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
conversion takes multiple cycles. The timing is controlled by an ADC clock. While a conversion
is in progress, the busy flag is 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 controller' that can steal cycles from the CPU and store a block of conversion
results directly in memory.
Low-power mode 0 (LPM0)
• 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 capture/ 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.

Dept. of ECE Page 49


ES Lab (16BT70432) Manual

Dept. of ECE Page 50


ES Lab (16BT70432) Manual

PROGRAM:
#include<msp430g2553.h>

void main()
{
WDTCTL=WDTPW + WDTHOLD;
ADC10CTL0|= ADC10ON + SREF_0 + ADC10SHT_2; //Enable ADC //module,reference
//voltage, sample & //hold time
ADC10CTL1|= INCH_3; //Select input channel 3
ADC10AE0|= 0x08; //Analog Enable channel 3
P1DIR|=BIT6; //Make Port1-->Pin6 as output
P1SEL|=BIT6; //Select PWM Function
TA0CTL|=TASSEL_2+ID_3+MC_1+TAIE; //Configure Timer0,//SMCLK,UP mode,
//Clock Source divide by
8,//InterruptEnable
TA0CCTL1|=OUTMOD_7 ; //Select OUTPUT MODE 7; RESET/SET
TA0CCR0=1024; //Configure PWM time period
TA0CCR1=1; //Configure PWM ON_TIME(Duty Cycle)
__bis_SR_register(GIE); //General Interrupt Enable
while(1);
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void timer(void)
{
ADC10CTL0|=ENC+ADC10SC;//ADC enable conversion & start conversion
TA0CCR1= ADC10MEM; //Copy ADC buffer value into CCR1 to vary duty cycle
}

Experiment No.:8 (b)

Configure ADC to interface potentiometer to control Servo Motor


using Energia
AIM To control the angle of coverage for given Servo motor by using Energia libraries

APPARATUS
Dept. of ECE Page 51
ES Lab (16BT70432) Manual

 PC Installed with Energia


 Launch pad : MSP-EXP430F5529LP
 Servo SG90
 USB Cable to interconnect Launch pad to windows enabled PC

THEORY:

Servo SG90 with wire connections:

Connection details:
1. Connect Brown wire to gnd on launchpad
2. Connect Red wire to +5V on launch pad
3. Connect Orange wire to output PWM – P2.5 – pin no. 40
4. use 10K pot middle pin at A0=Pin6.0 = A0 to control Servo angle ( for program ii)

PROGRAM:
i) Sweep: to sweep servo continuously

#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{

Dept. of ECE Page 52


ES Lab (16BT70432) Manual

myservo.attach(40); // attaches the servo on pin 40 to the servo object


}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

ii) using Knob: Controlling a servo position using a potentiometer (variable resistor)

#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
myservo.attach(40); // attaches the servo on pin 9 to the servo object
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 4095, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}

Experiment No.:9

PROGRAMMING COMPARATOR A+

AIM : To Program Comparator A+ on MSP430G2553 to compare the unknown signal


crossing the threshold using code composer studio

Dept. of ECE Page 53


ES Lab (16BT70432) Manual

APPARATUS:
 PC Installed with CCSV6
 Launch pad : MSP-EXP430G2553
 USB Cable to interconnect Launch pad to windows enabled PC
 10K Potentiometer

THEORY:
Configure Comparator_A to detect a voltage threshold-Using an external potentiometer, an unknown
voltage is applied to P1.1. and compared with an internal reference

Internal Circuitry

The experiment is to Compare External Analog input at P1.1 (CA1) with 0.25 VCC and glow
LED at P1.0 to indicate that it is above 0.25 VCC.

PROGRAM:
#include <msp430.h>
int main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x01; // P1.0 output

Dept. of ECE Page 54


ES Lab (16BT70432) Manual

CACTL1 = CARSEL + CAREF0 + CAON; // 0.25 Vcc = -comp, on


CACTL2 = P2CA4; // P1.1/CA1 = +comp
while (1) // Test comparator_A output
{
if ((CAOUT & CACTL2))
P1OUT |= 0x01; // if CAOUT set, set P1.0
else P1OUT &= ~0x01; // else reset
}
}

Experiment No.:10
LOW POWER MODES
AIM : To Test Various Power down modes in MSP430 - Analyze current drawn /Power
Consumed by the MSP430G2553 launch pad in different modes of operation (AM, LPM0,
LPM1, LPM2, LPM3 & LPM4) using code composer studio.

APPARATUS:

Dept. of ECE Page 55


ES Lab (16BT70432) Manual

 PC Installed with CCSV6


 Launch pad : MSP-EXP430G2553
 USB Cable to interconnect Launch pad to windows enabled PC
 Digital Multimeter with connecting probes

THEORY:
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 consumption is reduced by disabling the clock for a particular peripheral as per the
application requirement.

The state of the CPU and clocks for the different low power modes of the MSP430G2553 is
given below

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 below.

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

Dept. of ECE Page 56


ES Lab (16BT70432) Manual

spent in the while (1) loop, waiting for an interrupt.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.

PROGRAM:
Active Mode:

#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
volatile long tempRaw;
volatile unsigned int i;
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

Dept. of ECE Page 57


ES Lab (16BT70432) Manual

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 3 second to the timer
}

Standby Mode:

#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
volatile long tempRaw;
//volatile unsigned int i;
void FaultRoutine(void);
void ConfigWDT(void);
void ConfigClocks(void);
void ConfigPins(void);
void ConfigADC10(void);

Dept. of ECE Page 58


ES Lab (16BT70432) Manual

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

Dept. of ECE Page 59


ES Lab (16BT70432) Manual

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
}

PROCEDURE:

Demonstration Involves two steps: Measurement of current in Active Mode & Measurement of
current in Standby (LPM3) Mode.

Initially, connect the MSP-EXP430G2 LaunchPad to the PC using the USB cable supplied.

Measurement of Current in Active Mode

1. Run MSP in active mode


2. Build, load, and run the code. The green LED will blink once every three or four seconds.
3. When done, halt the code and click the Terminate button to return to the "CCS Edit".
4. Remove all five jumpers on header J3.
5. The red lead of the multimeter should connect to the top (emulation side) Vcc pin on header J3
and the black lead of the multimeter should connect to the bottom (target side) Vcc pin on header J3.
6. Press the Reset button on the LaunchPad board.
7. Measure the current drawn by the MSP430G2553.

Measurement of Current in Standby (LPM3) Mode

1. Copy the code main_standby.c in the CCS new project.


2. Build, load, and run the code. The green LED will blink once every three or four seconds.
3. When done, halt the code and click the Terminate button to return to the "CCS Edit".
4. Remove all five jumpers on header J3.
5. The red lead of the multimeter should connect to the top (emulation side) Vcc pin on header J3
and the black lead of the multimeter should connect to the bottom (target side) Vcc pin on
header J3.
6. Press the Reset button on the LaunchPad board.
7. Measure the current drawn by the MSP430G2553

The current consumption in both the active and standby modes operating MSP in various low
power modes is measured while running the application code with a digital multimeter. The
Typical current consumption curve looks like.

Dept. of ECE Page 60


ES Lab (16BT70432) Manual

Compute Power consumption which is VCC * I drawn in various modes.

Experiment No.:11

SPI (MASTER AND SLAVE)


Dept. of ECE Page 61
ES Lab (16BT70432) Manual

AIM : To establish network and handle communication between master and slave launch pads
using code composer studio.

APPARATUS:
 PC Installed with CCSV6
 Launch pads : MSP-EXP430F5529 – 2 Nos.
 USB Cables to interconnect Launch pad to windows enabled PC
 Connecting probes to interconnect master to slave

THEORY:
Universal Serial Communication Interface (USCI):
The MSP430F5529 consists of two Universal Serial Communication Interfaces (USCI) which
support multiple serial communication modes as shown below.

The USCI_Ax modules support:

• UART mode
• Pulse shaping for IrDA communications
• Automatic baud rate detection for LIN communications
• Synchronous SPI mode

The USCI_Bx modules support:

• 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.

• UCxSIMO (Slave In Master Out)


• UCxSOMI (Slave Out Master In)
• UCxCLK USCI SPI clock
• UCxSTE Slave Transmit Enable

Dept. of ECE Page 62


ES Lab (16BT70432) Manual

Fig: Synchronous SPI Mode of USCI

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:

• 7 or 8-bit data length


• LSB-first or MSB-first data transmit and receive
• 3-pin and 4-pin SPI operation
• Master or slave modes
• Independent transmit and receive shift registers
• Separate transmit and receive buffer registers
• Continuous transmit and receive operation
• Selectable clock polarity and phase control
• Programmable clock frequency in master mode
• Independent interrupt capability for receive and transmit
• Slave operation in LPM4

The block diagram for the experiment is as shown in below figure . In this experiment the SPI
master 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.

Fig: Functional Block Diagram

The master-slave connection for SPI communication is shown in Figure 10-3.

Dept. of ECE Page 63


ES Lab (16BT70432) Manual

Fig: Connection Diagram for Master Slave


Communication Using SPI Protocol
FLOWCHART:

MASTER:

Dept. of ECE Page 64


ES Lab (16BT70432) Manual

SLAVE:

PROGRAM:
MASTER:

#include<msp430f5529.h>

unsigned char MST_Data,SLV_Data;

unsigned char temp;

int main (void)

volatile unsigned int i;

Dept. of ECE Page 65


ES Lab (16BT70432) Manual

WDTCTL = WDTPW+WDTHOLD;

// Stop watchdog timer

P1OUT |= 0x02;

P2OUT = BIT1; //Pull-up resistor on P2.1

P2REN = BIT1; //Select pull-up mode for P2.1

P2DIR = 0xFF ^ BIT1; // Set all but P2.1 to output direction

P2IES = BIT1; // P2.1 Hi/Lo edge

P2IFG = 0; // Clear all P2 interrupt flags

P2IE = BIT1; // P2.1 interrupt enabled

// Set P1.0 for LED

// Set P1.1 for slavereset

// P1DIR |= 0x03;

P4DIR |=BIT7;

// Set P1.0-2 to output direction

P3SEL |= BIT3+BIT4;

// P3.3,4 option select

P2SEL |= BIT7;

// P2.7 option select

UCA0CTL1 |= UCSWRST;

// **Put state machine in reset**

UCA0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB;

// 3-pin, 8-bit SPI synchronous master

// Clock polarity high, MSB

UCA0CTL1 |= UCSSEL_2;

Dept. of ECE Page 66


ES Lab (16BT70432) Manual

// SMCLK

UCA0BR0 = 0x02;

UCA0BR1 = 0;

UCA0MCTL = 0;

// No modulation

UCA0CTL1 &= ~UCSWRST;

// **Initialize USCI state machine**

//UCA0IE |= UCRXIE;

// Enable USCI_A0 RX interrupt

P1OUT &= ~0x02;

// Now with SPI signals initialized,

P1OUT |= 0x02;

// Initialize data values

// SLV_Data = 0x00;

// USCI_A0 TX buffer ready?

//UCA0TXBUF = MST_Data;

// Transmit first character

__bis_SR_register(LPM0_bits + GIE);

// CPU off, enable interrupts

#pragma vector = PORT2_VECTOR

__interrupt void port2(void)

P2IES ^= BIT1; // Toggle interrupt edge

P2IFG &= ~BIT1; // Clear P2.1 IFG

Dept. of ECE Page 67


ES Lab (16BT70432) Manual

P4OUT^=BIT7;

MST_Data = 0x01;

UCA0IE |= UCTXIE;

__bis_SR_register(LPM0_bits | GIE); // CPU off, enable interrupts

#pragma vector=USCI_A0_VECTOR

__interrupt void USCI_B0_ISR(void)

P1OUT|=BIT0;

UCA0TXBUF = MST_Data; // Transmit characters

UCA0IE &= ~UCTXIE;

__bic_SR_register_on_exit(LPM0_bits); // Wake up to setup next TX

SLAVE :

#include <msp430.h>

int main(void)

WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer

while(!(P2IN&0x80)); // If clock sig from mstr stays low,

// it is not yet in SPI mode

P3SEL |= BIT3+BIT4; // P3.3,4 option select

P2SEL |= BIT7; // P2.7 option select

UCA0CTL1 |= UCSWRST; // **Put state machine in reset**

UCA0CTL0 |= UCSYNC+UCCKPL+UCMSB; // 3-pin, 8-bit SPI slave,

Dept. of ECE Page 68


ES Lab (16BT70432) Manual

// Clock polarity high, MSB

UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**

UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt

__bis_SR_register(LPM4_bits + GIE); // Enter LPM4, enable interrupts

// Echo character

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)

#pragma vector=USCI_A0_VECTOR

__interrupt void USCI_A0_ISR(void)

#elif defined(__GNUC__)

void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)

#else

#error Compiler not supported!

#endif

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;

}}

Dept. of ECE Page 69


ES Lab (16BT70432) Manual

Experiment No.:12

MSP AS IOT DEVICE USING CC3100

AIM : To Scan available networks for enabling MSP as IOT to print the Wifi MAC address, and scans
for available Wi-fi networks once for every 10 seconds.

APPARATUS:
 PC Installed with Energia
 Launch pads : MSP-EXP430F5529
 CC3100 WiFi booster pack
 USB Cables to interconnect Launch pad to windows enabled PC

THEORY:
To interconnect MSP launchpad with internet it can be done by stacking CC3100 WIFI launch
pad over it. This code in Energia checks for near by active WIFI networks for accessing MSP
using internet using SPI.

PROGRAM:
#include <SPI.h>

#endif

#include <WiFi.h>

void setup() {

//Initialize serial and wait for port to open:

Serial.begin(115200);

WiFi.init();

Serial.println(WiFi.firmwareVersion());

// Print WiFi MAC address:

printMacAddress();

Dept. of ECE Page 70


ES Lab (16BT70432) Manual

// scan for existing networks:

Serial.println("Scanning available networks...");

listNetworks();

void loop() {

delay(10000);

// scan for existing networks:

Serial.println("Scanning available networks...");

listNetworks();

void printMacAddress() {

// the MAC address of your Wifi

byte mac[6];

// print your MAC address:

WiFi.macAddress(mac);

Serial.print("MAC: ");

Serial.print(mac[5], HEX);

Serial.print(":");

Serial.print(mac[4], HEX);

Serial.print(":");

Serial.print(mac[3], HEX);

Serial.print(":");

Serial.print(mac[2], HEX);

Serial.print(":");

Serial.print(mac[1], HEX);

Serial.print(":");

Serial.println(mac[0], HEX);

Dept. of ECE Page 71


ES Lab (16BT70432) Manual

void listNetworks() {

// scan for nearby networks:

Serial.println("** Scan Networks **");

int numSsid = WiFi.scanNetworks();

if (numSsid == -1)

Serial.println("Couldn't get a wifi connection");

while (true);

// print the list of networks seen:

Serial.print("number of available networks:");

Serial.println(numSsid);

// print the network number and name for each network found:

for (int thisNet = 0; thisNet < numSsid; thisNet++) {

Serial.print(thisNet);

Serial.print(") ");

Serial.print(WiFi.SSID(thisNet));

Serial.print("\tSignal: ");

Serial.print(WiFi.RSSI(thisNet));

Serial.print(" dBm");

Serial.print("\tEncryption: ");

printEncryptionType(WiFi.encryptionType(thisNet));

void printEncryptionType(int thisType) {

Dept. of ECE Page 72


ES Lab (16BT70432) Manual

// read the encryption type and print out the name:

switch (thisType) {

case ENC_TYPE_WEP:

Serial.println("WEP");

break;

case ENC_TYPE_TKIP:

Serial.println("WPA");

break;

case ENC_TYPE_CCMP:

Serial.println("WPA2");

break;

case ENC_TYPE_NONE:

Serial.println("None");

break;

case ENC_TYPE_AUTO:

Serial.println("Auto");

break;

Dept. of ECE Page 73

You might also like