tisoftware-dl.ti.com/trainingtto/trainingtto_public_sw...msp430 4xx one day workshop 2010 msp430 one...

174
TI MSP430 4xx One Day Workshop 2010 Student Guide Revision 3.2 January 2010 Technical Training Organization

Upload: others

Post on 24-Jun-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

TI

MSP430 4xx One Day Workshop 2010

Student Guide

Revision 3.2 January 2010

Technical Training Organization

Page 2: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Important Notice

Important Notice Texas Instruments and its subsidiaries (TI) reserve the right to make changes to their products or to discontinue any product or service without notice, and advise customers to obtain the latest version of relevant information to verify, before placing orders, that information being relied on is current and complete. All products are sold subject to the terms and conditions of sale supplied at the time of order acknowledgment, including those pertaining to warranty, patent infringement, and limitation of liability.

TI warrants performance of its semiconductor products to the specifications applicable at the time of sale in accordance with TI’s standard warranty. Testing and other quality control techniques are utilized to the extent TI deems necessary to support this warranty. Specific testing of all parameters of each device is not necessarily performed, except those mandated by government requirements.

Customers are responsible for their applications using TI components.

In order to minimize risks associated with the customer’s applications, adequate design and operating safeguards must be provided by the customer to minimize inherent or procedural hazards.

TI assumes no liability for applications assistance or customer product design. TI does not warrant or represent that any license, either express or implied, is granted under any patent right, copyright, mask work right, or other intellectual property right of TI covering or relating to any combination, machine, or process in which such semiconductor products or services might be or are used. TI’s publication of information regarding any third party’s products or services does not constitute TI’s approval, warranty or endorsement thereof.

Copyright © 2005, 2010 Texas Instruments Incorporated

Revision History Version 2.00 September 2007 TTO release of workshop

Version 2.10 January 2008 Errata

Version 2.20 May 2008 Errata

Version 3.0 March 2009 Include MSP430F5xx and CCS 4.0, general update

Version 3.1 October 2009 Additional 5xx material, general update

Version 3.2 January 2010 Update to CCS4.1

Mailing Address Texas Instruments Training Technical Organization 7839 Churchill Way, M/S 3984 Dallas, Texas 75251-1903

ii MSP430 One Day Workshop - Cover Page

Page 3: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 One Day Workshop - Introduction 1 - 1

Introduction

Introduction In this section we’ll take a look at the MSP430 architecture, instructions, and tools and give you a chance to get some hands-on time with the hardware and software with a lab using the MSP430F2013. We’ll also learn about the I/O and do another lab using the MSP430FG4618/9.

Objectives • Overview

• TI Embedded Processor Portfolio

• Architecture

• Tools

• Introduction lab

• I/O

• I/O lab

Page 4: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

1 - 2 MSP430 One Day Workshop - Introduction

*** This page intentionally left blank ***

Page 5: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

MSP430 One Day Workshop - Introduction 1 - 3

MSP430 4xx One Day Workshop 2010 Introduction ............................................................................................................................................... 1-1

MSP430 4xx One Day Workshop 2010................................................................................................... 1-3 TI Microcontroller Portfolio ............................................................................................................... 1-5 MSP430 Generations.......................................................................................................................... 1-5 MSP430 Peripheral Overview ............................................................................................................ 1-6 MSP430 Portfolio ............................................................................................................................... 1-6 LCD Controllers ................................................................................................................................. 1-7 USB .................................................................................................................................................... 1-8 CC430................................................................................................................................................. 1-9 Innovative Peripherals ........................................................................................................................ 1-9 FRAM................................................................................................................................................1-10 No-Power Apps .................................................................................................................................1-10 Key Family Features..........................................................................................................................1-11 The Nuts and Bolts ............................................................................................................................1-13 Embedded Emulation ........................................................................................................................1-17 Innovative Tools ................................................................................................................................1-18 eZ430-Chronos ..................................................................................................................................1-18 Code Composer Studio V4 ................................................................................................................1-19 IAR Systems......................................................................................................................................1-19 IAR Kickstart.....................................................................................................................................1-20 Third Party Resources .......................................................................................................................1-20 www.ti.com/msp430..........................................................................................................................1-21 Community Support ..........................................................................................................................1-21 MSP430 Summary.............................................................................................................................1-22 Reset Conditions................................................................................................................................1-22 Experimenter’s Board........................................................................................................................1-23

Lab 1 – Flash the LED...........................................................................................................................1-25 Hardware list: ....................................................................................................................................1-26 Software list:......................................................................................................................................1-26

IAR Kickstart Procedure........................................................................................................................1-27 Install IAR Kickstart..........................................................................................................................1-27 Hardware Verification .......................................................................................................................1-29 Power jumpers ...................................................................................................................................1-30 IAR Kickstart.....................................................................................................................................1-31 Configuring the Project .....................................................................................................................1-31 Create and Add the Source File .........................................................................................................1-32 Download and Run the Program........................................................................................................1-33 FLASH Programming Exercise.........................................................................................................1-34

CCS 4.1 Procedure ................................................................................................................................1-35 Install Code Composer Studio ...........................................................................................................1-35 Hardware Verification .......................................................................................................................1-38 Power jumpers ...................................................................................................................................1-39 CCS 4.1 .............................................................................................................................................1-40 Configuring the Target ......................................................................................................................1-41 Understanding the IDE Display.........................................................................................................1-42 Create and Add a Source File ............................................................................................................1-43 Download and Run the Program........................................................................................................1-44 FLASH Programming Exercise.........................................................................................................1-45

Standard Definitions ..............................................................................................................................1-47 Controlling GPIO Ports .....................................................................................................................1-47

Page 6: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

1 - 4 MSP430 One Day Workshop - Introduction

Lab 2 – I/O Overview.............................................................................................................................1-49 Hardware list: ....................................................................................................................................1-50 Software list:......................................................................................................................................1-50

IAR Kickstart Procedure........................................................................................................................1-51 New Workspace and Project..............................................................................................................1-51 Configure the Project.........................................................................................................................1-51 Add Source File .................................................................................................................................1-51 Complete the Code ............................................................................................................................1-52 Test Your Code..................................................................................................................................1-54

CCS 4.1 Procedure ................................................................................................................................1-57 Add a Source File ..............................................................................................................................1-58 Complete the Code ............................................................................................................................1-58 Test Your Code..................................................................................................................................1-60

Review Questions ...................................................................................................................................1-62

Page 7: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

MSP430 One Day Workshop - Introduction 1 - 5

TI Microcontroller Portfolio

TI Embedded Processing Portfolio

MSP430 Generations …

32-bitReal-time

C2000™Fixed &

Floating Point

Up to 150 MHz

Flash32 KB to 512 KB

PWM, ADC, CAN, SPI, I2 C

Motor Control, Digital Power,

Lighting

$1.50 to $20.00

32-bit ARM

Stellaris M3Industry StdLow Power

Up to 100 MHz

Flash8kB to 256kB

USB (H/D/OTG),ENET(PHY, 1588), ADC, PWM, QVGA

Host Control

$2.00 to $8.00

16-bit

Microcontrollers

MSP430Ultra-Low

Power

Up to 25 MHz

Flash1 KB to 256 KB

Analog I/O, ADCLCD, USB, RF

Measurement,Sensing, General

Purpose

$0.49 to $9.00

DSP

C647x, C64x+, C55x

Leadership DSP Performance

24,000 MMACS

Up to 3 MBL2 Cache

1G EMAC, SRIO,DDR2, PCI-66

Comm, WiMAX, Industrial/

Medical Imaging

$4.00 to $99.00+

ARM+

ARM9Cortex A-8

Industry-Std Core,High-Perf GPP

Accelerators

MMU

USB, LCD,MMC, EMAC

Linux/WinCE User Apps

$8.00 to $35.00

DSP

C64x+ plusARM9/Cortex A-8Industry-Std Core +DSP for Signal Proc.

4800 MMACs/1.07 DMIPS/MHz

MMU, Cache

VPSS, USB, EMAC, MMC

Linux/Win +Video, Imaging,

Multimedia

$12.00 to $65.00

ARM + DSP

ARM-Based

Software & Dev. Tools

MSP430 Generations

MSP430 Generations2xx 4xx 5xx

CPU Clock (Max) 16MHz 8 & 16 MHz 25MHzFlash/RAM (Largest comparable device) 120KB / 4KB (F24xx) 120KB / 4KB

(FG46xx) 256KB / 16KB (F54xx)

Active Current (3.0V)µA/MIPS

1MHz 515 µA 600 µA 220µA8MHz 525 µA/MIPS 600 µA/MIPS 165 µA/MIPS16MHz 569 µA/MIPS N/A 188 µA/MIPS25MHz N/A N/A 224 µA/MIPS

Standby Current (LPM3) 0.3 – 1.1µA 0.7 – 1.3µA 2.6µA (w/ active true RTC) Power Down Current (LPM4/5) 0.1µA 0.1µA 1.6µA (LPM4) / 0.1µA

(LPM5)Wake-up Time From LPM3 1µs 6µs 5µsFlash ISP Minimum DVCC 2.2V 2.7V 1.8V

Port I/O Interrupt Capability P1/P2 P1/P2P1/P2 (F5438)Add’l pins in future devices

Prog. Port Pin Drive Strength N/A N/A All port pinsProg. Pull-ups/-downs All port pins N/A All port pinsAvailable MCLK Sources DCO, VLO, LFXT1,

XT2FLL, LFXT1, XT2 FLL, VLO, REFO, XT1, XT2

FLL Reference Clocks N/A LFXT1 REFO, XT1, XT2

Lowest active

power in the

industry

Lowest active

power in the

industry

Lowest stand-by

and fastest

wakeup

Write to Flash at min Vcc

MSP430 Peripheral Overview …

Page 8: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

1 - 6 MSP430 One Day Workshop - Introduction

MSP430 Peripheral Overview

MSP430 Peripheral Overview

1xx 2xx 4xx 5xxBasic Clock System Basic Clock System + FLL, FLL+ Unified Clock SystemCore voltage same as supply voltage (1.8-3.6V)

Core voltage same as supply voltage (1.8-3.6V)

Core voltage same as supply voltage (1.8-3.6V)

Programmable core voltage with integrated PMM (1.8-3.6V)

16-bit CPU 16-bit CPU, CPUX 16-bit CPU, CPUX 16-bit CPUXv2GPIO GPIO w/ pull-up and

pull-downGPIO, LCD Controller GPIO w/pull-up

and pull-down, drive s trength

N/A N/A N/A CRC16Software RTC Software RTC Software RTC with

Bas ic Timer, Basic Timer + RTC

True 32-bit RTC w/Alarms

USART USCI, USI USART, USCI USCI, USB, RFD MA up to 3-ch DMA up to 3-ch DMA up to 3-ch DMA up to 8-chMPY16 MPY16 MPY16, MPY32 MPY32ADC10,12 ADC10,12, SD16 ADC12, SD16, OPA ADC12_A4-wire JTAG 4-wire JTAG, 2-wire

Spy Bi-Wire (Some devices)

4-wire JTAG 4-wire JTAG, 2-wire Spy Bi-Wire

MSP430 portfolio …

MSP430 Portfolio

MSP430 Portfolio

100+ devices2xx-Catalog• 16 MIPS• 120 kB F lash• 8 kB RAM• 500 nA Standb y• 1.8 – 3.6V

75+ devices1xx-Catalog• 8M IPS• 60 kB F lash• 10 kB RAM• 1.8 – 3.6 V

F = FlashC = ROMFR = FRAM

100+ devices4xx: LCD• 16 M IPS• 120 kB F lash• 8 kB RAM• LCD Con tro ller, 160

segments• 1.8 – 3.6V

F23x0

The New Generation5xx-6xx• 25MIPS• 256 kB Flash• 16 kB RAM• 1.8 – 3.6V• FRAM, USB, RF• 6xx: LCD Co ntroller• 160 u A/MIPS

PerformanceGateway

Device

F23x-F24x

F261xF241x

F R1000

F20xxF21x1

F21x2F22xx

F23x0

F13x-F14xF15x-F16x

F541xF 543x

F/C11xxF12xx

CC430RF

F550x USB

F552xUSB

Fx42x0Fx42x

F44xFx43x

F/CG461x

FE42x2F/C41x

F 47x4Fx47x

F41x2

F 471xx

LCD controllers …

Page 9: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

MSP430 One Day Workshop - Introduction 1 - 7

LCD Controllers

LCD Controllers

Ultra-low powerFully automatic4/3/2/1 muxUp to 160-bit displayInternal regulated voltage generatorInternal or external bias generationContrast control1/2 bias for 3 or 4 muxInternal clock generationAuto segment blinking

Segm entOutputControl

AnalogVoltage

MultiplexerTiming GeneratorR23

R13

R03

COM0

COM2COM1

R33/LCDCAP

COM3

S0S1

S39

S38

ACLK

NotRequired

Rx

R

R

R

Dis playMemory

20x8-b its

CommonOutputControl

Charge PumpContrast Control

BiasGenerator

USB …

Page 10: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

1 - 8 MSP430 One Day Workshop - Introduction

USB

Enabling You with Full Speed USB

Ultra-low power MCUs + USB for smarter connectivity

Analog and peripheral integration reduces system cost

44 New USB devices within next 12 months

• Embedded full-speed USB 2.0 (12 Mbps)• High flexibility with configurable 2K data buffers that can be used as RAM• Unused USB interface pins can function as high-current I/O (5v tolerant)

• Multiple analog options with 10 or 12-bit ADC, DAC, comparator • Integrated 3.3V LDO for use with 5V USB bus power• Uses low-cost crystal for USB clock, with flexible, integrated PLL

• Wide range of memory configurations and package options, 8k-128k flash• Diverse peripheral mix in the MSP430F55xx family• Pricing as low a $0.96 in volume

USB made easy …

USB Made EasyUSB Bootstrap Loader (USB)

Supporting device programming Field Firmware updates

USB Descriptor ToolConfigures stack functions via GUI

Free USB stacks available:Communication Device Class (CDC) Human Interface Device (HID) Mass Storage Class (MSC)

Additional stacks available from third parties

FREE Vendor ID/ Product ID

sharing program

FREE Vendor ID/ Product ID

sharing program

MSP430F5529 Sample Kit

CC430 …

Page 11: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

MSP430 One Day Workshop - Introduction 1 - 9

CC430

CC430: Enabling You With RF

CC430

MSP430MCU

Application and protocol

processor

Lowest Power MonolithicRF SoC

Low Power RFRadio frequency

The Best of Both Worlds

MSP430 MCU• Market’s lowest power MCU• High analog performance• High level of integration• Ease of development• Sensor interface

Low Power RF Transceiver• High sensitivity• Low current consumption• Excellent blocking performance• Flexible data rate & modulation format• Backwards compatible

Innovative peripherals …

Innovative Peripherals

LCD_B

Comparator_B

CC430: Innovative Peripherals

• Blinking of individual segments, Programmable frame frequency, Software-driver contrast control

• Regulated charge pump• Integrated drivers

AES 128• Encryption and decryption according to AES FIPS PUB 197 with 128-bit keys

• Key expansion for en- and decryption• Off-line key generation for decryption

• Selectable reference voltage & voltage hysteresis generator • High-speed, normal, and ultra-low power 100nA modes • Internal output to Timer A capture• Selectable RC filter for comparator output

FRAM …

Page 12: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

1 - 10 MSP430 One Day Workshop - Introduction

FRAM

FRAM: The Future of MCU MemoryNon-volatile, Reliable Storage

Over 100 Trillion write/read cyclesWrite Guarantee in case of power loss

Fast write times like SRAM~50ns per byte or word1,000x faster than Flash/EEPROM

Low PowerOnly 1.5v to write & erase >10-14v for Flash/EEPROM

Universal Memory Photo: Ramtron Corporation

No-power apps …

No-Power Apps

MSP430 Enables No-Power Apps

Energy harvesting is the process by which energy is captured and stored

Can substitute batteries that are costly to maintain and can extend system uptime

Only possible with ultra-low power components

Solar, kinetic, thermal, RF, salinity gradients, pH difference and other ambient sources available

Body warn monitoring

devices powered by body heat,

movement

Monitor environmental condit ions on farm, winery,

etc.

Mesh networking for environmental

monitoring (e.g. forest f ire detection)

Automotive monitoring (e.g.

tire pressure gauges powered

by vibration)

F2xx key features …

Page 13: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

MSP430 One Day Workshop - Introduction 1 - 11

Key Family Features

F2xx Key Features

<1µA standby LPM3<1µs 0-16MHzZero-power BORFailsafe oscillatorEnhanced watchdogPull-up / down resistorsHack proof boot loader2.2V Flash ISPExtended temp 105°CSame instruction set

architecture

F4xx key features …

F4xx Key Features

<1µA standby LPM3<1µs 0-16MHz4-120 KB FlashBuilt-in LCD DriverZero-power BORPull-up / down resistors2.7V Flash ISPSame instruction set architecture

F5xx key features …

Page 14: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

1 - 12 MSP430 One Day Workshop - Introduction

F5xx Key FeaturesUltra-Low Power

160 µA/MIPS2.5 µA standby modeIntegrated LDO, BOR, WDT+, RTC12 MHz @ 1.8VWake up from standby in <5 µs

Increased PerformanceUp to 25 MHz1.8V ISP Flash erase and writeFail-safe, flexible clocking systemUser-defined Bootstrap LoaderUp to 1MB linear memory addressing

Innovative FeaturesMulti-channel DMA supports data movement in standby modeIndustry leading code densityMore design options including USB, RF, encryption, LCD interface

P o w e r M a n a g e m e n tM o d u le

S u p p ly S u p e rv i s o rsS u p p l y M o n i t o rs

B r o w n o u t

U n i fie d C lo c kS y s t e m

J T A GS p y B i - W ir e

In t e r fa c e

E n h a n c e d E m b e d d e d E m u la tio n

1 6 - b i t R IS C C P U

S y s t e m C o n t ro l /

W a t c h d o g

D M A C o n t ro l le r

R A M

H a r d w a r e 3 2 x 3 2

M u l t ip l ie r

C R C

A E C

G en e r a l P u r p os e T im e r s C a p tu re /C o m p a re P W M

O u tp u ts

B a s ic T im e r+

RT CA D C

D A C

O p e r a tio n a l A m p l i fie r s

C o m p a r a to r sUn iv e rs a l S e r ia l Co m m u n i c at io n

In te rfa c e s( S P I , U AR T , I2 C )

U S B 2 . 0 ( F u l l S p e e d )

E n g i n e + P H Y

R F T ra n s c e iv e rs

G e n e r a l P u rp o s e I /O ,

P u l l -U p /Do w n , H ig h D ri v e

S e g m e n t e d L CD , S ta ti c ,

M u x e d

C o m p u t a t io n T im in g a n d C o n tr o l S ig n a l C h a i n C o m m u n ic a t io n I /O & D is p la y

M S P 4 3 0 F 5 x x B lo c k D i a g ra m

Fla s h

RISC CPU …

Page 15: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

MSP430 One Day Workshop - Introduction 1 - 13

The Nuts and Bolts

16-bit RISC CPU

Efficient, ultra-low power CPUC-compiler friendlyRISC architecture

27 core instructions24 emulated instructions7 addressing modesConstant generator

Single-cycle register operationsMemory-to-memoryatomic addressingBit, byte and word processing20-bit addressing on MSP430X for Flash >64KB

Bytes, Words and CPU Registers …

16-bit addition Code/Cycles5405 add.w R4,R5 ; 1/1529202000202 add.w &0200,&0202 ; 3/6

8-bit addition5445 add.b R4,R5 ; 1/152D202000202 add.b &0200,&0202 ; 3/6

16-bit addition Code/Cycles5405 add.w R4,R5 ; 1/1529202000202 add.w &0200,&0202 ; 3/6

8-bit addition5445 add.b R4,R5 ; 1/152D202000202 add.b &0200,&0202 ; 3/6

Bytes, Words And CPU Registers

Use CPU registers for calculations and dedicated variablesSame code size for word or byteUse word operations when possible

Seven addressing modes …

Page 16: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

1 - 14 MSP430 One Day Workshop - Introduction

Register Mode mov.w R10,R11Single cycle

Indexed Mode mov.w 2(R5),6(R6)Table processing

Symbolic Mode mov.w EDE,TONIEasy to read code, PC relative

Absolute Mode mov.w &EDE,&TONIDirectly access any memory

Indirect Register Mode mov.w @R10,0(R11)Access memory with pointers

Indirect Autoincrement mov.w @R10+,0(R11)Table processing

Immediate Mode mov.w #45h,&TONIUnrestricted constant values

Seven Addressing Modes

Atomic

Atomic addressing …

Non-interruptible memory-to-memory operationsUseable with complete instruction set

MemoryB

; MSP430add A,B

; MSP430add A,B

; Pure RISCpush R5ld R5,Aadd R5,Bst B,R5pop R5

; Pure RISCpush R5ld R5,Aadd R5,Bst B,R5pop R5

A

Atomic Addressing

B=B+A

Constant generator …

Page 17: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

MSP430 One Day Workshop - Introduction 1 - 15

Immediate values -1,0,1,2,4,8 generated in hardwareReduces code size and cyclesCompletely automatic

4314 mov.w #0002h,R4 ; With CG

40341234 mov.w #1234h,R4 ; Without CG

4314 mov.w #0002h,R4 ; With CG

40341234 mov.w #1234h,R4 ; Without CG

Constant Generator

Emulated instructions …

24 Emulated Instructions

Easier to understand - no code size or speed penaltyReplaced by assembler with core instructionsCompletely automatic

4130 ret ; Return (emulated)

4130 mov.w @SP+,PC ; Core instruction

4130 ret ; Return (emulated)

4130 mov.w @SP+,PC ; Core instruction

Assembly instruction formats …

Page 18: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

1 - 16 MSP430 One Day Workshop - Introduction

Format I Source and Destination

add.w R4,R5 ; R4+R5=R5 xxxxadd.b R4,R5 ; R4+R5=R5 00xx

Format II Destination Only

rlc.w R4 rlc.b R4

Format III 8(Un)conditional Jumps

jmp Loop_1 ; Goto Loop_1

Three Assembly Instruction Formats

Instruction list …

Format I Source, Destination

Format II Single Operand

Format III +/- 9bit Offset

Support

add(.b) br jmp clrc addc(.b) call jc setc and(.b) swpb jnc clrz bic(.b) sxt jeq setz bis(.b) push(.b) jne clrn bit(.b) pop(.b) jge setn cmp(.b) rra(.b) jl dint dadd(.b) rrc(.b) jn eint mov(.b) inv(.b) nop sub(.b) inc(.b) ret subc(.b) incd(.b) reti xor(.b) dec(.b) decd(.b) adc(.b) sbc(.b) clr(.b) dadc(.b) rla(.b) rlc(.b) tst(.b)

51 Total Assembly Instructions

Bold type denotes emulated instructionsUnified memory map …

Page 19: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

MSP430 One Day Workshop - Introduction 1 - 17

Unified Memory Map

Absolutely no pagingSupports code agilityIn System Programmable (ISP) Flash

Self programmingJTAGBootloader

FLASH

Main Segments(x) 512B

Boot Loader

RAM

Info Segments

Peripherals

Interrupt VectorsFFFF

0000

// Flash In System ProgrammingFCTL3 = FWKEY; // UnlockFCTL1 = FWKEY | WRT; // Enable*(unsigned int *)0xFC00 = 0x1234;

// Flash In System ProgrammingFCTL3 = FWKEY; // UnlockFCTL1 = FWKEY | WRT; // Enable*(unsigned int *)0xFC00 = 0x1234;

Embedded Emulation

Embedded Emulation

Embedded Emulation

Real-time, in-system debugNo application resources usedFull speed execution H/W breakpoints Single steppingComplex triggeringTrace capability

Powerful, easy to use toolsSpy Bi-Wire

2-wire debug interfaceNo pin function impact

Only 1 tool required for all devices

JTAG

Tools …

Page 20: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

1 - 18 MSP430 One Day Workshop - Introduction

Innovative Tools

Easy To Use, Innovative Tools

MSP430 Experimenter Boards• Fully featured prototyping system• Available for FG4618 & F5438• Starting at $99

eZ430 Tools• Complete development system in USB stick

• Available for wireless and energy harvesting

• Starting at $20

Flash Emulation Tools• Compatible with all devices• Target boards available • $99 ($149 with target board)• Target boards available without FET• Free IDEs included

Chronos …

eZ430-Chronos

eZ430-Chronos: CC430 Dev Tool

CC430-based wirelessdevelopment tool in a watch915/868/433 MHz versions availableCustom LCD driven directly by CC430Features:

3-axis accelerometerAltimeterTemperature sensorBuzzer

USB RF access point

Updated eZ430 emulator for programming

CCS v4 …

Page 21: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

MSP430 One Day Workshop - Introduction 1 - 19

Code Composer Studio V4

CCE is now Code Composer Studio v4

Code Composer Studio v4: A single development platform for all TI processorsCCE users will feel at homeEnhancements since CCE:

SpeedCode size improvementsAuto-updatingLicense managerSupport for all TI MCUs

Only $495 for MCU EditionFREE 16KB-limited edition

IAR …

IAR Systems

TI and IAR Systems:Deep and Evolving Partnership

TI and IAR Systemspartners on MSP430

TI acquires Chipcon,partner  to IAR Systems

TI acquires Luminary Micro,partner to IAR Systems

TI and IAR partnerson ARM MCU’s

1990 ’s 2005 2006 2009

TI and IAR Systems Product Integration and SupportTI and IAR Systems Product Integration and Support

IAR KickStart  KitsCompletelyintegrated kits

IAR KickStart  KitsCompletelyintegrated kits

IAR PowerPacRTOSFile SystemUSB Device StackTCP/IP stack

IAR PowerPacRTOSFile SystemUSB Device StackTCP/IP stack

IAR v isualSTATEdesign, test and verificat ion tools using state machines

IAR v isualSTATEdesign, test and verificat ion tools using state machines

IAR Embedded WorkbenchC/C++ compiler  and debugger  tool  set

IAR Embedded WorkbenchC/C++ compiler  and debugger  tool  set

TI MSP430 microcontrollersTI MSP430 microcontrollers

TI Stellaris microcontrollersTI Stellaris microcontrollers

RF/IF  and ZigBee  SolutionsRF/IF  and ZigBee  Solutions

IAR kickstart …

Page 22: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

1 - 20 MSP430 One Day Workshop - Introduction

IAR Kickstart

IAR Kickstart IDE

4kB Compiler(8kB for >60k Flash devices)Assembler/LinkerEditorDebugger

Third parties …

Third Party Resources

Rowley CrossWorksComplete IDE solution High code densitySimulatorWindows, Linux, Mac

www.rowley.co.uk

Third Party Development ResourcesElprotronic

MSP430, CC Chipcon, C2000 ProgrammersFastest download speedProduction programmers

RTOS OptionsµC/OS-II™CMX-Tiny+™embOSFreeRTOS™IAR PowerPacQP™Salvo™TinyOS

MSPGCC Tool ChainFree Open SourceGNU C Compiler, Assembler/ Linker, GDB DebuggerWindows, Linux, Unix

http://mspgcc.sourceforge.net

Amber WirelessDrop in wireless modules<1GHZ eZ430-RF target boardsCC430 Development boards

USB StacksIARHCC

ti.com/msp430 …

Page 23: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

MSP430 One Day Workshop - Introduction 1 - 21

www.ti.com/msp430

www.ti.com/msp430

User’s GuidesDatasheetsTI Community Forum100+ Application Reports1000+ Code ExamplesProduct BrochureMCU Selection ToolLatest Tool Software3rd Party Listing

Silicon Errata

Community support …

Community Support

Videos, Blogs, ForumsExtensive community support and idea exchangeGlobal customer supporthttp://e2e.ti.com

Growing collection of technical wiki articlesTips & tricks, common pitfalls, and design ideashttp://wiki.msp430.com

Extensive Community Support

E2E Community Processor Wiki

Summary …

Page 24: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

1 - 22 MSP430 One Day Workshop - Introduction

MSP430 Summary

MSP430 Summary

Ultra-low Power

Broad portfolioAccess for size and cost constraintsPerformance for precision and speed

Enabling TechnologiesFRAM, USB, RF, energy harvesting

Ease of UseHW and SW ToolsCommunity

Reset …

Reset Conditions

Reset Conditions

RST/NMI configured in the reset modeAll I/O pins are switched to inputWatchdog timer powers up as active watchdogOther peripheral modules are disabledStatus register (SR) is resetProgram counter (PC) is loaded with (0FFFEh)Always refer to the user guide for information specific to your device

FLASHClock

DigitalPeripheral

RISCCPU

16-bit

MAB 16

MDB 16

RAM

AnalogPeripheral

. . .

. . .ACLK

SMCLK

JTA

G/D

ebug

Board

Page 25: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

MSP430 One Day Workshop - Introduction 1 - 23

Experimenter’s Board

MSP430FG461x/F20xx Experimenter’s Board

Two MSP430 devices:MSP430FG4618 orMSP430FG4619MSP430F2013

Interface for ChipConRF transceiver EMKboards

Lab1 …

Page 26: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

MSP430 4xx One Day Workshop 2010

1 - 24 MSP430 One Day Workshop - Introduction

*** ***

Page 27: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab 1 – Flash the LED

MSP430 One Day Workshop - Introduction 1 - 25

Lab 1 – Flash the LED Let’s familiarize ourselves with the lab equipment and then move on to performing a simple task: flashing the LED using the F2013.

Lab1: Flash the LED

FET

Blink the LED with assembly code running on the F2013

Standard Definitions …

There are two sets of instructions for the labs; one using the IAR Kickstart IDE and the other using TI’s Code Composer Studio 4.1. Decide which IDE you’d like to use and then team up with a partner using the same IDE.

Page 28: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab 1 – Flash the LED

1 - 26 MSP430 One Day Workshop - Introduction

Hardware list: WinXP PC

MSP-FET430UIF

USB cable

JTAG ribbon cable

MSP430FG461x/F28xx Experimenter’s Board

Jumpers

Software list: IAR Kickstart for MSP430 version 4.21B

Code Composer Studio 4.1

Labs

Additional pdf documentation

Adobe™ Reader

Page 29: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

MSP430 One Day Workshop - Introduction 1 - 27

IAR Kickstart Procedure In this lab, you will verify that the hardware/software has been set up properly. We’ll also familiarize ourselves with the tools we’ll be using for the rest of the workshop via a short program running on the F2013.

Install IAR Kickstart 1. Disconnect any evaluation board that you have connected to your PCs USB port(s).

Insert the Workshop Installation Flash Drive into a free USB port.

2. Using Windows Explorer, find and double-click on the file named EW430-KS-web-4212.exe.

3. Follow the steps in the IAR installation program. When you reach the Enter User Information window, use Windows Explorer to find and open the IAR Li-cense.txt file on the installation flash drive. Copy/paste the license number as shown below and click Next.

Page 30: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

1 - 28 MSP430 One Day Workshop - Introduction

4. In the same way, copy/paste the License Key into the next window and click Next.

Select a Complete installation and click Next. Install the tools into the default folder, if possible. The installation should take less than 10 minutes to complete.

5. Driver Installation Using Windows Explorer, look on the workshop flash drive and double-click on swrc094e setup. Follow the wizard steps until it completes. Again using Win-dows Explorer, navigate to C:\Program Files\Texas Instruments Inc\TUSB3410 Single Driver Installer\DISK1 and double-click on setup. Fol-low the wizard steps until it completes.

6. Lab Files Installation Using Windows Explorer, look on the workshop flash drive and double-click on all_labs.exe. Leave the unzip directory as C:\ and click Unzip. When the process completes, click Close. The labs have been placed in C:\MSP430ODW. If you’ve been tasked with installing IAR Kickstart, the drivers and labs only, please stop here and ask your instructor for further directions.

Page 31: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

MSP430 One Day Workshop - Introduction 1 - 29

Hardware Verification 1. Check out the hardware

Make sure that the MSP430 USB FET is connected to the USB cable and that the other end of the cable is connected to the PC’s USB port. The ribbon cable should be connected to the debug interface at one end to the port marked Target and to the lower of the two debug ports on the MSP430FG461x/F28xx Experimenter’s Board (the MSP430F2013 emulation port).

2. Software driver

If you are prompted to load the driver when you connect the FET to the PC, don’t search the web for the driver and don’t load the driver automatically. You can locate the driver in the C:\Program Files\IAR Systems\Embedded Workbench 5.4 Kickstart\430\drivers\TIUSBFET folder.

MSP430FG4619 JTAG Emulation Port

MSP430F2013 JTAG Emulation Port

Page 32: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

1 - 30 MSP430 One Day Workshop - Introduction

Power jumpers 3. The board has several jumpers that control power to the board …

PWR1

PWR2 and JP2

VCC_1 and VCC_2

ON

OFF

BATT

Make sure the jumpers are set as follows:

PWR1 controls power to the MSP430FG4619 (ON)

PWR2 controls power to the MSP430F2013 (ON)

JP2 isolates the LED from the touch pad (ON)

BATT controls power from the AAA batteries and can be used to measure current (OFF)

VCC_1 and VCC_2 control whether the microcontrollers are powered by the emulator (FET) or the batteries (LCL). Since we’ll be powering from the board from the emulator, place both jumpers over the rightmost two pins as shown:

LCL FET

Page 33: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

MSP430 One Day Workshop - Introduction 1 - 31

IAR Kickstart

4. Start up the IDE

On the desktop of your PC you should see a shortcut that looks like:

Double-click the shortcut to start IAR Kickstart. The IAR Information Center window will appear on top of the IAR tool. Click the X in the upper right to close the window.

5. Create a New Workspace

Click File New Workspace on the menu bar to create a new workspace.

6. Create a New Project

On the menu bar, click Project Create New Project. When the Create New Project dialogue appears, click OK. The Save As dialogue will appear; name your project Lab1 in the C:\MSP430ODW\IAR Labs\Lab1 folder and click Save.

Configuring the Project 7. Set the Project Options

From the IAR Embedded Workbench menu bar, select Project Options.

Under the Target tab, note the Device selection box. Click the drop-menu to the right of this box and select MSP430x2xx Family, then MSP430F2013 from the list.

Still under the Target tab, click Assembler-only project.

In the Category list to the left, click Debugger. Under the Setup tab, select FET Debugger from the Driver drop-down menu.

Select the Plugins tab, and uncheck the box next to Stack.

In the Category list to the left, click FET Debugger. Under the Setup tab, select Texas Instrument USB-IF from the Connection drop-down menu.

Click OK.

Page 34: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

1 - 32 MSP430 One Day Workshop - Introduction

Create and Add the Source File 8. Create the Source File

From the IAR Embedded Workbench menu bar, select File New File. In the untitled editor window that appears, type the following code or you can cut/paste it from the Lab1.txt file included in the Lab1 folder.

To cut/paste, select File Open File from the menu bar. Change the Files of type: to Text Files (*.txt) and select Lab1.txt, then click Open. Cut/Paste to the Untitled1 file in your IAR editor.

#include "msp430x20x3.h" ORG 0F800h ; Program start RESET mov.w #280h,SP ; Stack mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog bis.b #01h,&P1DIR Mainloop xor.b #01h,&P1OUT Delay dec.w R15 jnz Delay jmp Mainloop ORG 0FFFEh ; RESET vector DW RESET END

On the menu bar, click the Save button , name the file Lab1.asm and place it in the C:\MSP430ODW\IAR Labs\Lab1 folder. Click the Save button.

9. Add the File to the Project

From the IAR Embedded Workbench menu bar, select Project Add Files. You may need to change the Files of type to Assembler Files. Highlight Lab1.asm and click Open.

Page 35: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

MSP430 One Day Workshop - Introduction 1 - 33

Download and Run the Program 10. Assemble and Download

Click the Debug button . Clicking this button will assemble the source file in your project and download the executable to the flash memory of the MSP430. You may be prompted to save your workspace. Click Yes, name the workspace Lab1.eww, locate it in the C:\MSP430ODW\IAR Labs\Lab1 folder and click Save.

A Message window will open at the bottom of the IAR tool and will inform you of the status of the build as it runs. Notice the download status as the code is transferred to the MSP430 flash memory. The IAR debugger may ask if you want to update the FET pod firmware; click OK.

11. Run the Program

You should be looking at a screen that looks something like this:

The buttons on the top-left that look like this: control the

running of the code. Click on the Go button to run the code. You should notice that the red LED near the MSP430F2013 debug port is blinking about twice per second.

12. Stop Debugging and Close IAR Kickstart

Click the Stop Debugging button .

From the IAR Embedded Workbench menu bar, click File Exit. If you are prompted to save anything, do so.

Page 36: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

1 - 34 MSP430 One Day Workshop - Introduction

FLASH Programming Exercise 13. Exercise

In the F2xx family, the time to program any bit, byte or word in FLASH is 30/fFTG – where FTG is between 257kHz – 476kHz. This means that the minimum programming time for any random bit, byte or word is 63us.

If FLASH memory is programmed sequentially though, the programming time can be reduced to 18/fFTG.

We’ve provided you with an excerpt from the F2013 datasheet below. Use it to fill in the blanks provided. Remember that 2KB is equal to 1KW, so it makes sense to program in words to reduce programming time.

What is fFTG? ____________ (pick the highest frequency/shortest period)

What is tword? ____________

Calculate the time to program a word or byte ________________________________________

Multiply that by 1024 words _______________________________

We calculated that the time required to program the entire F2013 2KB Flash array as random words is 64.5ms.

IAR Kickstart users … you’re done. Proceed to page 1-41.

Page 37: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

MSP430 One Day Workshop - Introduction 1 - 35

CCS 4.1 Procedure In this lab, you will install Code Composer Studio and verify that the hardware/software has been set up properly. We’ll also familiarize ourselves with the tools we’ll be using for the rest of the workshop via a short program running on the MSP430F2013.

Install Code Composer Studio 7. Disconnect any evaluation board that you have connected to your PCs USB port(s).

Insert the Workshop Installation Flash Drive into a free USB port.

8. Using Windows Explorer, find the setup_CCS_n.n.n.n folder on the Flash drive and double-click on the file named setup_CCS_n.n.n.n.exe.

9. Follow the instructions in the Code Composer Studio installation program. Select the Platinum Edition for installation when the Product Configuration dialog window appears. Click Next.

Page 38: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

1 - 36 MSP430 One Day Workshop - Introduction

10. In the Choose ISA dialog, if you are attending a Stellaris only workshop, make sure that only the Stellaris Cortex-M3 MCU and ARM checkboxes are selected. If you are also attending an MSP430 workshop, check that checkbox too. Click Next.

Page 39: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

MSP430 One Day Workshop - Introduction 1 - 37

11. In the Select Components dialog, uncheck the Target Content and Emulators checkboxes. If you are attending a Stellaris only workshop, click Next. If you are attending a MSP430 workshop too, check the MSP430 USB FET checkbox and click Next. The installation should take less than 10 minutes to complete.

12. Driver Installation Using Windows Explorer, look on the workshop flash drive and double-click on swrc094e setup. Follow the wizard steps until it completes. Again using Win-dows Explorer, navigate to C:\Program Files\Texas Instruments Inc\TUSB3410 Single Driver Installer\DISK1 and double-click on setup. Fol-low the wizard steps until it completes.

13. Lab Files Installation Using Windows Explorer, look on the workshop flash drive and double-click on all_labs.exe. Leave the unzip directory as C:\ and click Unzip. When the process completes, click Close. The labs have been placed in C:\MSP430ODW. If you’ve been tasked with installing Code Composer, the drivers and labs only, please stop here and ask your instructor for further directions.

Page 40: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

1 - 38 MSP430 One Day Workshop - Introduction

Hardware Verification 1. Check out the hardware

Make sure that the MSP430 USB FET is connected to the USB cable and that the other end of the cable is connected to the PC’s USB port.

The ribbon cable should be connected to the debug interface at one end to the port marked Target and to the lower of the two debug ports on the MSP430FG461x/F28xx Experimenter’s Board (the MSP430F2013 emulation port).

MSP430FG4619 JTAG Emulation Port

MSP430F2013 JTAG Emulation Port

Page 41: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

MSP430 One Day Workshop - Introduction 1 - 39

Power jumpers 2. The board has several jumpers that control power to the board …

PWR1

PWR2 and JP2

VCC_1 and VCC_2

ON

OFF

BATT

Make sure the jumpers are set as follows:

PWR1 controls power to the MSP430FG4619 (ON)

PWR2 controls power to the MSP430F2013 (ON)

JP2 isolates the LED from the touch pad (ON)

BATT controls power from the AAA batteries and can be used to measure current (OFF)

VCC_1 and VCC_2 control whether the microcontrollers are powered by the emulator (FET) or the batteries (LCL). Since we’ll be powering from the board from the emulator, place both jumpers over the rightmost two pins as shown:

LCL FET

Page 42: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

1 - 40 MSP430 One Day Workshop - Introduction

CCS 4.1 3. Start up the IDE

On the desktop of your PC you should see a shortcut that looks like this:

Double-click the shortcut to start Code Composer Studio 4.1. The Workspace Launcher window will appear. In the Workspace window, enter C:\MSP430ODW\CCS Labs\Lab1\workspace and click the OK button on the lower right. This will create a workspace folder in the Lab1 folder.

If the Welcome screen appears, close it by clicking on the CCS emblem in the upper right.

4. Create a New Project

On the menu bar, click File New CCS Project. When the New Project dialogue appears, name the project Lab1 and click Next. Note that the location is our Lab1 workspace folder.

In the Select a type of project window, change the project type to MSP430 and click Next.

In the Additional Project Settings window, make no changes and click Next.

In the Project Settings window, change the Device Variant to MSP430F2XXX and select MSP430F2013.

Check the box marked Treat as an Assembly-only project and click Finish.

Page 43: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

MSP430 One Day Workshop - Introduction 1 - 41

Configuring the Target

5. Create a New Target Configuration

From the CCS menu bar, select Target New Target Configuration …

Change the File name to Lab1.ccxml and click Finish.

When the Basic window tab appears, make the change as shown below:

Close the Lab1.ccxml tab by clicking the X on the tab.. When prompted, click Yes to save the changes.

Page 44: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

1 - 42 MSP430 One Day Workshop - Introduction

Understanding the IDE Display 6. Displayed Windows

CCS 4.1 is a highly customizable tool, but your first view of it should look like below:

If the Cheat Sheets pane is open on the right, close it by clicking the X on the tab.

The left hand pane is the Project pane. All of the components; libraries, source files, settings, etc that comprise a project are displayed here. The middle pane is the Workspace pane. When you are editing, the Eclipse editor will be seen here, along with tabs to the files being edited. The Outline pane, on the right displays C/C++ file elements, like structures, etc. Since this project is an assembly project, you can close this pane now by clicking the X in the Outline tab.

Page 45: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

MSP430 One Day Workshop - Introduction 1 - 43

Create and Add a Source File 7. Create a Source File

Right-click in the Project pane and select New Source File. When the New Source File window appears, name the Source File Lab1.asm and click Finish. In the Project pane you’ll see that Lab1.asm is now added to the project and that the file is open for editing in the Workspace pane.

In the Lab1.asm editor window that appears, type the following code or you can cut/paste it from the Lab1.txt file included in the Lab1 folder.

To cut/paste, select File Open File … from the menu bar. Navigate to: C:\MSP430ODW\CCS Labs\Lab1, select Lab1.txt, and then click Open. Cut/Paste to the Lab1.asm editor window.

.cdecls C,LIST,"msp430x21x1.h" ; Device header file .text ; Progam Start RESET mov.w #280h,SP ; Stack mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog bis.b #01h,&P1DIR Mainloop xor.b #01h,&P1OUT Delay dec.w R15 jnz Delay jmp Mainloop .sect ".reset" ; MSP430 RESET Vector .short RESET

.end

On the menu bar, click the Save button .

Page 46: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

1 - 44 MSP430 One Day Workshop - Introduction

Download and Run the Program 8. Assemble and Download

Click the Debug Launch button (not the Debug perspective button). Clicking this button will assemble the source file in your project and download the executable to the flash memory of the MSP430F2013.

A Progress Information window will open and inform you of the status of the assembly and download.

9. Run the Program

You should be looking at a screen that looks something like this:

The buttons on the top-left that look like this: control the running of the code. Click on the Run button to run the code. You should notice that the red LED near the MSP430F2013 debug port is blinking about twice per second.

10. Halt Debugging and Close CCS

Click the Terminate All button to halt the program, terminate the debugger session and return to the editor view. From the CCS menu bar, click File Exit. If you are prompted to save anything, do so.

Page 47: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

MSP430 One Day Workshop - Introduction 1 - 45

FLASH Programming Exercise 11. Exercise

In the F2xx family, the time to program any bit, byte or word in FLASH is 30/fFTG – where FTG is between 257kHz – 476kHz. This means that the minimum programming time for any random bit, byte or word is 63us.

If FLASH memory is programmed sequentially though, the programming time can be reduced to 18/fFTG.

We’ve provided you with an excerpt from the F2013 datasheet below. Use it to fill in the blanks provided. Remember that 2KB is equal to 1KW, so it makes sense to program in words to reduce programming time.

What is fFTG? ____________ (pick the highest frequency/shortest period)

What is tword? ____________

Calculate the time to program a word or byte ________________________________________

Multiply that by 1024 words _______________________________

We calculated that the time required to program the entire F2013 2KB Flash array as random words is 64.5ms.

CCS users … you’re done

Page 48: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

1 - 46 MSP430 One Day Workshop - Introduction

*** This page left blank by order of the fire marshal ***

Page 49: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Standard Definitions

MSP430 One Day Workshop - Introduction 1 - 47

Standard Definitions

WDTCTL = 0x5A80;

WDTCTL = 0xA580;

WDTCTL = 0xA540; // Hold watchdog timer

WDTCTL = WDTPW + WDTHOLD; // Hold watchdog timer

WDTCTL = 0x5A80;

WDTCTL = 0xA580;

WDTCTL = 0xA540; // Hold watchdog timer

WDTCTL = WDTPW + WDTHOLD; // Hold watchdog timer

Standard Definitions

Standard definitions make code easier to read and debugPeripheral bit definition files are included with all tools

Controlling GPIO

Controlling GPIO Ports

Controlling GPIO Portsbis.b #010h,&P1DIR bis.b #010h,&P1SEL bis.b #010h,&P1DIR bis.b #010h,&P1SEL

bis.b #001h,&P1DIR bis.b #001h,&P1OUT bis.b #001h,&P1DIR bis.b #001h,&P1OUT

Input Register PxIN

Output Register PxOUT

Direction Register PxDIR

Function Select PxSEL

Interrupt Edge PxIES

Interrupt Enable PxIE

Interrupt Flags PxIFG P1 and P2 only

Lab2 …

Page 50: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Standard Definitions

1 - 48 MSP430 One Day Workshop - Introduction

*** Yet another senseless waste of resources ***

Page 51: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Standard Definitions

MSP430 One Day Workshop - Introduction 1 - 49

Lab 2 – I/O Overview In this lab we’ll configure I/O ports on a FG4618 or FG4619 to recognize an interrupt from a switch and toggle an LED.

Lab2: I/O Overview

FET

Configure Port1 and Port2 of the MSP430FG4618/9P1.0 as input with interrupt enabledP1.0 interrupt on H-L transitionP2.1 as output to turn on LED

Inside of P1ISRClear pending interrupt flag

Review Questions

Page 52: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Standard Definitions

1 - 50 MSP430 One Day Workshop - Introduction

Hardware list: WinXP PC

MSP-FET430UIF

USB cable

JTAG ribbon cable

MSP430FG461x/F28xx Experimenter’s Board

Jumpers

Software list: IAR Kickstart for MSP430 version 4.21B

Code Composer Studio 4.1

Labs

Additional pdf documentation

Adobe™ Reader

Page 53: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

MSP430 One Day Workshop - Introduction 1 - 51

IAR Kickstart Procedure 1. JTAG

Remove the JTAG ribbon cable from the MSP430F2013 debug port on the Experimenter’s Board and connect it to the MSP430FG4619 port as shown on page 1-19. The red LED next to the MSP430F2013 emulator port should start blinking again. After all, the program is still in flash memory and you just applied power to the part …

2. Start IAR Kickstart

Double-click on the IAR Kickstart shortcut on the desktop to start the tool. When the Embedded Workbench Startup dialogue appears, click Cancel.

New Workspace and Project 3. New Workspace

Create a new workspace by clicking File New Workspace on the menu bar. We could have used the previous workspace, but for clarity and practice, let’s make a new one.

4. New Project

Create a new project named Lab2 and save it in the C:\MSP430\IAR Labs\Lab2 folder. If you are unsure how to do this, look back at Lab1.

Configure the Project NOTE: The Experimenter’s Board at your workstation may have either a FG4618 or a FG4619 device installed on it. It’s important at this point that you look at the device itself and identify which part you have.

Feel free to write it down here _____________________

5. Configure the Project

Click Project Options on the menu bar. Change the target device to the MSP430FG4618 or MSP430FG4619.

In the Debugger category, change the Driver to FET Debugger.

In the FET Debugger category, change the Connection to Texas Instrument USB-IF. Click OK.

Add Source File 6. Add the source file to the project

Click Project Add Files on the menu bar. Select Lab2_exercise.c from the C:\MSP430\IAR Labs\Lab2 folder and click Open.

Page 54: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

1 - 52 MSP430 One Day Workshop - Introduction

Complete the Code

7. Answer some questions

Fill in the four blanks in the code on the facing page.

Where will you find the information to complete this task? Start by searching your workstation PC for the MSP430x4xx Family User’s Guide (slau056g.pdf). The Digital I/O section contains some pertinent information. You might also want to open the header file included at the start of the program (msp430xG46x.h), which is also on your PC.

If seeing the schematic will help, try MSP-EXP430FG4618Schematic.pdf.

A couple other files of interest are MSP430FG4618.sfr and .ddf. (or MSP430FG4619.sfr and .ddf ) . The first file is the peripheral I/O registers and bits definition. The second file is the I/O register description file.

Finally, if you just want to throw up your hands and give up, you can look in the Lab2_solution.c file in the Lab2 folder or see the completed code in the Addendum chapter at the end of the workbook.

Once you have completed the paper exercise, type your answers into the code in Lab2_exercise.c.

Page 55: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

MSP430 One Day Workshop - Introduction 1 - 53

#include <msp430xG46x.h>

void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

FLL_CTL0 |= XCAP14PF; // Configure load caps

P2DIR = ____; // Set P2.1 to output direction

P1IES = ____; // H-L transition

P1IE = ____; // Enable interrupt

_EINT(); // Enable interrupts

while (1);

}

// P1 interrupt service routine

#pragma vector=PORT1_VECTOR

__interrupt void P1ISR (void)

{

unsigned volatile int i;

for (i=10000; i>0; i--); // Debounce delay

P1IFG &= ~____; // Clear P1IFG

if ((P1IN & 0x01) == 0)

P2OUT ^= 0x02; // Toggle P2.1 using exclusive-OR

}

Page 56: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

1 - 54 MSP430 One Day Workshop - Introduction

Test Your Code 8. Compile, Download and Debug

Click the Debug button to compile and download your code to the MSP430FG4618/9. When prompted to save your workspace, name it Lab2 and save it in the Lab2 folder. Correct any errors that you may find.

9. Run Your Code

Click the Go button . If your code works, LED3 (yellow, near the FG4618/9 debug port) should toggle each time you press S1 on the bottom right of the Experimenter’s Board.

10. Code Explanation

In case you haven’t already figured it out, the first part of the Lab2 code sets up the ports; one for output and the other as an interrupt input. Execution is then trapped by a while(1) statement until an interrupt occurs. The second part of the code is the interrupt service routine (ISR). When an interrupt occurs, execution of code is vectored to this ISR through the use of the #pragma statement.

The mechanical contacts within a pushbutton switch can literally bounce hundreds of times before finally coming to rest, and a microcontroller is fast enough to try to respond to most of them as legitimate key presses. The for statement located first in the ISR allows time for the switch contacts to stabilize. The following statement clears the interrupt flag for port1. If you fail to do this, the ISR will only run once! The final IF statement detects whether the switch is depressed and toggles the LED port using an XOR. After that, execution is again trapped in the while(1) statement.

Page 57: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

MSP430 One Day Workshop - Introduction 1 - 55

11. Some Debugging Fun

How can you know if an ISR is running properly? You might be surprised how few students know the right answer. By setting a breakpoint on the first instruction!

If your code is still running, halt it by clicking the Break button on the menu bar.

Reset the CPU by clicking the Reset button .

Double-click to the left of the for statement in the ISR code (in the gray area). This will set a breakpoint just before the instruction executes. It should look like this:

Click the Go button. The green arrow and highlight (indicating the position of the Program Counter) over the first instruction in main() should go away. Nothing else should happen until you press S1 … go ahead and press it now. You should see this:

Now you can see (by the green arrow) that indeed, the ISR code is about to run for the first time.

At this point it might be nice to check on the status of the port pins. Click View Register. A window will appear on the right of the IAR Workbench. In the drop-down menu select Port 1/2. Expand P1IN and P2OUT by clicking the + to the left. If you ever get confused about exactly which hardware port/pin you’re dealing with, this is a good way to find out.

P1IN – P0 (Port 1 input pin 0) is the MSP430 input pin reading the status of the pushbutton. P2OUT – P1 (Port 2 output pin 1) is the MSP430 pin connected to the LED

Start the code running again by clicking the Go button, then press S1. Unless you continue pressing S1 when you click Go, the LED won’t toggle since the IF statement didn’t detect S1 being pressed. Try this a few times, and notice the register values change. You may want to set other breakpoints in the ISR code to better see the values change.

12. Shut Down

When done, click the Stop Debugging button and close IAR Kickstart.

IAR Kickstart users … you’re done. Proceed to the Review Questions at the end of this module.

Page 58: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

1 - 56 MSP430 One Day Workshop - Introduction

*** Bottled water … what’s next? Bottled air? ***

Page 59: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

MSP430 One Day Workshop - Introduction 1 - 57

CCS 4.1 Procedure 1. JTAG

Remove the JTAG ribbon cable from the MSP430F2013 debug port on the Experimenter’s Board and connect it to the MSP430FG4619 port as shown on page 1-19. The red LED next to the MSP430F2013 emulator port should start blinking again. After all, the program is still in flash memory and you just applied power to the part …

2. Start CCS and Create New Workspace

Double-click on the Code Composer Studio shortcut on the desktop to start the tool. When the Select a Workspace window appears, enter C:\MSP430ODW\CCS Labs\Lab2\workspace in the dialog, and click OK. Close the Welcome screen when it appears.

3. New Project

Create a new project named Lab2 and save it in the Lab2 workspace folder. If you are unsure how to do this, or have a short term memory issue, look back at Lab1.

NOTE: The Experimenter’s Board at your workstation may have either a FG4618 or a FG4619 device installed on it. It’s important at this point that you look at the device itself and identify which part you have.

Feel free to write it down here _____________________

Make sure you select the Project Type to be MSP430. When you reach the Project Settings window, make sure to select the correct Device Variant, written above. This project will not be an assembly project.

Page 60: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

1 - 58 MSP430 One Day Workshop - Introduction

Add a Source File 4. Add the source file to the project

Right-click in the Project pane and select Add Files to Project. Select Lab2_exercise.c from the C:\MSP430\CCS Labs\Lab2 folder and click Open.

Double-click on Lab2_exercise.c in the Project pane to open the file for editing.

Complete the Code

5. Answer some questions

Fill in the four blanks in the code on the facing page.

Where will you find the information to complete this task? Start by searching your workstation PC for the MSP430x4xx Family User’s Guide (slau056g.pdf). The Digital I/O section contains some pertinent information. You might also want to open the header file included at the start of the program (msp430xG46x.h), which is also on your PC.

If seeing the schematic will help, try MSP-EXP430FG4618Schematic.pdf.

A couple other files of interest are MSP430FG4618.sfr and .ddf. (or MSP430FG4619.sfr and .ddf ) . The first file is the peripheral I/O registers and bits definition. The second file is the I/O register description file.

Finally, if you just want to throw up your hands and give up, you can look in the Lab2_solution.c file in the Lab2 folder or see the completed code in the Addendum chapter at the end of the workbook.

Once you have completed the paper exercise, type your answers into the code in Lab2_exercise.c.

Page 61: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

MSP430 One Day Workshop - Introduction 1 - 59

#include <msp430xG46x.h>

void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

FLL_CTL0 |= XCAP14PF; // Configure load caps

P2DIR = ____; // Set P2.1 to output direction

P1IES = ____; // H-L transition

P1IE = ____; // Enable interrupt

_EINT(); // Enable interrupts

while (1);

}

// P1 interrupt service routine

#pragma vector=PORT1_VECTOR

__interrupt void P1ISR (void)

{

unsigned volatile int i;

for (i=10000; i>0; i--); // Debounce delay

P1IFG &= ~____; // Clear P1IFG

if ((P1IN & 0x01) == 0)

P2OUT ^= 0x02; // Toggle P2.1 using exclusive-OR

}

Page 62: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

1 - 60 MSP430 One Day Workshop - Introduction

Test Your Code 6. Compile, Download and Debug

Click the Debug button to compile and download your code to the MSP430FG4618/9. Correct any errors that you may find.

7. Run Your Code

Click the Run button . If your code works, LED3 (yellow, near the FG4618/9 debug port) should toggle each time you press S1 on the bottom right of the Experimenter’s Board.

8. Code Explanation

In case you haven’t already figured it out, the first part of the Lab2 code sets up the ports; one for output and the other as an interrupt input. Execution is then trapped by a while(1) statement until an interrupt occurs. The second part of the code is the interrupt service routine (ISR). When an interrupt occurs, execution of code is vectored to this ISR through the use of the #pragma statement.

The mechanical contacts within a pushbutton switch can literally bounce hundreds of times before finally coming to rest, and a microcontroller is fast enough to try to respond to most of them as legitimate key presses. The for statement located first in the ISR allows time for the switch contacts to stabilize. The following statement clears the interrupt flag for port1. If you fail to do this, the ISR will only run once! The final IF statement detects whether the switch is depressed and toggles the LED port using an XOR. After that, execution is again trapped in the while(1) statement.

Page 63: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

CCS 4.1 Procedure

MSP430 One Day Workshop - Introduction 1 - 61

9. Some Debugging Fun

How can you know if an ISR is running properly? You might be surprised how few students know the right answer. By setting a breakpoint on the first instruction!

If your code is still running, halt it by clicking the Halt button on the menu bar.

Reset the CPU by clicking the Reset CPU button .

Double-click to the left of the for statement in the ISR code (in the gray area). This will set a breakpoint just before the instruction executes. It should look like this:

Click the Run button. The blue arrow and green highlight (indicating the position of the Program Counter) over the first instruction in main() should go away. Nothing else should happen until you press S1 … go ahead and press it now. You should see this:

Now you can see (by the blue arrow) that indeed, the ISR code is about to run for the first time.

At this point it might be nice to check on the status of the port pins. Click View Registers. A window will appear on the top-right of the CCS display. Click the + next to Port 1/2. Expand P1IN and P2OUT by clicking the + to the left. Re-arrange the window so that you can see the display clearly. If you ever get confused about exactly which hardware port/pin you’re dealing with, this is a good way to find out.

P1IN – P0 (Port 1 input pin 0) is the MSP430 input pin reading the status of the pushbutton. P2OUT – P1 (Port 2 output pin 1) is the MSP430 pin connected to the LED

Start the code running again by clicking the Run button, then press S1. Unless you continue pressing S1 when you click Run, the LED won’t toggle since the IF statement didn’t detect S1 being pressed. Try this a few times, and notice the register values change. You may want to set other breakpoints in the ISR code to better see the values change.

10. Shut Down

When done, click the Terminate All button and exit Code Composer Studio.

CCS 4.1 users … you’re done.

Page 64: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Review Questions

1 - 62 MSP430 One Day Workshop - Introduction

Review Questions Review

How many general purpose registers does the MSP430 have?

What is the purpose of the constant generator?

Where is the best resource for MSP430 information?

At reset, all I/O pins are set to …

Why should you use standard definitions?

You can find the answers to these questions in the Addendum section at the end of this workbook.

Page 65: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Ultra-Low Power

Introduction In this section we’ll explore the ultra-low power abilities and architecture of the MSP430. We’ll take a look at its low power modes and unique oscillator arrangement, along with techniques that can be used to minimize power consumption.

Objectives • Principles of ultra-low power applications

• Low power modes

• Oscillators

• Interrupts

• Ultra-low power lab

MSP430 One Day Workshop - Ultra-Low Power 2 - 1

Page 66: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

*** This page isn’t really blank, you know. ***

2 - 2 MSP430 One Day Workshop - Ultra-Low Power

Page 67: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Module Topics Ultra-Low Power ....................................................................................................................................... 2-1

Module Topics......................................................................................................................................... 2-3 Activity Profile ................................................................................................................................... 2-5 Performance on Demand .................................................................................................................... 2-5 Low Power Mode Clock Control........................................................................................................ 2-6 Low Power Mode Configuration ........................................................................................................ 2-6 Low Power Modes in Assembly......................................................................................................... 2-7 Low Power Modes in C ...................................................................................................................... 2-7 11x/12x Basic Clock........................................................................................................................... 2-8 1xx XTAL Options............................................................................................................................. 2-8 1xx DCO Control ............................................................................................................................... 2-9 DCO Jitter........................................................................................................................................... 2-9 1xx DCO Calibration.........................................................................................................................2-10 2xx Basic Clock.................................................................................................................................2-10 4xx FLL.............................................................................................................................................2-11 5xx Unified Clock System.................................................................................................................2-11 5xx Power Management Module.......................................................................................................2-12 Program Flow ....................................................................................................................................2-12 Interrupt Processing...........................................................................................................................2-13 11x1 Interrupt Vectors.......................................................................................................................2-13 Move S/W Functions to Peripherals ..................................................................................................2-14 Power Manage Internal Peripherals...................................................................................................2-14 Lowering System Power....................................................................................................................2-15 Increasing Power Efficiency..............................................................................................................2-15 Terminate Unused Pins......................................................................................................................2-16 Ultra Low Power Principles...............................................................................................................2-16

Lab 3 – Ultra-Low Power in Practice....................................................................................................2-17 Hardware list: ....................................................................................................................................2-18 Software list:......................................................................................................................................2-18

IAR Kickstart Procedure........................................................................................................................2-19 Lab3 Baseline ....................................................................................................................................2-19 Lab3 using LPM3 ..............................................................................................................................2-19 Shut Down.........................................................................................................................................2-20

Code Composer Studio 4.1 Procedure...................................................................................................2-23 Lab3 Baseline ....................................................................................................................................2-23 Lab3 using LPM3 ..............................................................................................................................2-23 Shut Down.........................................................................................................................................2-24

Review Questions ...................................................................................................................................2-26

MSP430 One Day Workshop - Ultra-Low Power 2 - 3

Page 68: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

*** Let this be your doodle area ***

2 - 4 MSP430 One Day Workshop - Ultra-Low Power

Page 69: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Activity Profile

250uA

1 uA t

Standby

Active Activ e

Ultra-low Power Activity Profile

3 2768

DCOM CLKCPU a nd periphe rals

A CLKlow- power periphera ls

MSP430Always-on

On demand

Performance on Demand

Performance on Demand

Performance on Demand

Interrupt

DCO

Immediate-stable clock start for quick reaction to events

Low Power Mode Clock Control

MSP430 One Day Workshop - Ultra-Low Power 2 - 5

Page 70: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Low Power Mode Clock Control

Low Power Mode Clock Control

LPM Configuration

OffAll

Clocks Off0.1µA

Stand-byDCO offACLK on

1.0µA

LPM3• RTC function• LCD driver• RAM/SFR retained

CPU OffDCO onACLK on

45µA

LPM0

Active

165µA

DCO onACLK on

<1-6µs

<6µs

Specific values vary by device

• RAM/SFR retainedLPM4

Low Power Mode Configuration

Low Power Mode Configuration

Active Mode 0 0 0 0 ~ 250uA

LPM0 0 0 0 1 ~ 35uA

LPM3 1 1 0 1 ~ 0.8uA

LPM4 1 1 1 1 ~ 0.1uA

bis.w #CPUOFF,SR ; LPM0 bis.w #CPUOFF,SR ; LPM0

R2/SR

Reserved CSCG1 SCG0 CPUOFF

OSCOFF ZNGIEV

LPM in Assembly

2 - 6 MSP430 One Day Workshop - Ultra-Low Power

Page 71: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Low Power Modes in Assembly

ORG 0F000h RESET mov.w #300h,SP

mov.w #WDT_MDLY_32,&WDTCTL

bis.b #WDTIE,&IE1 bis.b #01h,&P1DIR

Mainloop bis.w #CPUOFF+GIE,SR xor.b #01h,&P1OUT jmp Mainloop

WDT_ISR bic.w #

Low Power Modes In Assembly

CPUOFF,0(SP)reti

ORG 0FFFEh DW RESET ORG 0FFF4h DW WDT_ISR

ORG 0F000h RESET mov.w #300h,SP

mov.w #WDT_MDLY_32,&WDTCTL

bis.b #WDTIE,&IE1 bis.b #01h,&P1DIR

Mainloop bis.w #CPUOFF+GIE,SR xor.b #01h,&P1OUT jmp Mainloop

WDT_ISR bic.w # (SP)reti

ORG 0FFFEh DW RESET ORG 0FFF4h

CPUOFF,0

DW WDT_ISR

Item1Item2

Item1Item2 SP

PCSR=00

SP

SP18

Item1Item2

PCSR

Item1Item2

PCSR=0008

LPM in C

Low Power Modes in C

Low Power Modes In C

Item1Item2

PCSR=0018

Item1Item2 void main(void)

{ WDTCTL = WDT_MDLY_32; IE1 |= WDTIE; P1DIR |= 0x01;

for (;;){_BIS_SR(CPUOFF + GIE);P1OUT ^= 0x01;

}}#pragma vector=WDT_VECTOR__interrupt void watchdog_timer(void){

_BIC_SR_IRQ(CPUOFF); }

void main(void){ WDTCTL = WDT_MDLY_32; IE1 |= WDTIE; P1DIR |= 0x01;

for (;;){_BIS_SR(CPUOFF + GIE);P1OUT ^= 0x01;

}}#pragma vector=WDT_VECTOR__interrupt void watchdog_timer(void){

_BIC_SR_IRQ(CPUOFF); }SP

SP

SP

Item1Item2

Item1Item2

PCSR=0008

PCSR

’11x/’12x Basic Clock

MSP430 One Day Workshop - Ultra-Low Power 2 - 7

Page 72: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

11x/12x Basic Clock

MSP430x11x/12x Basic Clock

R2/SR

Reserved CSCG1 SCG0 CPUOFF

OSCOFFV ZNGIE

MCLK

LFXT1CLK

DCOCLK

CPUOFF

ACLK

SMCLK

SCG1

DCO

SCG0

OSCOFF

LFXT1 Oscillator

LF XT12pF12pF

VCC

Digitally ControlledOsciallator

‘1xx Basic Clock XTAL options

1xx XTAL Options

32768Hz 1- 8MHz

F1xx Basic Clock XTAL Options

Most MSP430 applications use a 32,768Hz crystal

XOUT

XIN

XOUT

XIN

XOUT

XIN

XOUT

XINROSC

100K

‘1xx Basic Clock DCO Control

2 - 8 MSP430 One Day Workshop - Ultra-Low Power

Page 73: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

1xx DCO Control

F1xx Basic Clock DCO Control

MOD2M OD3 M OD1 M OD0MOD4DC00DCO1DCO2RSEL2XT5V RSEL1 RSEL0DIVA0DIVA1XTSXT2OFF

DCOCLKDCOxRSELx

MODx

n

n+1

DCOCLK

-0.33%/C

0 1 2 3 4 5 6 7 DCOx

0

4

7RSELx

100kHz

10MHz

Average DCO

1MHz

n

n+1

MODx

DCO - Digitally Controlled Oscillator DCO Jitter

DCO Jitter

DCO Jitter

DCOCLKn

n+1DCOx

MODx

The modulator mixes two frequencies to produce the DCO clockThis spreads the clock energy and reduces electromagnetic interference (EMI)Due to jitter, DCO cannot be used to lock a PLL

‘1xx DCO Calibration

MSP430 One Day Workshop - Ultra-Low Power 2 - 9

Page 74: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

1xx DCO Calibration

Periodic loop adjusts DCOKnown reference can be 50/60Hz AC power or 32kHz crystal frequencyIf Rosc = 100k then DCOCLK ~ 2MHz

F1xx DCO Calibration

DCOCLK

DCOR

P2.5/Rosc

VCC

DCOxRSELxn

n+1

VCC

100k

2MHz

4096Hz ACLK

// P SW FLL Codeif (488 < Compare ) // DCO too fastDCOCTL--;

else DCOCTL++; // DCO too slow

artial// Partial SW FLL Codeif ( < Compare ) // DCO too fastDCOCTL--;

else DCOCTL++; // DCO too slow

488

Clock precision is achieved by periodic adjustment

‘F2xx Basic Clock +

2xx Basic Clock

F2xx Basic Clock+LFXT1 XTAL Oscillator

<1uA LPM3 standby modeXTAL CAPs

programmableOSCfault LF/(XT) Very Low Power

Oscillator (VLO)Improved DCO

< 1us 0-to-16MHz+ 2.5% DCOProgrammable

frequencyVLO not in F21x1

MCLK

CPUOFF

SMCLK

SCG1

ACLK

DCO 16MHz

SCG0

OSCOFF

LFXT1 Oscillator

LF

Min. PulsFilter

Min. PulsFilter

VLO

OSC_FaultXT

Digitally ControlledOscillator

F4xx FLL

2 - 10 MSP430 One Day Workshop - Ultra-Low Power

Page 75: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

4xx FLL

Automatic DCO Stabilization

F4xx Frequency-Locked Loop (FLL)

Fully digitalOscillator fault fail-safe for LFXT1, DCO and XT2

FrequencyIntegrator

DCO+

Modulator

AC LKPeripherials

MCLKCPU

SMCLKPeripherials

+

-/(N+1)

LF XT

/1.. /8

DCGenerator

F5xx UCS …

5xx Unified Clock System

F5xx: Unified Clock System

Orthogonal clock systemAny source can drive any clock signal

2 Integrated clock sources:REFO: 32kHz, trimmed osc.VLO: 12kHz, ultra-low power

DCO & FLL provide high frequency accurate timingMODOSC provides bullet

proof timing for FlashCrystal pins muxed with

I/O function

D ivide r/1/2/4/8/16

1 0- bitF re qu en cy In te gr at or

FL L

D C O

FL LR E F C LK

D C O C LKD C O C LK D I V

V LO

R EF O

LF X T 1

X T 2

A C L K

M C L K

SM C L K

M O D O SCM O D C L K

P r ov ide d to Fla sh c on tr oll er , A D C 12

F5xx PMM …

MSP430 One Day Workshop - Ultra-Low Power 2 - 11

Page 76: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

5xx Power Management Module

F5xx: Power Management Module

Integrated LDOVCORE level programmable Flexibility in processing performance vs. powerIntegrated supervision& monitoringZero-power BORFive integrated supervisors

SVSHSVSLSVMHSVMLBOR

Program flow …

Program Flow

100% CPU Load

Interrupts Control Program Flow

UARTRXTX

// Polling UART Receivefor (;;){while (!(IFG2&URXIFG0));TXBUF0 = RXBUF0;}

// Polling UART Receivefor (;;){while (!(IFG2&URXIFG0));TXBUF0 = RXBUF0;}

// UART Receive Interrupt#pragma vector=UART_VECTOR__interrupt void rx (void){TXBUF0 = RXBUF0;}

// UART Receive Interrupt#pragma vector=UART_VECTOR__interrupt void rx (void){TXBUF0 = RXBUF0;}

0.1% CPU Load

9600 baud

Interrupt Processing

2 - 12 MSP430 One Day Workshop - Ultra-Low Power

Page 77: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Interrupt Processing

ISR hardware - automatically

reti - automatically

Prior to ISRItem1Item2

PC pushed SR pushedInterrupt vector moved to PCGIE, CPUOFF, OSCOFF and SCG1 clearedIFG flag cleared on single source flags

SR popped - originalPC popped

SP

Item1Item2

PCSR

SP

SP

Item1Item2

PCSR

Interrupt Processing

Vectors

11x1 Interrupt Vectors

Interrupt Vectors – F11x1

SOURCE FLAG INTERRUPT ADDRESS PRIORITYPower-up ext. Reset Watchdog

WDTIFG Reset 0FFFEh 15, highest

NMI Osc. Fault Flash violation

NMIIFG OFIFG ACCVIFG

(non)-maskable (non)-maskable (non)-maskable

0FFFCh 14

0FFFAh 13 0FFF8h 12 Comparator_A CAIFG maskable 0FFF6h 11 Watchdog timer WDTIFG maskable 0FFF4h 10 Timer_A CCIFG0 maskable 0FFF2h 9 Timer_A CCIFGx maskable 0FFF0h 8 0FFEEh 7 0FFECh 6 0FFEAh 5 0FFE8h 4 I/O Port P2 P2IFGx maskable 0FFE6h 3 I/O Port P1 P1IFGx maskable 0FFE4h 2 0FFE2h 1 0FFE0h 0, lowest

FLASH

(x) 512BSegments

8-bit Peripherals

Boot Loader

RAM

(2) 128B

16-bit Peripherals

Interrupt Vectors

Move s/w to peripherals

MSP430 One Day Workshop - Ultra-Low Power 2 - 13

Page 78: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Move S/W Functions to Peripherals

100% CPU Load

Move Software Functions to Peripherals

MCUP1.2

// Endless Loop for (;;) {P1OUT |= 0x04; // Set delay1();P1OUT &= ~0x04; // Resetdelay2();

}

// Endless Loop for (;;) {P1OUT |= 0x04; // Set delay1();P1OUT &= ~0x04; // Resetdelay2();}

// Setup output unitCCTL1 = OUTMOD0_1; _BIS_SR(CPUOFF);

// Setup output unitCCTL1 = OUTMOD0_1; _BIS_SR(CPUOFF);

Zero CPU Load

Power manage internal peripherals

Power Manage Internal Peripherals

Power Manage Internal Peripherals

P1OUT |= 0x02; // Power dividerCACTL1 = CARSEL + CAREF_2 + CAON; // Comp_A onif (CAOUT & CACTL2)P1OUT |= 0x01; // FaultelseP1OUT &= ~0x01;

P1OUT &= ~0x02; // de-power divider CACTL1 = 0; // Disable Comp_A

P1OUT |= 0x02; // Power dividerCACTL1 = CARSEL + CAREF_2 + CAON; // Comp_A onif (CAOUT & CACTL2)P1OUT |= 0x01; // Fault

elseP1OUT &= ~0x01;

P1OUT &= ~0x02; // de-power divider CACTL1 = 0; // Disable Comp_A

Comparator_A

MSP430F20x1Px.x

Ref

CAONP1.0

+

-

System power …

2 - 14 MSP430 One Day Workshop - Ultra-Low Power

Page 79: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Lowering System Power

Lowering System Power

My MCU is only operating a portion of the time, is there a way to lower the overall power

consumption of my system?

Problem

2.2V – 3.3V

V SS

V C C

I /O

MSP4 30Or

Eq uiva lent

VIN

V SE T

VO U T

GND

TPS78 0 xx1uF 1uF

Vin V out

VsetGND

TPS780xx

Using a LDO with a programmable output voltage yields lower power consumption when

your MCU is in an idle state

Solution

Power efficiency …

Increasing Power Efficiency

Solution

DCDC Converters with Integrated FETs have low external component count and dramatically reduce complexity with much greater efficiency

TPS60kDCDC C onverte r

Switch in g Regu lator Eff iciency = 85-95% typ- varies slight ly w ith Vout & outp ut current

- one addition al compo nen t vs L DO solution

V in V out

EN

MODE

GND FB

Problem

Increasing Power Efficiency

I want higher efficiency than LDOs, but DCDC's are more complicated, right?

Vin Vout

E N GND

TPS7xxxx LDO

Linear Regulator Ef ficiency = Vout/Vin- If Vin = 5V, Vout = 3.3V Eff = 66%

Translating to Real World Applications: If LDO eff = 66% & DCDC eff = 90% : DCDC allows your battery to last ~36% longer

Unused pins …

MSP430 One Day Workshop - Ultra-Low Power 2 - 15

Page 80: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Terminate Unused Pins

Terminate Unused Pins

Unused port pins Px.0 – Px.7Set as output direction to avoid floating gate current

XT2IN, XT2OUT?See the last page of chapter 2 in the user’s guide

Low-power principals …

Ultra Low Power Principles

Principles For ULP ApplicationsMaximize the time in LPM3Use interrupts to control program flowReplace software with peripheralsPower manage external devicesConfigure unused pins properlyEfficient code makes a differenceEven wall powered devices can be “greener”Every unnecessary instruction executed is a portion of the battery wasted that will never return

Lab3 …

2 - 16 MSP430 One Day Workshop - Ultra-Low Power

Page 81: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Lab 3 – Ultra-Low Power in PracticeWe’re going to measure the power saving effect of using LPM3 mode.

Lab3: Ultra Low-Power In Practice

FET

The code from lab 2 has been converted to use LPM3 instead of the while(1) loopUsing an ammeter, measure the current through the PWR1 jumper

Review

MSP430 One Day Workshop - Ultra-Low Power 2 - 17

Page 82: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Hardware list: WinXP PC

MSP-FET430UIF

USB cable

JTAG ribbon cable

MSP430FG461x/F28xx Experimenter’s Board with batteries

Digital Multimeter

Jumpers

Two AAA Batteries

Software list: IAR Kickstart for MSP430 version 4.21B

Code Composer Studio 4.1

Labs

Additional pdf documentation

Adobe™ Reader

2 - 18 MSP430 One Day Workshop - Ultra-Low Power

Page 83: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

IAR Kickstart Procedure The C code from the previous lab has been modified to use LPM3 mode instead of the while(1) loop. We’ll measure the current draw of both labs.

Lab3 Baseline 1. Set up the Hardware

Remove the PWR1 jumper from the Experimenter’s Board and place it over a nearby pin so you won’t lose it.

Make sure the two AAA batteries are in place and connect the BATT jumper to power the board.

Hook up the positive lead of the multimeter to the right-hand PWR1 pin and the negative lead to the left-hand PWR1 pin. Make sure the leads are connected to the proper jacks on the multimeter. Place the multimeter in the lowest milliamp measurement setting and turn it on.

2. Run the Software

Your Lab2 software should still be loaded in the F4618/9 (as well as the Lab1 code in the F2013). If for some reason the Lab2 code is not running, use the steps in Lab2 to reload and run it. Remove the JTAG cable from the FG4618/9 debug port. You may have to remove and replace the BATT jumper to get the MSP430 to boot properly. Press S1 a couple times to verify that the software is functioning.

3. Measure the current

Fill in the blanks in the chart below for Lab2 with LED3 on and off.

Code used LED Off (mA) LED On (mA)

Lab2

Lab3

Lab3 using LPM3 4. Start up IAR Kickstart

Start up IAR Kickstart. When prompted, load the Lab2 workspace. The Lab2 code is probably visible in the editor window. Close the editor by clicking the tiny, little X in the upper right-hand corner of the editor window (not the one that closes IAR Embedded Workbench).

5. Swap out the Source Files

Right-click on Lab2_exercise.c in the Workspace window and select Remove. When prompted whether or not you are sure, click Yes.

On the menu bar, click Project Add Files. Navigate to C:\MSP430\IAR Labs\Lab3 and select Lab3_solution.c. Click Open.

MSP430 One Day Workshop - Ultra-Low Power 2 - 19

Page 84: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

6. Inspect the Modified Code

Double-click on Lab3_solution.c in the Workspace window to open it in the editor. Take a moment to inspect the Lab3_solution code. Note the configuration of unused pins in the initialization as well as the use of LPM3 in the while(1) loop. The while(1) loop itself has been altered somewhat to decrease power. Note also the ISR code changes.

7. Build, Download and Run

Replace the JTAG cable in the FG4618/9 debug port. Click the Debug button to build and download the code to the Experimenter’s Board. Correct any errors you may find. When you’ve successfully downloaded the code to the board, Click the Stop Debugging button in IAR Embedded Workbench and remove the JTAG cable from the FG4618/9 debug port. You may have to remove and replace the BATT jumper to get the MSP430 to boot properly. Press S1 a couple times to verify that the software is functioning

8. Measure the Lab3 current

Fill in the remaining cells in the table in step 3.

9. Analysis

We made the same measurements, and here’s what we got:

Code used LED Off (mA) LED On (mA)

Lab2 0.6 2.7

Lab3 0.0 2.1

Obviously, the current for Lab3 with the LED off was below the measurement abilities of the meter we were using. Subsequent measurements with a better (more expensive) multimeter showed that the current was 1.5uA. That’s a current reduction of about 97%.

Shut Down 10. Shut Down

Turn off the multimeter and remove the leads from the PWR1 pins. Replace the PWR1 jumper.

Remove the BATT jumper and place it over one pin for safekeeping.

Shut down IAR Embedded Workbench. When prompted to save the project, click No.

Replace the JTAG cable in the FG4618/9 debug port.

2 - 20 MSP430 One Day Workshop - Ultra-Low Power

Page 85: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

11. Some further questions

Why were the I/Os configured as they were?

Why was LPM3 used?

Look in the header file to see how LPM3_bits is defined

What further low-power improvements could be made?

You can find the answers to these questions in the Addendum section at the end of this workbook.

IAR Kickstart users … You’re done. Proceed to the review questions on page 2-26.

MSP430 One Day Workshop - Ultra-Low Power 2 - 21

Page 86: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

*** Where is my flying car? ***

2 - 22 MSP430 One Day Workshop - Ultra-Low Power

Page 87: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

Code Composer Studio 4.1 Procedure The C code from the previous lab has been modified to use LPM3 mode instead of the while(1) loop. We’ll measure the current draw of both labs.

Lab3 Baseline 1. Set up the Hardware

Remove the PWR1 jumper from the Experimenter’s Board and place it over a nearby pin so you won’t lose it.

Make sure the two AAA batteries are in place and connect the BATT jumper to power the board.

Hook up the positive lead of the multimeter to the right-hand PWR1 pin and the negative lead to the left-hand PWR1 pin. Make sure the leads are connected to the proper jacks on the multimeter. Place the multimeter in the lowest milliamp measurement setting and turn it on.

2. Run the Software

Your Lab2 software should still be loaded in the F4618/9 (as well as the Lab1 code in the F2013). If for some reason the Lab2 code is not running, use the steps in Lab2 to reload and run it. Remove the JTAG cable from the FG4618/9 debug port. You may have to remove and replace the BATT jumper to get the MSP430 to boot properly. Press S1 a couple times to verify that the software is functioning.

3. Measure the current

Fill in the blanks in the chart below for Lab2 with LED3 on and off.

Code used LED Off (mA) LED On (mA)

Lab2

Lab3

Lab3 using LPM3 4. Start up CCS

Start up CCS. When prompted, select the Lab2 workspace. If CCS opens in the debug

perspective, click on on the upper right of the menu bar to return to the editing perspective. The Lab2 code is probably visible in the editor window. Close the editor window by clicking the X in the Lab2_exercise.c tab.

MSP430 One Day Workshop - Ultra-Low Power 2 - 23

Page 88: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

5. Swap out the Source Files

Right-click on Lab2_exercise.c in the Project pane and select Delete. When prompted whether or not you are sure, click Yes.

On the menu bar, click Project Add Files to Active Project … Navigate to C:\MSP430\CCS Labs\Lab3 and select Lab3_solution.c. Click Open.

6. Inspect the Modified Code

Double-click on Lab3_solution.c in the Project pane to open it in the editor. Take a moment to inspect the Lab3_solution code. Note the configuration of unused pins in the initialization as well as the use of LPM3 in the while(1) loop. The while(1) loop itself has been altered somewhat to decrease power. Note also the ISR code changes.

7. Build, Download and Run

Make sure that the JTAG cable in the FG4618/9 debug port. Click the Debug Launch button to build and download the code to the Experimenter’s Board. Correct any errors you may find. When you’ve successfully downloaded the code to the board, Click the Terminate All button in CCS and remove the JTAG cable from the FG4618/9 debug port. You may have to remove and replace the BATT jumper to get the MSP430 to boot properly. Press S1 a couple times to verify that the software is functioning

8. Measure the Lab3 current

Fill in the remaining cells in the table in step 3.

9. Analysis

We made the same measurements, and here’s what we got:

Code used LED Off (mA) LED On (mA)

Lab2 0.6 2.7

Lab3 0.0 2.1

Obviously, the current for Lab3 with the LED off was below the measurement abilities of the meter we were using. Subsequent measurements with a better (more expensive) multimeter showed that the current was 1.5uA. That’s a current reduction of about 97%.

Shut Down 10. Shut Down

Turn off the multimeter and remove the leads from the PWR1 pins. Replace the PWR1 jumper.

Remove the BATT jumper and place it over one pin for safekeeping.

Shut down Code Composer Studio.

Replace the JTAG cable in the FG4618/9 debug port.

2 - 24 MSP430 One Day Workshop - Ultra-Low Power

Page 89: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

11. Some further questions

Why were the I/Os configured as they were?

Why was LPM3 used?

Look in the header file to see how LPM3_bits is defined

What further low-power improvements could be made?

You can find the answers to these questions in the Addendum section at the end of this workbook.

You’re done

MSP430 One Day Workshop - Ultra-Low Power 2 - 25

Page 90: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Review Questions

Review Questions Review

To minimize power consumption, you should maximize your time in what LPM mode?

Why are unused pins set as outputs?

You should control program flow with …

Most MSP430 designs utilize a ________ crystal.

You can find the answers to these questions in the Addendum section at the end of this workbook.

2 - 26 MSP430 One Day Workshop - Ultra-Low Power

Page 91: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Analog Peripherals

Introduction In this section we’ll take a look at the MSP430 analog peripherals. It’s not possible in this limited amount of time to give you a complete overview of the possible analog inputs, but hopefully this introduction will guide you in the right direction

Objectives • Comparators

• ADC10 & 12

• SD16 & SD16A

• DAC12

• DTC

• Timer triggers

• Lab

MSP430 One Day Workshop - Analog Peripherals 3 - 1

Page 92: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

*** This page intentionally left _____ ***

3 - 2 MSP430 One Day Workshop - Analog Peripherals

Page 93: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Module Topics Analog Peripherals .................................................................................................................................... 3-1

Module Topics......................................................................................................................................... 3-3 ADC Selection.................................................................................................................................... 3-5 Comparators ....................................................................................................................................... 3-5 ADC10 & ADC12 .............................................................................................................................. 3-6 Conversion Memory and Control ....................................................................................................... 3-6 ADC10 DTC....................................................................................................................................... 3-7 Timer Triggers.................................................................................................................................... 3-7 SD16................................................................................................................................................... 3-8 SD16A................................................................................................................................................ 3-8 SD16 & SD16A Input Range ............................................................................................................. 3-9 DAC12................................................................................................................................................ 3-9

Lab 4 – Using the ADC12......................................................................................................................3-11 Hardware list: ....................................................................................................................................3-12 Software list:......................................................................................................................................3-12

IAR Kickstart Procedure........................................................................................................................3-13 Start Up..............................................................................................................................................3-13 Add Source File .................................................................................................................................3-13 Complete the Code ............................................................................................................................3-13 Test Your Work.................................................................................................................................3-16 Shut Down.........................................................................................................................................3-16

Code Composer Studio 4.1 Procedure...................................................................................................3-17 Start Up..............................................................................................................................................3-17 Add Source File .................................................................................................................................3-17 Complete the Code ............................................................................................................................3-17 Test Your Work.................................................................................................................................3-20 Shut Down.........................................................................................................................................3-20

Review Questions ...................................................................................................................................3-21

MSP430 One Day Workshop - Analog Peripherals 3 - 3

Page 94: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

*** Blankety, blank ***

3 - 4 MSP430 One Day Workshop - Analog Peripherals

Page 95: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

ADC Selection

MSP430 ADC Selection

ADC12

ADC10

SD16

SD16A

Voltage range to be measured?Max frequency for AIN?How much resolution?Differential inputs?Reference range?Multiple channels?

S l o p e

B it s

1 0 1 0 0 1 k 1 0 k 1 0 0 k 1 M

S A R

S i g m a -D e l t a

S a m p l e s p e r S e c o n d

8

1 2

1 6

2 0

2 4

Comparators …

Comparator

Comparators

Analog Comparators

~100nA operation (Comp_B)

Multiplexer short for sample-and-hold

Hysteresis generator (B)Input multiplexerReference generatorLow-pass filterBattery detectInterrupt sourceTimer_A capture

0.5xVCC0.25xVCC

CA0

+-

10 ~0.55V

CA1CA2

CA1CA2CA3CA4CA5CA6CA7

ADC10 & 12 …

MSP430 One Day Workshop - Analog Peripherals 3 - 5

Page 96: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

ADC10 & ADC12

10- and 12-bit ADCs

10-bit & 12-bit ADCs200ksps+Autoscan

SingleSequenceRepeat-singleRepeat-sequence

Internal/External referenceTA SOC triggers Data Transfer Controller (DTC)DMA Enabled

RAM, Flash, Pe riphe rals

S/H 10-bit SAR

ADC10S CTA1

TA2TA0

Dire ct Transfer

Controller

VR- VR+

AVCCA VSS

1. 5V or 2. 5V

Auto

Batt Temp

DirectTransferController

DataTransferController

Mem and control …

Conversion Memory and Control

ADC12 Conversion Memory & Control

Each location interrupt capableEach location DMA enabled

ADC12MEM0ADC12MEM1

ADC12MEM15 EOS15 SREF15 INCH15

EOS1 SREF0 INCH1EOS0 SREF0 INCH0

Memory Registers Control Registers

EOSx – End of SequenceSREFx – Reference SelectionINCHx – Input Channel Selection

DTC …

3 - 6 MSP430 One Day Workshop - Analog Peripherals

Page 97: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

ADC10 DTC

70 cycles/Sample Fully Automatic

ADC10 Direct Transfer Controller (DTC)

// SoftwareRes[pRes++] = ADC10MEM;ADC10CTL0 &= ~ENC; if (pRes < NR_CONV) {CurrINCH++;if (CurrINCH == 3)

CurrINCH = 0;ADC10CTL1 &= ~INCH_3; ADC10CTL1 |= CurrINCH; ADC10CTL0 |= ENC+ADC10SC;}

// SoftwareRes[pRes++] = ADC10MEM;ADC10CTL0 &= ~ENC; if (pRes < NR_CONV) {CurrINCH++;if (CurrINCH == 3)

CurrINCH = 0;ADC10CTL1 &= ~INCH_3; ADC10CTL1 |= CurrINCH; ADC10CTL0 |= ENC+ADC10SC;}

Data2Data1Data0Data2

ADCDTC

// DTC_BIS_SR(CPUOFF);

// DTC_BIS_SR(CPUOFF);

AUT

O

Other automated conversion methods offer similar benefitsTimer Triggers …

Timer Triggers

Timer Triggers – Low-Power

// Interrupt CPU cycles; MSP430 ISR to start conversion 6 BIS #ADC12SC,&ADC12CTL0 ; Start conversion 5 RETI ; Return 5

; 16

// Interrupt CPU cycles; MSP430 ISR to start conversion 6 BIS #ADC12SC,&ADC12CTL0 ; Start conversion 5 RETI ; Return 5

; 16

Memory

ADC

Timer

Timer triggered interrupts – no software wait loops

SD16 …

MSP430 One Day Workshop - Analog Peripherals 3 - 7

Page 98: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

SD16

SD16

VREF

16-bit Sigma Delta ADC

32x PGA

Differential inputs4.096ksps85dB SINAD

18ppm 1.2V refTemp sensorBattery input

8x

1.2V

SD16MEM0

Batt

PGA 16-bit ΣΔ

Temp

SD16A …

SD16A

SD16A

ACLKTACLK

011011

MCLKSMCLK

VREF

Divider

A0 +-+-+-+-+-+-+-+-

A1A2A3A4A5A6

SD16MEM0

Reference

A7

f M

1.2V

Start ConversionLogic

Divider

BUF

A5Temp.sensor

PGA 2nd OrderΣΔ Mod

16-bit, S-?, 4kspsOne converter, one channelUp to 8 muxed differentialinputsIndependent ProgrammableGain Amplifier (PGA)High impedance input buffer*Internal/External ReferenceUp to 1024x Over Sampling Rate (OSR)Optional low-power conversionVCC measurementInput Range: +/- 600mV

* Buffer not in ‘F20x3 devices

Input range …

3 - 8 MSP430 One Day Workshop - Analog Peripherals

Page 99: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

SD16 & SD16A Input Range

SD16/SD16A Input Range

What is VREF?What is the PGA setting?

Applies to all inputs & modes

0V = Vss (SD16), 0V = relative (SD16A)

PGA

refFSR GAIN

VV

2/=

GAIN 1 2 32

0 V

+0.6V

-0.6V

+0.5V

-0.5V

• • •

-0.015V+0.015V

DAC12 …

DAC12

DAC12

12-bit monotonic8/12-bit voltage outputProgrammable settlingtime versus power Internal/External referenceBinary or 2’s complimentSelf-calibrationGroup sync loadDMA enabled

DAC12_0

ADC12 1.5V /2.5V Reference

VR+ VR+

DAC12_1VR+ VR-

AVSS

AVSS

TB2

GND

TA1

Group Load

TB2

GND

TA1

Lab4 …

MSP430 One Day Workshop - Analog Peripherals 3 - 9

Page 100: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

*** www.this-page-intentionally-left-blank.org no kidding***

3 - 10 MSP430 One Day Workshop - Analog Peripherals

Page 101: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Lab 4 – Using the ADC12In this lab we’ll configure and use the ADC12 analog input in the FG4618/9 to measure the temperature from the internal thermistor.

Lab4: Using the ADC12

FET

Review

Use ADC12 integrated temperature sensorSet up ADC12 to perform a single conversionLoop continuously, converting to Degrees F and C in softwareTouch the FG4618/9 with a finger to change the temperatureOpen a watch window in the debugger to see the temperature values

MSP430 One Day Workshop - Analog Peripherals 3 - 11

Page 102: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Hardware list: WinXP PC

MSP-FET430UIF

USB cable

JTAG ribbon cable

MSP430FG461x/F28xx Experimenter’s Board

Jumpers

Software list: IAR Kickstart for MSP430 version 4.21B

Code Composer Studio 4.1

Labs

Additional pdf documentation

Adobe™ Reader

3 - 12 MSP430 One Day Workshop - Analog Peripherals

Page 103: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

IAR Kickstart Procedure In this lab we’ll configure and use the ADC12 analog input in the FG4618/9 to measure the temperature from the internal thermistor. Touching the MSP430 will change the temperature enough to measure it, calculate it and place it in a memory for observation.

Start Up 1. JTAG

Assure that the JTAG interface is connected to the FG4618/9 debug port.

2. New Workspace, New Project

Start up IAR Kickstart and create a new workspace, Create a new project named Lab4 and save it in the C:\MSP430\IAR Labs\Lab4 folder.

3. Configure the Project Options

Target device = MSP430FG4618 or MSP430FG4619

Driver = FET Debugger

FET Debugger = Texas Instrument USB-IF

Add Source File 4. Add the source file to the project

Add Lab4_exercise.c from the C:\MSP430\IAR Labs\Lab4 folder.

Complete the Code The following lab steps will walk you through filling in the blanks in the code as shown on the facing page. You’ll want to open the MSP430x4xx Family User’s Guide (slau056g.pdf), as well as the MSP430FG4618/9 datasheet (msp430fg4618.pdf or msp430fg4619.pdf). We’re also going to need to look at the standard definitions in the header file:

C:\Program Files\IAR Systems\Embedded Workbench 5.0\430\inc\msp430xG46x.h.

Open that file in the IAR Kickstart editor.

If you want to take the easy way out, you’ll find the completed code in the Addendum chapter at the end of this workbook or you can peruse the solution file in the Lab4 folder.

If you’re a glutton for punishment, ignore the following steps and do it on your own. No one’s forcing you to do it our way!

MSP430 One Day Workshop - Analog Peripherals 3 - 13

Page 104: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

#include "msp430xG46x.h" volatile unsigned int i; volatile unsigned int ADCresult; volatile unsigned long int DegC, DegF; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer ADC12CTL0 = __________________________; // Turn ADC on, ref on. Ref = 2.5V,

// Set sampling time ADC12CTL1 = _________________; // Use sampling timer ADC12MCTL0 = ________________; // Channel A10, Vref+ & AVSS

ADC12IE = 0x01; // Enable ADC12IFG.0 for (i = 0; i < 0x3600; i++); // Delay for reference start-up ADC12CTL0 |= ENC; // Enable conversions __enable_interrupt(); // Enable interrupts while(1) { ADC12CTL0 |= ________________; // Start conversion __bis_SR_register(LPM0_bits); // Enter LPM0 // DegC = (Vsensor - 986mV)/3.55mV // Vsensor = (Vref)(ADCresult)/4095) // DegC -> ((ADCresult - 1615)*704)/4095 DegC = ((((long)ADCresult-1615)*704)/4095); DegF = ((DegC * 9/5)+32); // Calculate DegF __no_operation(); // SET BREAKPOINT HERE } } #pragma vector=ADC12_VECTOR __interrupt void ADC12ISR(void) { ADCresult = ADC12MEM0; // Move results, IFG is cleared __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0 }

3 - 14 MSP430 One Day Workshop - Analog Peripherals

Page 105: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

5. ADC12CTL0 = __________________________;

Search slau056f.pdf for ADC12CTL0. Somewhere in there you’ll find the bit field layout for the register. Search the header file for the same thing. Under about the fourth occurrence you’ll see the definitions for the individual bit fields.

Look around and find the following definitions:

Turn ADC12 on: _________________

Turn ADC12 reference on: _____________________

Set the reference to 2.5V: _______________________

Set the sampling time: _______________________

This last one is a little harder than the first three. First, we need to find out how fast we can sample the temperature sensor. Search the msp430fg4618.pdf or msp430fg4619.pdf datasheet for tSENSOR and you’ll see the following:

The ADC12 in this lab is set up to use the ADC12OSC as the clock source, so search the datasheet for fADC12OSC and find the following:

So, we need to make sure that the sampling timer uses enough clock cycles in the sample period to guarantee we meet the 30us sampling time required by the temperature sensor. Calculate the clock cycles needed and select a sampling time that has at least that many cycles.

Take all those definitions, put + signs in between them and type them in the proper blank. By the way, the order doesn’t matter since the definitions are all 16-bits.

6. ADC12CTL1 = _________________;

This one’s easy. Look in the header file for ADC12CTL1 and find the correct mode setting for the sample/hold field. Check the datasheet too, if necessary.

7. ADC12MCTL0 = ________________;

You should have it down by now, but this time search the header file for ADC12CTLx. Look in the definitions for Input Channel 10. You also have to select VREF+ using the SREFx field. A quick look at the mux near the top of the ADC12 block diagram in spau056g.pdf will give you a clue which one to pick.

MSP430 One Day Workshop - Analog Peripherals 3 - 15

Page 106: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

8. ADC12CTL0 |= ________________;

Last one. You should find it pretty quickly if you look in the header file under ADC12CTL0.

Test Your Work 9. Build and Download

You know what to do by now. Correct any errors you may find. When prompted to save your workspace, save it in the Lab4 folder as Lab4.eww.

10. Set a Breakpoint

Set a breakpoint on the line with the comment //SET BREAKPOINT HERE (wow, that was tough). If you’ve already looked through the code, you’ll see that this line is right after the temperature calculations are complete

11. Set a Watch

Right click on the DegC or DegF variable in the code right before the breakpoint. Select Add to Watch from the drop down menu. Right now the value should be 0.

12. Run

Run the code and it will quickly stop at the breakpoint you set. Observe the temperature in the Watch window on the right of the screen. Keep clicking the Go button while you place your finger on the FG4618/9 and watch the temperature rise.

Unfortunately, we didn’t properly calibrate the temperature before we started, so the temperature isn’t very accurate. But it’s close enough to understand the ADC12 functions.

13. Additional Information

Did you notice the line in the initialization with the comment //Delay for reference start-up ? The ADC12 module has a shortcoming, in that a 17mS delay is required after initializing the ADC in order for the reference to stabilize. A software loop is a terrible waste of cycles, but in this case we thought it would be simpler from a coding perspective.

If you have the time and the motivation, how about eliminating the loop and using Timer_A to delay those 17mS? Let your instructor know that you’re going to give this a try!

Shut Down 14. Shut Down

When done, click the Stop Debugging button and close IAR Embedded Workbench..

IAR Kickstart users … you’re done. Proceed to the review questions on page 3-21

3 - 16 MSP430 One Day Workshop - Analog Peripherals

Page 107: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

Code Composer Studio 4.1 Procedure In this lab, we’ll configure and use the ADC12 analog input in the FG4618/9 to measure the temperature from the internal thermistor. Touching the MSP430 will change the temperature enough to measure it, calculate it and place it in a memory for observation.

Start Up 1. JTAG

Assure that the JTAG interface is connected to the FG4618/9 debug port.

2. New Workspace, New Project

Start up CCS and create a new workspace at C:\MSP430ODW\CCS Labs\Lab4\workspace. Create a new project named Lab4 in the newly created workspace folder. Make sure the:

Project Type = MSP430

Device Variant = MSP430FG4618 or MSP430FG4619

Add Source File 3. Add the source file to the project

Add Lab4_exercise.c from the C:\MSP430\CCS Labs\Lab4 folder.

Complete the Code The following lab steps will walk you through filling in the blanks in the code as shown on the facing page. You’ll want to open the MSP430x4xx Family User’s Guide (slau056g.pdf), as well as the MSP430FG4618/9 datasheet (msp430fg4618.pdf or msp430fg4619.pdf). We’re also going to need to look at the standard definitions in the msp430xG46x.h header file:

Find the line in the code containing #include “msp430xG46x.h”. Right-click on the line and select Show In, then Outline. In the Outline pane (on the right), double-click on msp430xG46x.h to open that file in the editor.

If you want to take the easy way out, you’ll find the completed code in the Addendum chapter at the end of this workbook or you can peruse the solution file in the Lab4 folder.

If you’re a glutton for punishment, ignore the following steps and do it on your own. No one’s forcing you to do it our way!

MSP430 One Day Workshop - Analog Peripherals 3 - 17

Page 108: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

#include "msp430xG46x.h" volatile unsigned int i; volatile unsigned int ADCresult; volatile unsigned long int DegC, DegF; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer ADC12CTL0 = __________________________; // Turn ADC on, ref on. Ref = 2.5V,

// Set sampling time ADC12CTL1 = _________________; // Use sampling timer ADC12MCTL0 = ________________; // Select channel A10, Vref+ ADC12IE = 0x01; // Enable ADC12IFG.0 for (i = 0; i < 0x3600; i++); // Delay for reference start-up ADC12CTL0 |= ENC; // Enable conversions __enable_interrupt(); // Enable interrupts while(1) { ADC12CTL0 |= ________________; // Start conversion __bis_SR_register(LPM0_bits); // Enter LPM0 // DegC = (Vsensor - 986mV)/3.55mV // Vsensor = (Vref)(ADCresult)/4095) // DegC -> ((ADCresult - 1615)*704)/4095 DegC = ((((long)ADCresult-1615)*704)/4095); DegF = ((DegC * 9/5)+32); // Calculate DegF __no_operation(); // SET BREAKPOINT HERE } } #pragma vector=ADC12_VECTOR __interrupt void ADC12ISR(void) { ADCresult = ADC12MEM0; // Move results, IFG is cleared __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0 }

3 - 18 MSP430 One Day Workshop - Analog Peripherals

Page 109: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

4. ADC12CTL0 = __________________________;

Search slau056f.pdf for ADC12CTL0. Somewhere in there you’ll find the bit field layout for the register. Search the header file for the same thing. Under about the fourth occurrence you’ll see the definitions for the individual bit fields.

Look around and find the following definitions:

Turn ADC12 on: _________________

Turn ADC12 reference on: _____________________

Set the reference to 2.5V: _______________________

Set the sampling time: _______________________

This last one is a little harder than the first three. First, we need to find out how fast we can sample the temperature sensor. Search the msp430fg4618.pdf or msp430fg4619.pdf datasheet for tSENSOR and you’ll see the following:

The ADC12 in this lab is set up to use the ADC12OSC as the clock source, so search the datasheet for fADC12OSC and find the following:

So, we need to make sure that the sampling timer uses enough clock cycles in the sample period to guarantee we meet the 30us sampling time required by the temperature sensor. Calculate the clock cycles needed and select a sampling time that has at least that many cycles.

Take all those definitions, put + signs in between them and type them in the proper blank. By the way, the order doesn’t matter since the definitions are all 16-bits.

5. ADC12CTL1 = _________________;

This one’s easy. Look in the header file for ADC12CTL1 and find the correct mode setting for the sample/hold field. Check the datasheet too, if necessary.

6. ADC12MCTL0 = ________________;

You should have it down by now, but this time search the header file for ADC12CTLx. Look in the definitions for Input Channel 10. You also have to select VREF+ using the SREFx field. A quick look at the mux near the top of the ADC12 block diagram in spau056g.pdf will give you a clue which one to pick.

MSP430 One Day Workshop - Analog Peripherals 3 - 19

Page 110: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

7. ADC12CTL0 |= ________________;

Last one. You should find it pretty quickly if you look in the header file under ADC12CTL0.

Test Your Work 8. Build and Download

You know what to do by now. Correct any errors you may find.

9. Set a Breakpoint

Set a breakpoint on the line with the comment //SET BREAKPOINT HERE (wow, that was tough). If you’ve already looked through the code, you’ll see that this line is right after the temperature calculations are complete

10. Set a Watch

Double-click on the DegC or DegF variable in the code right before the breakpoint. Right-click on the selected variable, then select Add Watch Expression from the drop down menu. You should see a Watch tab in the upper right pane in CCS. If the Watch pane isn’t already open, click on the tab now.

11. Run

Run the code and it will quickly stop at the breakpoint you set. Observe the temperature in the Watch pane. Keep clicking the Run button while you place your finger on the FG4618/9 and watch the temperature rise.

Unfortunately, we didn’t properly calibrate the temperature before we started, so the temperature isn’t very accurate. But it’s close enough to understand the ADC12 functions.

12. Additional Information

Did you notice the line in the initialization with the comment //Delay for reference start-up ? The ADC12 module has a shortcoming, in that a 17mS delay is required after initializing the ADC in order for the reference to stabilize. A software loop is a terrible waste of cycles, but in this case we thought it would be simpler from a coding perspective.

If you have the time and the motivation, how about eliminating the loop and using Timer_A to delay those 17mS? Let your instructor know that you’re going to give this a try!

Shut Down 13. Shut Down

When done, click the Terminate All button and close Code Composer Studio.

Code Composer Studio users … you’re done

3 - 20 MSP430 One Day Workshop - Analog Peripherals

Page 111: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

Review Questions

ReviewWhat is your lowest power option for triggering an ADC?

Name the four ADC conversion modes:

What is the purpose of the DTC?

ADC10 and ADC12 can sample at what speed?

You can find the answers to these questions in the Addendum section at the end of this workbook.

MSP430 One Day Workshop - Analog Peripherals 3 - 21

Page 112: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

*** Why can’t we do this outside? ***

3 - 22 MSP430 One Day Workshop - Analog Peripherals

Page 113: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Timers

Introduction In many microprocessors, timers are used for determining simple intervals. The MSP430 timers are significantly more capable. They can be used to generate multiple PWM frequencies, control ADC hardware or even implement a UART port. Let’s learn a bit more about then now.

Objectives • Timer_A Architecture

• Count modes

• Interrupts

• TAIV

• Timer_B differences

• Timer lab

MSP430 One Day Workshop - Timers 4 - 1

Page 114: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

*** This page left blank with malice aforethought ***

4 - 2 MSP430 One Day Workshop - Timers

Page 115: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Module Topics Timers......................................................................................................................................................... 4-1

Module Topics......................................................................................................................................... 4-3 Timer_A ............................................................................................................................................. 4-5 Counting Modes ................................................................................................................................. 4-5 Interrupts ............................................................................................................................................ 4-6 TAIV Handler..................................................................................................................................... 4-6 PWM Example ................................................................................................................................... 4-7 Direct Hardware Control .................................................................................................................... 4-7 UART Implementation ....................................................................................................................... 4-8 Timer B............................................................................................................................................... 4-8

Lab 5 – Timer_A ..................................................................................................................................... 4-9 Hardware list: ....................................................................................................................................4-10 Software list:......................................................................................................................................4-10

IAR Kickstart Procedure........................................................................................................................4-11 Start-up ..............................................................................................................................................4-11 Add Source File .................................................................................................................................4-11 Complete the Code ............................................................................................................................4-11 Shut Down.........................................................................................................................................4-14

Code Composer Studio 4.1 Procedure...................................................................................................4-15 Start-up ..............................................................................................................................................4-15 Add Source File .................................................................................................................................4-15 Complete the Code ............................................................................................................................4-15 Shut Down.........................................................................................................................................4-18

Review Questions ...................................................................................................................................4-19

MSP430 One Day Workshop - Timers 4 - 3

Page 116: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

*** Blank! Blank! My kingdom for a blank! ***

4 - 4 MSP430 One Day Workshop - Timers

Page 117: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Timer_A

Timer_A

Asynchronous16-Bit timer/counter Continuous,up-down,up count modesMultiple capture/compare registersPWM outputsInterrupt vectorregister for fastdecoding Can trigger DMA transferOn all MSP430s

Compararator 2

CCI

CountMode

SetTAIFG

TACCR2

ACLKSMCLK

TACLK

INCLK

GNDVCC

CCI2ACCI2B

SetCCIFG2

Ou tputUnit2

CCR0

SCCI Y AEN

CCR1

CCR2

Ca ptureMod e

16-bit TimerTAR

Counting Modes …

Counting Modes

Timer_A Counting Modes

0FFFFh

0h

CCR0

Stop/Halt Timer is halted

UpTimer counts between 0 and CCR0

0FFFFh

0h

Continuous Timer continuously counts up

0FFFFh

0h

CCR0

UP/DOWN Mode

Up/Down Timer counts between 0 and CCR0 and 0

CCR – Count Compare RegisterInterrupts …

MSP430 One Day Workshop - Timers 4 - 5

Page 118: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Interrupts

Timer_A Interrupts

TACCR1 CCIFG

TACCR2 CCIFG

TAIFG

TIMERA1_VECTORTAIV

TACCR1, 2 and TA interrupt flags are prioritized and combined using the Timer_A Interrupt Vector Register (TAIV) into anotherinterrupt vector

TACCR0 CCIFG TIMERA0_VECTOR

The Timer_A Capture/Comparison Register 0 Interrupt Flag (TACCR0) generates a single interrupt vector:

Your code must contain a handler to determine which Timer_A1 interrupt triggered

No handler required

TAIV …

TAIV Handler

TAIV Handler Example

#pragma vector = TIMERA1_VECTOR__interrupt void TIMERA1_ISR(void){

switch(__even_in_range(TAIV,10)){

case 2 : // TACCR1 CCIFGP1OUT ^= 0x04; break;

case 4 : // TACCR2 CCIFGP1OUT ^= 0x02; break;

case 10 : // TAIFGP1OUT ^= 0x01; break;

}}

#pragma vector = TIMERA1_VECTOR__interrupt void TIMERA1_ISR(void){

switch({

case 2 : // TACCR1 CCIFGP1OUT ^= 0x04; break;

case 4 : // TACCR2 CCIFGP1OUT ^= 0x02; break;

case 10 : // TAIFGP1OUT ^= 0x01; break;

}}

0xF814 add.0xF818 reti0xF81A jmp 0xF8240xF81C jmp 0xF82A0xF81E reti0xF820 reti0xF822 jmp 0xF8300xF824 xor.b #0x4,&P1OUT0xF828 reti0xF82A xor.b #0x2,&P1OUT0xF82E reti0xF830 xor.b #0x1,&P1OUT0xF834 reti

__even_in_range(TAIV,10))

w &TAIV,PC0xF814 0xF818 reti0xF81A jmp 0xF8240xF81C jmp 0xF82A0xF81E reti0xF820 reti0xF822 jmp 0xF8300xF824 xor.b #0x4,&P1OUT0xF828 reti0xF82A xor.b #0x2,&P1OUT0xF82E reti0xF830 xor.b #0x1,&P1OUT0xF834 reti

IAR C code Assembly code

Source TAIV Contents

add.w &TAIV,PC

No interrupt pending 0TACCR1 CCIFGTACCR2 CCIFG ReservedReserved TAIFGReservedReserved

02h04h06h08h0Ah0Ch0Eh

0TAIV

15xxxx000000000 00

0

PWM …

4 - 6 MSP430 One Day Workshop - Timers

Page 119: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

PWM Example

Completely automaticIndependent frequencies with different duty cycles can be generated for each CCRCode examples on the MSP430 website

Timer_A PWM Example

TESTVccP2.5VssXOUTXINRSTP2.0P2.1P2.2

TA2/P1.7P1.6P1.5P1.4P1.3

TA1/P1.2P1.1P1.0P2.4P2.3

MSP430F11x1

CCR0

C CR1

CCR0

CCR1

CCR0

CCR1

CCR2 CCR2 CCR2

ADC12 Control …

Direct Hardware Control

Direct Hardware Control With Timer_A

TACCR1:Ref delay / ADC trigger

TAIFG:

TAR

0

TACCR1 = 557

65536

CPU Active Mode

17ms

2s

Reference & ADC on

ADC12IFG:Process ADC result

Ref/ADC Off

Example: ADC12

UART ...

MSP430 One Day Workshop - Timers 4 - 7

Page 120: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

UART Implementation

Low-Overhead UART Implementation

100% hardware bit latching and outputFull speed from LPM3 and LPM4Low CPU OverheadApp Note SLAA078 on web

P2.2/ TA0 TA0/P1.1MSP430

Start - CCR0 = TAR- add 1.5 bit length to CCR0- switch to compare mode

compare - logic level latched in SCCI - add 1 bit length to CCR0

Stop

OUTMODx

OutputUnit0

SCCI Y AEN Capture/Compare

TXD

RXD

Timer_B …

Timer B

Timer_B Differences

8,10,12 or 16-bit timer or counterUp to 7 CCRx units availableOutputs double-buffered for simultaneous loadingCCRx registers can be grouped for simultaneous updatesSCCI latch not implemented (no UART function)Tri-state function from external pinDefault Function is identical to Timer_A

Lab5 …

4 - 8 MSP430 One Day Workshop - Timers

Page 121: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Lab 5 – Timer_ALet’s configure a timer to wake the MSP430 from a low power mode and blink an LED. Granted, that’s a pretty simple task, but the idea here is to learn how to program the timer.

Lab5: Timer_A

FET

Configure Timer_A on the MSP430FG4618/9 to wake up the CPU and toggle an LED

Review …

MSP430 One Day Workshop - Timers 4 - 9

Page 122: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Hardware list: WinXP PC

MSP-FET430UIF

USB cable

JTAG ribbon cable

MSP430FG461x/F28xx Experimenter’s Board

Jumpers

Software list: IAR Kickstart for MSP430 version 4.21B

Code Composer Studio 4.1

Labs

Additional pdf documentation

Adobe™ Reader

4 - 10 MSP430 One Day Workshop - Timers

Page 123: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

IAR Kickstart Procedure Configure a timer to wake up the CPU from a low power mode and blink an LED … pretty straight-forward.

Start-up 1. Hardware

Assure that the debug interface is correctly connected to the PC and the FG4618/9 debug port.

2. Start IAR

Start IAR Kickstart. Create a new workspace and a new project in the Lab5 folder. Configure the project options as shown earlier.

Add Source File 3. Add the source file to the project

Add Lab5_exercise.c from the C:\MSP430\IAR Labs\Lab5 folder to the project. Double-click on the file in the Project pane to open it for editing.

Complete the Code Like the previous lab, the next steps will lead you though the process of filling in the four blanks in the code. You should already have the process down, though, so we won’t give you nearly the level of detail as you had in the previous lab.

You’ll probably want to open slau056g.pdf and the msp430xG46x.h header file.

Again, if you’re lazy and want to skip to the solution, you can either look in the Addendum at the back of this workbook or open up the solution file.

MSP430 One Day Workshop - Timers 4 - 11

Page 124: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

#include <msp430xG46x.h>

void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

FLL_CTL0 |= XCAP14PF; // Configure load caps

P2DIR |= BIT1; // Set P2.1 to output direction

TACTL = ________________; // Clock = ACLK (32768), clear

TACCTL0 = ____; // CCR0 interrupt enabled

TACCR0 = _______; // #counts for 1s

TACTL |= ____; // Setting mode bits starts timer

_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupt

}

// Timer A0 interrupt service routine

#pragma vector=TIMERA0_VECTOR

__interrupt void Timer_A (void)

{

P2OUT ^= 0x02; // Toggle P2.1 using exclusive-OR

}

4 - 12 MSP430 One Day Workshop - Timers

Page 125: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

4. TACTL = ___________________;

Clock = ACLK (32768Hz)

To set the clock source select to ACLK you’re going to need to know how the TASSELx field is configured. That’s enough of a hint …

Clear

Finding the counter clear is pretty easy.

5. TACCTL0 = ______________;

Enable CCR0 interrupt

Enable the capture/compare interrupt. If you’ve ever been geo-caching, this process is analogous. The GPS will get you close, but then you’ve got to hunt around on your hands and knees for the prize.

6. TACCR0 = ________________;

Number of counts for one second

This one takes just a little bit of thought. What’s the clock frequency we’re using to drive the timer? (Hint: We selected it in step 4). How many clock cycles would equal one second? Bear in mind that when the timer rolls over to zero, that is also counted as a tick, so to get n ticks, you put n-1 in the CCR0 register.

7. TACTL |= ________________;

Check the User’s Guide and make sure which mode you want the timer to operate in, then find the correct symbol in the header file.

8. Build, Download and Run

Try out the code and make sure it works properly. Correct any errors you may have. Observe the LED and verify that it blinks at the proper interval. Feel free to play around with the interval period in the code.

MSP430 One Day Workshop - Timers 4 - 13

Page 126: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

9. A Few More Questions

Here’s a great opportunity to show off your ability to search the User’s Guide. The answers are in the Addendum at the back of this workbook.

Why was TAIE not set in TACTL?

Why were the MCx bits not set initially when TACTL was configured?

Shut Down 10. Shut down

Halt the debugger and shut down IAR Kickstart.

IAR Users … you’re done. Proceed to the review questions on page 4-19.

4 - 14 MSP430 One Day Workshop - Timers

Page 127: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

Code Composer Studio 4.1 Procedure Configure a timer to wake up the CPU from a low power mode and blink an LED … pretty straight-forward.

Start-up 1. Hardware

Assure that the debug interface is correctly connected to the PC and the FG4618/9 debug port.

2. Start CCS

Start CCS. Create a new workspace in C:\MSP430ODW\CCS Labs\Lab5\workspace and a new project in the folder called Lab5. Configure the project settings as shown earlier.

Add Source File 3. Add the source file to the project

Add Lab5_exercise.c from the C:\MSP430\CCS Labs\Lab5 folder to the project. Double-click on the file in the Project pane to open it for editing.

Complete the Code Like the previous lab, the next steps will lead you though the process of filling in the four blanks in the code. You should already have the process down, though, so we won’t give you nearly the level of detail as you had in the previous lab.

You’ll probably want to open slau056g.pdf and the msp430xG46x.h header file.

Again, if you’re lazy and want to skip to the solution, you can either look in the Addendum at the back of this workbook or open up the solution file.

MSP430 One Day Workshop - Timers 4 - 15

Page 128: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

#include <msp430xG46x.h>

void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

FLL_CTL0 |= XCAP14PF; // Configure load caps

P2DIR |= BIT1; // Set P2.1 to output direction

TACTL = ________________; // Clock = ACLK (32768), clear

TACCTL0 = ____; // CCR0 interrupt enabled

TACCR0 = _______; // #counts for 1s

TACTL |= ____; // Setting mode bits starts timer

_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupt

}

// Timer A0 interrupt service routine

#pragma vector=TIMERA0_VECTOR

__interrupt void Timer_A (void)

{

P2OUT ^= 0x02; // Toggle P2.1 using exclusive-OR

}

4 - 16 MSP430 One Day Workshop - Timers

Page 129: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

4. TACTL = ___________________;

Clock = ACLK (32768Hz)

To set the clock source select to ACLK you’re going to need to know how the TASSELx field is configured. That’s enough of a hint …

Clear

Finding the counter clear is pretty easy.

5. TACCTL0 = ______________;

Enable CCR0 interrupt

Enable the capture/compare interrupt. If you’ve ever been geo-caching, this process is analogous. The GPS will get you close, but then you’ve got to hunt around on your hands and knees for the prize.

6. TACCR0 = ________________;

Number of counts for one second

This one takes just a little bit of thought. What’s the clock frequency we’re using to drive the timer? (Hint: We selected it in step 4). How many clock cycles would equal one second? Bear in mind that when the timer rolls over to zero, that is also counted as a tick, so to get n ticks, you put n-1 in the CCR0 register.

7. TACTL |= ________________;

Check the User’s Guide and make sure which mode you want the timer to operate in, then find the correct symbol in the header file.

8. Build, Download and Run

Try out the code and make sure it works properly. Correct any errors you may have. Observe the LED and verify that it blinks at the proper interval. Feel free to play around with the interval period in the code.

MSP430 One Day Workshop - Timers 4 - 17

Page 130: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

9. A Few More Questions

Here’s a great opportunity to show off your ability to search the User’s Guide. The answers are in the Addendum at the back of this workbook.

Why was TAIE not set in TACTL?

Why were the MCx bits not set initially when TACTL was configured?

Shut Down 10. Shut down

Halt the debugger and shut down Code Composer Studio.

CCS Users … you’re done.

4 - 18 MSP430 One Day Workshop - Timers

Page 131: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Review Questions

Review Questions Review

Name the counting modes.

What is the TAIV register's purpose?

In addition to normal timer functions, name some other functions the timer can perform.

You can find the answers to these questions in the Addendum section at the end of this workbook.

MSP430 One Day Workshop - Timers 4 - 19

Page 132: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Review Questions

*** !KCOR s034PSM ***

4 - 20 MSP430 One Day Workshop - Timers

Page 133: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Communication

Introduction In this module we’ll take a look at the MSP430 communications modules and the protocols that can be implemented over them.

Objectives • USART

• USCI

• USI

MSP430 One Day Workshop - Communication 5 - 1

Page 134: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

*** I only insert blank pages when the voices tell me to***

5 - 2 MSP430 One Day Workshop - Communication

Page 135: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Module Topics Communication ......................................................................................................................................... 5-1

Module Topics......................................................................................................................................... 5-3 MSP430 Communication Modules..................................................................................................... 5-5 USI...................................................................................................................................................... 5-5 Data I/O via USI................................................................................................................................. 5-6 SPI via USI ......................................................................................................................................... 5-6 USART............................................................................................................................................... 5-7 Baudrate Generator............................................................................................................................. 5-7 USCI................................................................................................................................................... 5-8 USCI Initialization Sequence ............................................................................................................. 5-8 USCI Enhanced Features.................................................................................................................... 5-9 USCI Baudrate Generator................................................................................................................... 5-9

Optional Lab 6 – I2C Communications .................................................................................................5-11 Hardware list: ....................................................................................................................................5-12 Software list:......................................................................................................................................5-12

IAR Kickstart Procedure........................................................................................................................5-13 Set up the Hardware ..........................................................................................................................5-13 Load the MSP430F2013 Software.....................................................................................................5-13 Set up for the FG4618/9 ....................................................................................................................5-13 Complete the I2C Master Code .........................................................................................................5-14 Build/Load/Run/Test .........................................................................................................................5-15 Shut Down.........................................................................................................................................5-15

Code Composer Studio Procedure.........................................................................................................5-17 Set up the Hardware ..........................................................................................................................5-17 Load the MSP430F2013 Software.....................................................................................................5-17 Set up for the FG4618/9 ....................................................................................................................5-18 Complete the I2C Master Code .........................................................................................................5-18 Build/Load/Run/Test .........................................................................................................................5-19 Shut Down.........................................................................................................................................5-20

Review Questions ...................................................................................................................................5-21

MSP430 One Day Workshop - Communication 5 - 3

Page 136: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

*** For security reasons this page must be left blank ***

5 - 4 MSP430 One Day Workshop - Communication

Page 137: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

MSP430 Communication Modules

MSP430 Communication Modules

- SW state machine needed- Master and slave modes

- Simplified interrupt usage- Master and slave modes - Up to 400kbps

(on ‘15x/’16x only)- Master and slave

modes- Up to 400kbps

- One SPI available- Master and slave modes

Two SPI (one each on USCI_A and USCI_B)

- Master and slave modes- 3 and 4 wire modes

One SPI channel- Master and slave

modes- 3 and 4 wire modes

- - -

Two modulators; supports n/16 timings

- Auto baud rate detection- IrDA encoder & decoder- Simultaneous USCI_A . and USCI_B (2 channels)

One modulator

Universal SerialInterface

Universal SerialCommunication

Interface

Universal Synch/Async

Receiver/Transmitter

USART USCI USI

SPI

I2C

UART

USI …

USI

USIMSP430x20xx devicesVariable length shift registerSupports I2C

START/STOP detectionSCL held after STARTSCL held after counter overflowArbitration lost detection

Supports SPI8/16-bit Shift RegisterMSB/LSB first

Flexible ClockingInterrupt Driven

8/16-Bit Shift Register

SDASDI

SCLSCLK

USIIFG

USIIFG

USISTTIFG

SMCLK

SCLKACLK

TA1TA2

SWCLKTA0

DividerHOLD

USIIFG

SCL Hold

Bit Counter STARTSTOPDetect

SDO

USISTTIFGUSISTP

Data I/O …

MSP430 One Day Workshop - Communication 5 - 5

Page 138: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Data I/O via USI

USI for Data I/O

Data shift register: up to 16 bits supportedNumber of bits transmitted and received is controlled by a bit counterTransmit and Receive is simultaneousData I/O is user-defined: MSB or LSB firstBit counter automatically stops clocking after last bit & sets flagNo data buffering needed

USISSELx

USIIFG

Data ShiftRegister

Data I/O

USICNTx

Bit Counter Set USIIFG

SMCLKSMCLK

SCLKACLK

TA1TA2

USISWCLKTA0

Clock Divider/1/2/4/8…/128

USID IVx

HOLD

SPI Implementation …

SPI via USI

//Shift16_inout_SoftwareSR = DATA;for (CNT=0x10;CNT>0;CNT--){P2OUT &= ~SDO; if (SR & 0x8000)P2OUT |= SDO; SR = SR << 1;if (P2IN & SDIN)SR |= 0x01;

P2OUT |= SCLK; P2OUT &= ~SCLK;

}

//Shift16_inout_SoftwareSR = DATA;for (CNT=0x10;CNT>0;CNT--){P2OUT &= ~SDO; if (SR & 0x8000)P2OUT |= SDO; SR = SR << 1;if (P2IN & SDIN)SR |= 0x01;

P2OUT |= SCLK; P2OUT &= ~SCLK;

}

USI Reduces CPU Load for SPI

425 Cycles

10 Cycles

// Shift16_inout_USIUSISR |= DATA;USICNT |= 0x10;

// Shift16_inout_USIUSISR |= DATA;USICNT |= 0x10;

Peripheral

SDOSCLK

SDIN

MSP430

I2C Slave has as little as 4us from clock edge to dataTraditional software-only solution allows time for little elseUSI hardware enables practical and compliant I2CCode on MSP430 website

USART …

5 - 6 MSP430 One Day Workshop - Communication

Page 139: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

USART

USART

Ultra-Low Power Support:Auto-Start from any Low-Power Mode

UART or SPI Mode(I2C on ‘F15x/’F16x only)Double Buffered TX/RXBaudrate GeneratorDMA enabledError Detection

UxRXBUF

URXD

SMCLK

UCLKIACLK

SMCLK

Receiver Shift Register

Baud-Rate Generator

Transmit Shift Register

UxTXBUF

Clock Phase and Polarity UCLK

UTXD

SOMI

SIMO

STE

Recommended USART initialization/re-configuration process is shown in your workbook.

Baudrate Generator …

Baudrate Generator

USART Baudrate Generator

15-Bit Prescaler/Div ider

UxBR0

Modulator BITCLK

UxBR187

UCLKIACLK

SMCLKSMCLK

15

9600 baud:ACLK = 32768 Hz

Prescaler = 32768Hz/9600baud = 3.41

UxBR1 | UxBR0 | = 00h | 03h |

UxMCTL8

UxMCTL 4Ah

D0 D1 D2 D3 D4 D5 D6 D7ST ST

BITCLK = ACLK/3 /4 /3 /4 /3 /3 /4 /3 . . .

Content of UxMCTL is the modulation pattern

USCI …

MSP430 One Day Workshop - Communication 5 - 7

Page 140: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

USCI

USCI: Universal Serial Comm I/FUART with IrDA/LIN support or SPIBaud-rate generator with auto-baud rate detectDouble buffered TX/RX

U SCI_A

USCI_B

I2C

Bitc lock Generator

SPI

Transmit Shift Register

Transmit Buffer UC1TXBUF

I2C Bus Interface

Receive Buffer UC1RXBUF

Receive Shift Register

UCB0SIMO

UCB0SOMI

Baud ra te G en era tor

IrD A Deco de r

SPI

UART

Tra nsm it Buf fer UC0TXBUF I rDA En cod er

Tra nsm it Shift Reg ister

Rece ive Bu ffer UC 0RXBU F

Rece ive Sh ift Re giste r

UC A0 TXD

UCA0R XD

I2C master/slave up to 400kHz or SPIBit clock generatorDouble buffered TX/RXs

USCI_A

USCI_B

Designed for Ultra-Low Power …Auto-Start from any Low-Power ModeRecommended USCI initialization/re-configuration process is shown in your workbook

Enhanced features …

USCI Initialization Sequence

5 - 8 MSP430 One Day Workshop - Communication

Page 141: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

USCI Enhanced Features

USCI Enhanced FeaturesNew standard MSP430 serial interfaceAuto clock start from any LPMxTwo independent communication blocksAsynchronous communication modes

UART standard and multiprocessor protocolsUART with automatic Baud rate detection (LIN support)Two modulators support n/16 bit timingIrDA bit shaping encoder and decoder

Synchronous communication modes SPI (Master & Slave modes, 3 & 4 wire)I2C (Master & Slave modes)

UxRXBUF

URXD

SMCLKUCLKIACLK

SM CLK

Rece iver Sh ift Reg ister

Baud-Rate Generator

Transmit Sh ift Reg ister

UxTXBUF

Clock Phase and Polarity UCLK

UTXD

SOMI

SIMO

STE

Baudrate Generator …

USCI Baudrate Generator

USCI Baudrate Generator

Prescaler/Divider

UCAxBR0

1st Modulator BITCLK16

UCAxBR188

UCBRSx3

UC0CLKACLK

SMCLKSMCLK

LSB

/16

2nd Modulator BITCLK

UCBRFx4

BITCLK16

1 Bit

RXD

Sampling for majority votes

Oversampling Baud Rate GenerationTwo Modulators:

UCBRSx and UCBRFx select modulation patternRX sampled using BITCLK16

Optional Lab6 …

MSP430 One Day Workshop - Communication 5 - 9

Page 142: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

*** War and Peace started this way ***

5 - 10 MSP430 One Day Workshop - Communication

Page 143: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Optional Lab 6 – I2C CommunicationsThis lab should be attempted if time permits during the class or as a take-home project for the student.

The MSP430F2013 is used to measure the temperature. It then transmits the result to the MSP430FG4618/9 via the I2C connection on the USCI port. The MSP430FG4618/9 will then determine if a preset difference has been reached, at which point it will light LED4. The MSP430F2013 will also flash LED3 each communication cycle. In this I2C implementation, the MSP430F2013 will be the slave and the MSP430FG4618/9 will be the master.

Optional Lab6: I2C Communication

I2C Master on the FG4618/9 USCI receives the 16-bit conversion result from the F2013 SlaveF2013 slave flashes LED3 with each communication cycleWhen the result-to-result difference exceeds a preset amount, the FG4618/9 I2C Master turns LED4 on

FG4619I2C MST

F2013I2C SLVLED4

SD16_A 16-bit Temperature Conversion Data

SDA

SCLLED3

Complete this lab if time permits or as a take-home project

Review …

MSP430 One Day Workshop - Communication 5 - 11

Page 144: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Module Topics

Hardware list: WinXP PC

MSP-FET430UIF

USB cable

JTAG ribbon cable

MSP430FG461x/F28xx Experimenter’s Board

Jumpers

Software list: IAR Kickstart for MSP430 version 4.21B

Code Composer Studio 4.1

Labs

Additional pdf documentation

Adobe™ Reader

5 - 12 MSP430 One Day Workshop - Communication

Page 145: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

IAR Kickstart Procedure In this lab, you will complete an I2C data link between the two MSP430s on the Experimenter’s Board. Our tasks will be to:

• Load ready-to-use USI I2C slave code on the MSP430F2013 (slave address = 0x48)

• Complete partial MSP430FG4618/9 USCI_B I2C Master Receiver code

Set up the Hardware 1. JTAG

The first thing we’re going to do is to load the ready-to-use I2C slave code into the MSP430F2013. Remove the JTAG ribbon cable from the MSP430FG4618/9 debug port and place it in the MSP430F2013 debug port.

Load the MSP430F2013 Software Note: Please do not load the MSP430F2013 code into the MSP430FG4618/9!

2. Load the I2C Software into the MSP430F2013

Open IAR Kickstart, create a new workspace and project called Lab6 in the IAR Labs\Lab6 folder. Don’t forget to set the project options with the target device being the MSP430F2013.

Add Lab6_2013_solution.c to the project and build/load it to the MSP430F2013. Feel free to open the code in the editor and take a look at it.

Click the Go button to start the MSP430F2013 I2C slave code running. You’ll probably have no visual indication that the code is running. Exit the debugger by clicking the Stop Debugging button. Now you should be looking at the editor window in IAR Kickstart.

Set up for the FG4618/9 3. Set up for the MSP430FG4618/9 I2C Master Code

Swap the JTAG connector to the MSP430FG4618/9 debug port.

Close the Lab6_2013_solution.c code in the editor window (if you still have it open). Right-click on the file in the Workspace window and select Remove, then click Yes.

Add Lab6_4618_exercise.c to the project. Change the project option target device to the MSP430FG4618 or MSP430FG4619.

Open the source file in the editor and feel free to look around in it.

MSP430 One Day Workshop - Communication 5 - 13

Page 146: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

Complete the I2C Master Code Let’s fill in the blanks one at the time in the code extract below. Lazy folks can reference the solutions …

P3SEL |= 0x06; // Assign I2C pins to USCI_B0

UCB0CTL1 |= _______; // Enable SW reset (why?)

UCB0CTL0 = _________________________; // I2C Master, synchronous mode

UCB0CTL1 = __________________; // Use SMCLK, keep UCSWRST set

UCB0BR0 = 11; // fSCL = SMCLK/11 = 95.3kHz

UCB0BR1 = 0;

UCB0I2CSA = 0x48; // Set slave address

UCB0CTL1 &= ~_______; // Clear SW reset, resume operation

UCB0I2CIE |= UCNACKIE; // Interrupt on slave Nack

IE2 |= UCB0RXIE; // Enable RX interrupt

4. UCB0CTL1 |= _______;

It’s pretty easy to find the USCI software reset in the UCB0CTL1 section of the header file. Why do you think the USCI should be in reset while you’re programming its bits? Gee, that’s a tough one …

5. UCB0CTL0 = _________________________;

I2C Master

Look for the master mode select in the UCB0CTL0 section.

Synchronous mode

A quick look at the Initialization and Reset chapter of the USCI/I2C section will tell you that the UCMODEx bits must be set properly to be in I2C mode. In addition, you must select the synchronous mode.

6. UCB0CTL1 = __________________;

Clock source

You must select the appropriate USCI clock source to use SMCLK. In this case, that’s source 2. Verify that in the User’s Guide.

Keep UCSWRST set

Make sure the USCI software reset stays set,

5 - 14 MSP430 One Day Workshop - Communication

Page 147: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

7. UCB0CTL1 &= ~_______

This one’s easy. Now that everything is all set up, you can clear the USCI software reset.

Build/Load/Run/Test 8. Build/Load/Run

Compile the code, download it to the MSP430FG4618/9 and run it. LED3 (next to the MSP430F2013 debug port) should be blinking about once every 2 seconds.

9. Test the Code

With the code running, place your fingertip on the MSP430F2013 device (the little one next to the MSP430F2013 debug port). After a few seconds, LED4 (underneath the LCD display) should light. Remove your finger and the LED will quickly go off. Look around in the MSP430FG4618/9 code to see what the threshold is to light the LED. Change it if you like.

Shut Down 10. Shut down

Shut down IAR Kickstart. Disconnect the JTAG debug interface from both the Experimenter’s Board and the PC.

IAR Users … you’re done. Proceed to the review questions on page 5-21.

MSP430 One Day Workshop - Communication 5 - 15

Page 148: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

IAR Kickstart Procedure

*** It’s about time for a refreshment, I think ***

5 - 16 MSP430 One Day Workshop - Communication

Page 149: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

Code Composer Studio 4.1 Procedure In this lab, you will complete an I2C data link between the two MSP430s on the Experimenter’s Board. Our tasks will be to:

• Load ready-to-use USI I2C slave code on the MSP430F2013 (slave address = 0x48)

• Complete partial MSP430FG4618/9 USCI_B I2C Master Receiver code

Set up the Hardware 1. JTAG

The first thing we’re going to do is to load the ready-to-use I2C slave code into the MSP430F2013. Remove the JTAG ribbon cable from the MSP430FG4618/9 debug port and place it in the MSP430F2013 debug port.

Load the MSP430F2013 Software Note: Please do not load the MSP430F2013 code into the MSP430FG4618/9!

2. Load the I2C Software into the MSP430F2013

Open CCS, create a new workspace in the CCS Labs\Lab6 folder. Create a new project in that workspace folder called Lab6_2013. Don’t forget to set the project options with the target device being the MSP430F2013.

Add Lab6_2013_solution.c to the project and build/load it to the MSP430F2013. Feel free to open the code in the editor and take a look at it.

Click the Run button to start the MSP430F2013 I2C slave code running. You’ll probably have no visual indication that the code is running. Exit the debugger by clicking the Terminate All button. Now you should be looking at the editor window in Code Composer Studio.

MSP430 One Day Workshop - Communication 5 - 17

Page 150: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

Set up for the FG4618/9 3. Set up for the MSP430FG4618/9 I2C Master Code

Swap the JTAG connector to the MSP430FG4618/9 debug port.

Close the Lab6_2013_solution.c code in the editor window (if you still have it open). We could delete the source file from the project, but …

CAUTION: Eclipse (the editor used here) actually deletes the source file from the workspace folder. In our case, that’s not an issue. When we added our source file, Eclipse made a copy of our source file in the workspace folder. But if you store your original source files in the workspace folder, they will be deleted in this process. Consider yourself warned.

Instead, let’s do something a little more interesting. Create a new project in this workspace called Lab6_4618 (I know, that’s not a very imaginative name). Don’t forget to set the project options with the target device being the MSP430FG4618 (or 19). Check this out … now our workspace has two projects in it. Imagine the possibilities.

Lab6_4618 is now the Active Project (notice the project pane). Add Lab6_4618_exercise.c to the project. We can easily switch between projects by right-clicking on the project and selecting Set as Active Project. But, leave Lab6_4618 as the active project now.

Open the Lab6_4618_exercise.c source file in the editor and feel free to look around in it.

Complete the I2C Master Code Let’s fill in the blanks one at the time in the code extract below. Lazy folks can reference the solutions …

P3SEL |= 0x06; // Assign I2C pins to USCI_B0

UCB0CTL1 |= _______; // Enable SW reset (why?)

UCB0CTL0 = _________________________; // I2C Master, synchronous mode

UCB0CTL1 = __________________; // Use SMCLK, keep UCSWRST set

UCB0BR0 = 11; // fSCL = SMCLK/11 = 95.3kHz

UCB0BR1 = 0;

UCB0I2CSA = 0x48; // Set slave address

UCB0CTL1 &= ~_______; // Clear SW reset, resume operation

UCB0I2CIE |= UCNACKIE; // Interrupt on slave Nack

IE2 |= UCB0RXIE; // Enable RX interrupt

5 - 18 MSP430 One Day Workshop - Communication

Page 151: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

4. UCB0CTL1 |= _______;

It’s pretty easy to find the USCI software reset in the UCB0CTL1 section of the header file. Why do you think the USCI should be in reset while you’re programming its bits? Gee, that’s a tough one …

5. UCB0CTL0 = _________________________;

I2C Master

Look for the master mode select in the UCB0CTL0 section.

Synchronous mode

A quick look at the Initialization and Reset chapter of the USCI/I2C section will tell you that the UCMODEx bits must be set properly to be in I2C mode. In addition, you must select the synchronous mode.

6. UCB0CTL1 = __________________;

Clock source

You must select the appropriate USCI clock source to use SMCLK. In this case, that’s source 2. Verify that in the User’s Guide.

Keep UCSWRST set

Make sure the USCI software reset stays set.

7. UCB0CTL1 &= ~_______

This one’s easy. Now that everything is all set up, you can clear the USCI software reset.

Build/Load/Run/Test 8. Build/Load/Run

Compile the code, download it to the MSP430FG4618/9 and run it. LED3 (next to the MSP430F2013 debug port) should be blinking about once every 2 seconds.

9. Test the Code

With the code running, place your fingertip on the MSP430F2013 device (the little one next to the MSP430F2013 debug port). After a few seconds, LED4 (underneath the LCD display) should light. Remove your finger and the LED will quickly go off. Look around in the MSP430FG4618/9 code to see what the threshold is to light the LED. Change it if you like.

MSP430 One Day Workshop - Communication 5 - 19

Page 152: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Code Composer Studio 4.1 Procedure

Shut Down 10. Shut down

Shut down Code Composer Studio. Disconnect the JTAG debug interface from both the Experimenter’s Board and the PC.

CCS Users … you’re done.

5 - 20 MSP430 One Day Workshop - Communication

Page 153: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Review Questions

Review Questions

ReviewThe new, standard MSP430 serial comm. module is:

Implementing SPI on the USI or USCI provides a ___________ and __________ solution.

The best place to look for code examples is:

The best place to find technical documentation is:

You can find the answers to these questions in the Addendum section at the end of this workbook.

MSP430 One Day Workshop - Communication 5 - 21

Page 154: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Review Questions

*** Relax, it’s almost over ***

5 - 22 MSP430 One Day Workshop - Communication

Page 155: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Wrap-Up

Introduction It’s been a long day, or at least it’s felt that way. Here are some things not to forget.

MSP430 One Day Workshop – Wrap-up 6 - 1

Page 156: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Wrap-up

*** Oh, the untapped potential of a page left blank. ***

6 - 2 MSP430 One Day Workshop – Wrap-up

Page 157: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Wrap-up

Wrap-up

Wrap-upMSP430

16-BitUltra-low powerEasy-to-use1k-256kB ISP Flash14-100 pin optionsUSART,I2C, Timers10/12/16-bit ADC DAC, OP Amp, LCD driverEmbedded emulation+ new 5xx High Performance!

Don’t Forget …

Don’t Forget

Don’t Forget!

Thank you for attendingHave a safe trip home

Take your workshop handouts home with you

Fill out the evaluation form on line if possible (use paper forms otherwise)

This material is available on-line:http://wiki.davincidsp.com/index.php?title=MSP430_One_Day_Workshop

MSP430 One Day Workshop – Wrap-up 6 - 3

Page 158: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Wrap-up

6 - 4 MSP430 One Day Workshop – Wrap-up

Page 159: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Addendum

Introduction Here are the answers to all those pesky questions in the workshop, along with the lab solutions.

Objectives • Module review answers

• Lab Question Answers

• Lab Solutions

MSP430 One Day Workshop - Addendum 7 - 1

Page 160: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

*** I was somewhat ambivalent about leaving this page blank. ***

7 - 2 MSP430 One Day Workshop - Addendum

Page 161: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

Lab Solutions and Review Answers Addendum.................................................................................................................................................. 7-1

Lab Solutions and Review Answers......................................................................................................... 7-3 Introduction Module Review Answers ............................................................................................... 7-5 Lab1 IAR Code................................................................................................................................... 7-5 Lab1 CCS Code.................................................................................................................................. 7-6 Flash Programming Exercise.............................................................................................................. 7-6 Lab2 IAR Solution.............................................................................................................................. 7-7 Lab3 Step 11 Answers........................................................................................................................ 7-8 Ultra-Low Power Module Review Answers....................................................................................... 7-9 Lab4 IAR Solution.............................................................................................................................7-10 Analog Peripherals Module Review Answers ...................................................................................7-11 Lab5 IAR Solution.............................................................................................................................7-12 Lab5 Step 9 Answers.........................................................................................................................7-13 Timer Module Review Answers........................................................................................................7-14 Communications Module Review Answers ......................................................................................7-15 Optional Lab6 - USCI/SPI Communications IAR Solution ..............................................................7-16

MSP430 One Day Workshop - Addendum 7 - 3

Page 162: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

*** This page reluctantly left blank ***

7 - 4 MSP430 One Day Workshop - Addendum

Page 163: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

Introduction Module Review Answers

ReviewHow many general purpose registers does the MSP430 have?

What is the purpose of the constant generator?

Where is the best resource for MSP430 information?

At reset, all I/O pins are set to …

Why should you use standard definitions?

12

Reduce code size and cycles by automatically generating commonly used constants

www.ti.com/msp430

Inputs

Resulting code is easier to read and debug

Ultra-low Power

Lab1 IAR Code

#include "msp430x20x3.h"

ORG 0F800h ; Program start

RESET mov.w #280h,SP ; Stack mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog bis.b #01h,&P1DIR

Mainloop xor.b #01h,&P1OUT

Delay dec.w R15 jnz Delay jmp Mainloop

ORG 0FFFEh ; RESET vector

MSP430 One Day Workshop - Addendum 7 - 5

Page 164: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

Lab1 CCS Code .cdecls C,LIST,"msp430x21x1.h" ; Include device header file

.text ; Progam Start RESET mov.w #280h,SP ; Stack mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog bis.b #01h,&P1DIR

Mainloop xor.b #01h,&P1OUT

Delay dec.w R15 jnz Delay jmp Mainloop

.sect ".reset" ; MSP430 RESET Vector

.short RESET

.end

DW RESET END

Flash Programming Exercise fFTG = 476 kHz

tWord = 30

Time to program a word or byte = 30/476000 = 63uS

Time to randomly program 1024 words = 1024 * 63uS = 64.5mS

7 - 6 MSP430 One Day Workshop - Addendum

Page 165: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

Lab2 IAR Solution

#include <msp430xG46x.h>

void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

FLL_CTL0 |= XCAP14PF; // Configure load caps

P2DIR = BIT1; // Set P2.1 to output direction

P1IES = BIT0; // H-L transition

P1IE = BIT0; // Enable interrupt

_EINT(); // Enable interrupts

while (1);

}

// P1 interrupt service routine

#pragma vector=PORT1_VECTOR

__interrupt void P1ISR (void)

{

unsigned volatile int i;

for (i=10000; i>0; i--); // Debounce delay

P1IFG &= ~BIT0; // Clear P1IFG

if ((P1IN & 0x01) == 0)

P2OUT ^= 0x02; // Toggle P2.1 using exclusive-OR

}

MSP430 One Day Workshop - Addendum 7 - 7

Page 166: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

Lab3 Step 11 Answers

Why were the I/Os configured as they were?

Unused I/O must be configured as outputs, otherwise, floating gate current will occur. The outputs were then set to values so as not to contend with other on-board circuitry.

Why was LPM3 used?

No clocks are needed. LPM3 leaves on the 32768Hz running and shuts down all other clocks.

Look in the header file to see how LPM3_bits is defined

SCG1+SCG0+CPUOFF

What further low-power improvements could be made?

LPM4 could be used. A timer could be employed for the pushbutton debounce.

7 - 8 MSP430 One Day Workshop - Addendum

Page 167: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

Ultra-Low Power Module Review Answers

Review

LPM3

To avoid floating gate currents

32,768 Hz

Interrupts

To minimize power consumption, you should maximize your time in what LPM mode?

Why are unused pins set as outputs?

You should control program flow with …

Most MSP430 designs utilize a ________ crystal.

Analog Peripherals

MSP430 One Day Workshop - Addendum 7 - 9

Page 168: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

Lab4 IAR Solution #include "msp430xG46x.h" volatile unsigned int i; volatile unsigned int ADCresult; volatile unsigned long int DegC, DegF; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer ADC12CTL0 = ADC12ON + REFON + REF2_5V + SHT0_7; // Turn ADC on, ref on. Ref = 2.5V,

// Set sampling time ADC12CTL1 = SHP; // Use sampling timer ADC12MCTL0 = INCH_10 + SREF_1; // Select channel A10, Vref+ ADC12IE = 0x01; // Enable ADC12IFG.0 for (i = 0; i < 0x3600; i++); // Delay for reference start-up ADC12CTL0 |= ENC; // Enable conversions __enable_interrupt(); // Enable interrupts while(1) { ADC12CTL0 |= ADC12SC; // Start conversion __bis_SR_register(LPM0_bits); // Enter LPM0 // DegC = (Vsensor - 986mV)/3.55mV // Vsensor = (Vref)(ADCresult)/4095) // DegC -> ((ADCresult - 1615)*704)/4095 DegC = ((((long)ADCresult-1615)*704)/4095); DegF = ((DegC * 9/5)+32); // Calculate DegF __no_operation(); // SET BREAKPOINT HERE } } #pragma vector=ADC12_VECTOR __interrupt void ADC12ISR(void) { ADCresult = ADC12MEM0; // Move results, IFG is cleared __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0 }

7 - 10 MSP430 One Day Workshop - Addendum

Page 169: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

Analog Peripherals Module Review Answers

ReviewWhat is your lowest power option for triggering an ADC?

Name the four ADC conversion modes:

What is the purpose of the DTC?

ADC10 and ADC12 can sample at what speed?

Trigger conversion with a timer.

Single, SequenceRepeat-single,Repeat-sequence

The Direct Transfer Controller moves the conversion result of the ADC10 into any MSP430 memory

200ksps

Timer Section …

MSP430 One Day Workshop - Addendum 7 - 11

Page 170: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

Lab5 IAR Solution

#include <msp430xG46x.h>

void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

FLL_CTL0 |= XCAP14PF; // Configure load caps

P2DIR |= BIT1; // Set P2.1 to output direction

TACTL = TASSEL_1 + TACLR; // Clock = ACLK (32768), clear

TACCTL0 = CCIE; // CCR0 interrupt enabled

TACCR0 = 32768-1; // #counts for 1s

TACTL |= MC_1; // Setting mode bits starts timer

_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupt

}

// Timer A0 interrupt service routine

#pragma vector=TIMERA0_VECTOR

__interrupt void Timer_A (void)

{

P2OUT ^= 0x02; // Toggle P2.1 using exclusive-OR

}

7 - 12 MSP430 One Day Workshop - Addendum

Page 171: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

Lab5 Step 9 Answers

Why was TAIE not set in TACTL?

Actually, we didn’t use the interrupt generated when you enable TAIE. Timer_A has several interrupts. TAIE enables an interrupt to occur on overflow. We could have used it, but instead we used the TACCR0 interrupt, which fires when TAR hits the CCR0 value.

Why were the MCx bits not set initially when TACTL was configured?

Setting the MCx bits starts the timer running, so you want all setup to be completed beforehand.

MSP430 One Day Workshop - Addendum 7 - 13

Page 172: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

Timer Module Review Answers

ReviewName the counting modes.

What is the TAIV register's purpose?

In addition to normal timer functions, name some other functions the timer can perform.

Communication section …

Up, Up/Down and Continuous

To combine three interrupts into a single interrupt to the CPU. Also acts as an indicator for handler code to determine which interrupt triggered.

ADC12 hardware control, PWM, UART

7 - 14 MSP430 One Day Workshop - Addendum

Page 173: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

Communications Module Review Answers

Review

Wrap Up …

the USCI module

low-power, low-cycle count

the MSP430 website

the MSP430 website

The new, standard MSP430 serial communication module is:

Implementing SPI on the USI or USCI provides a ___________ and __________ solution.

The best place to look for code examples is:

The best place to find technical documentation is:

MSP430 One Day Workshop - Addendum 7 - 15

Page 174: TIsoftware-dl.ti.com/trainingTTO/trainingTTO_public_sw...MSP430 4xx One Day Workshop 2010 MSP430 One Day Workshop - Introduction 1 - 7 LCD Controllers LCD Controllers Ultra-low power

Lab Solutions and Review Answers

Optional Lab6 - USCI/SPI Communications IAR Solution

P3SEL |= 0x06; // Assign I2C pins to USCI_B0

UCB0CTL1 |= UCSWRST; // Enable SW reset (why?)

UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode

UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep UCSWRST set

UCB0BR0 = 11; // fSCL = SMCLK/11 = 95.3kHz

UCB0BR1 = 0;

UCB0I2CSA = 0x48; // Set slave address

UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation

UCB0I2CIE |= UCNACKIE; // Interrupt on slave Nack

IE2 |= UCB0RXIE; // Enable RX interrupt

7 - 16 MSP430 One Day Workshop - Addendum