1.17k likes | 1.42k Views
Getting Started with the MSP430 LaunchPad. Agenda. Introduction to Value Line Code Composer Studio CPUX and Basic Clock Module Interrupt and GPIO TimerA and WDT+ Low-Power Optimization ADC10 and Comparator_A+ Serial Communications Grace Capacitive Touch Solution.
E N D
Agenda • Introduction to Value Line • Code Composer Studio • CPUX and Basic Clock Module • Interrupt and GPIO • TimerA and WDT+ • Low-Power Optimization • ADC10 and Comparator_A+ • Serial Communications • Grace • Capacitive Touch Solution
World’s Lowest Power MCU • Ultra-Low Power Active Mode • 7 Low Power Modes • Instant Wakeup • All MSP430 devices are Ultra-Low Power • Intelligent Analog & Digital Peripherals • Peripherals operate in low power modes • Minimize physical footprint and Bill of Materials • Featuring FRAM, USB, RF, Capacitive Touch I/O, Metrology Engines, LCD, ADC, DAC & MORE • Find the right MCU for you • 400+ devices • Up 256kB Flash, 18kB RAM, 25+ package options • Devices starting at $0.25 with Value Line • Various levels of performance & integration • Low cost and simple point of entry • Complete kits starting @ $4.30 • GUI-based coding & debugging tools available • MSP430Ware Software and Resource Package • -Incl. code examples, datasheets, user guides & more! MSP430 MCUsAn Introduction Ultra-Low Power Integration Easy to Get Started Extensive Portfolio, Low Cost Options
MSP430-Enabled Applications Utility Metering Portable Medical Electricity Meters Gas Meters Flow Meters Smart Meters Blood Glucose Meters Thermometers Heart-Rate Monitors Implantable Devices Thousands of applications are enabled by MSP430 MCUs Differentiation is possible with MSP430 MCU’s Ultra-Low Power performance, high analog & digital peripheral integration, and easy-to-use tool chain. Wireless Applications Sensors & Security Remote Sensors Communication Controllers RFID Smoke Detector Motion Detector Vibration Detector Smart Sensors Energy Harvesting Consumer Electronics Personal Health & Fitness Renewable Energy Battery-less devices Solar, thermal, vibration, etc Portable Electronics Remote Controls Personal Care PC peripherals Sports Watches Pedometers Calorimeters Dive watches
Value Line: 16-bit performance, 8-bit price ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC UART UART UART UART UART UART UART Cap Touch I/O MSP430G25X3 16KB ADC10 MSP430G24X3 SC SC SC SC SC SC SC SC SC SC SC SC 8KB Comparator MSP430G24X2 SPI/I2C MSP430G23X3 4KB MSP430G23X2 MSP430G22X2 Flash Size 2KB MSP430G22X3 MSP430G22X1* MSP430G21X2 1KB MSP430G21X1* MSP430G21X3 .5 KB MSP430G2001* 32-pin QFN 24 GPIO 16-pin QFN 10 GPIO 28-pin TSSOP 24 GPIO 20-pin TSSOP/PDIP 16 GPIO 14-pin TSSOP/PDIP 10 GPIO * 8-pin SOIC in development
Value Line Peripherals • General Purpose I/O • Independently programmable • Any combination of input, output, and interrupt (edge selectable) is possible • Read/write access to port-control registers is supported by all instructions • Each I/O has an individually programmable pull-up/pull-down resistor • Some parts/pins are touch-sense enabled (PinOsc) • 16-bit Timer_A3 • 3 capture/compare registers • Extensive interrupt capabilities • WDT+ Watchdog Timer • Also available as an interval timer • Brownout Reset • Provides correct reset signal during power up and down • Power consumption included in baseline current draw
Value Line Peripherals • Serial Communication • USI with I2C and SPI support • USCI with I2C, SPI and UART support • Comparator_A+ • Inverting and non-inverting inputs • Selectable RC output filter • Output to Timer_A2 capture input • Interrupt capability • 8 Channel/10-bit 200 ksps SAR ADC • 8 external channels (device dependent) • Voltage and Internal temperature sensors • Programmable reference • Direct transfer controller send results to conversion memory without CPU intervention • Interrupt capable • Some parts have a slope converter
LaunchPad Development Board USB EmulatorConnection Embedded Emulation 6-pin eZ430 Connector Crystal Pads Chip Pinouts Part and Socket Power Connector P1.3 Button LEDs and Jumpers P1.0 & P1.6 Reset Button
Agenda • Introduction to Value Line • Code Composer Studio • CPUX and Basic Clock Module • Interrupt and GPIO • TimerA and WDT+ • Low-Power Optimization • ADC10 and Comparator_A+ • Serial Communications • Grace • Capacitive Touch Solution
What is Code Composer Studio? • Integrated development environment for TI embedded processors • Includes debugger, compiler, editor, simulator, OS… • The IDE is built on the Eclipse open source software framework • Extended by TI to support device capabilities • CCSv5 is based on “off the shelf” Eclipse (version 3.7 in CCS 5.1) • Future CCS versions will use unmodified versions of Eclipse • TI contributes changes directly to the open source community • Drop in Eclipse plug-ins from other vendors or take TI tools and drop them into an existing Eclipse environment • Users can take advantage of all the latest improvements in Eclipse • Integrate additional tools • OS application development tools (Linux, Android…) • Code analysis, source control… • Linux support soon • Low cost! $445 or $495
Common Tasks • Creating New Projects • Very simple to create a new project for a device using a template • Build options • Many users have difficulty using the build options dialog and find it overwhelming • Updates to options are delivered via compiler releases and not dependent on CCS updates • Sharing projects • Easy for users to share projects, including working with version control (portable projects) • Setting up linked resources has been simplified
Workspaces and Projects Workspace Project 1 Project 2 Project 3 Settings and preferences Project Source files Header files Library files Build and tool settings Source files Code and Data Project Source files Header Files Library files Build and tool settings Project Source files Header Files Library files Build and tool settings Link Link Link Link Header files Declarations/Defines Library files Code and Data A workspace contains your settings and preferences, as well as links to your projects. Deleting projects from the workspace deletes the links, not the files A project contains your build and tool settings, as well as links to your input files. Deleting files from the workspace deletes the links, not the files
Project Wizard • Single page wizard for majority of users • Next button will show up if a template requires additional settings • Debugger setup included • If a specific device is selected, then user can also choose their connection, ccxml file will be created • Simple by default • Compiler version, endianness… are under advanced settings
Various IDE options Free Integrated Development Environments (IDE) available • Code Composer Studio • Eclipse-based IDE (Compiler, debugger, linker, etc) for all TI embedded processors • Unrestricted version available for $495 • Free versions are available! • Free 16kB code-limited version available for download • Free, full-featured, 120-day trial version available • IAR Embedded Workbench • Strong third-party IDE offering with project management tools and editor. Includes config files for all MSP430 devices. • Free versions are available! • Free 4/8/16kB code-limited Kickstart version available for download • Free, full-featured, 30-day trial version available • MSPGCC • Free, Open source, GCC tool chain for MSP430 • includes the GNU C compiler (GCC), the assembler and linker (binutils), the debugger (GDB) • Tools can be used on Windows, Linux, BSD and most other flavors of Unix. • Learn more @ http://mspgcc.sourceforge.net/ Other MSP430 IDE options are available! Learn more @ www.ti.com/msp430tools
Lab1: Code Composer Studio • Lab1: • Create a new workspace • Create Lab1 Project • Add in temperature sense demo • Compile it and run
Step 1: Create CCS workspace Put the Lab files onto your desktop Launch CCS v5 Core Edition Select a “Workspace” location 18
Step 2: Create a CCS Project File > New > CCS Project Project Name: Lab1 Device>Family: MSP430 Variant: MSP430G2452 Project templates and examples : Empty Project 19
Step 3: Add a File to the CCS Project Project > Add Files Navigate to Lab source folder And select : Temperature_Sense_Demo.c 20
CCS Window – C/C++ Perspective Overview Independent Debug and C/C++ Project Perspectives 1-click project Debug • Project Outline • Shortcut to project parts • Project View • List of all Projects • Problems View • Information, Warnings, Errors • Console • Build Information • Code Window • Real-time breakpoints, Syntax highlighting 21
CCS Window – Debug Perspective Overview Independent Debug and C/C++ Project Perspectives 1-click project Debug • Highly configurablewindow layout • User preferences • Plugin support • Target control • Start • Stop • Halt • Stepping • Stack Trace • Real-time, in-system MSP430 information • Register access • Flash, RAM, Info segment access • Disassembly view Program Size Info • Code Window • Real-time breakpoints, Syntax highlighting 22
Step 4: Build & Debug a CCS Project Click the “BUG” to build the code & launch the debugger 23
Step 5: Run, Terminate a CCS Project “RUN” Perspectives “TERMINATE” 24
Agenda • Introduction to Value Line • Code Composer Studio • CPUX and Basic Clock Module • Interrupt and GPIO • TimerA and WDT+ • Low-Power Optimization • ADC10 and Comparator_A+ • Serial Communications • Grace • Capacitive Touch Solution
MSP430G2xx Structure Ultra-low Power • 0.1uA power down • 0.8uA standby mode • 220uA / 1MIPS • <1us clock start-up • <50nA port leakage • Zero-power brown-out reset (BOR) Ultra-Flexible • 0.5k-16kB In-System Programmable (ISP) Flash • 16-bit Timer • SPI, I2C • 10bit ADC • Embedded emulation Clock FLASH RAM . . . MAB 16 RISC CPU 16-bit JTAG/Debug MDB 16 . . . ACLK Digital Analog Peripheral Peripheral SMCLK 6
Deep single-cycle register file 4 special purpose 12 general purpose No accumulator bottleneck RISC architecture 27 core instructions 24 emulated instructions 7 address modes Atomic memory-to-memory addressing Bit, byte and word processing Constant generator 16-bit RISC CPU 7
Memory Map G2452 shown • Flash programmable via JTAG or In-System (ISP) • ISP down to 2.2V. Single-byte or Word • Main memory: 512 byte segments (0-n). Erasable individually or all • Information memory: 64 byte segments (A-D) • Section A contains device-specific calibration data and is lockable • Programmable Flash Memory Timing Generator 0FFFFh0FFE0h FFDFh0E00h 010FFh01000h 02FFh0200h 01FFh0100h 0FFh010h 0Fh0h
Clock System On PUC, MCLK and SMCLK are sourced from DCOCLK at ~1.1 MHz. ACLK is sourced from LFXT1CLK in LF mode with an internal load capacitance of 6pF. • Very Low Power/Low Frequency Oscillator (VLO) • 4 – 20kHz (typical 12kHz) • 500nA standby • 0.5%/°C and 4%/Volt drift • Crystal oscillator (LFXT1) • Programmable capacitors • Failsafe OSC_Fault • Minimum pulse filter • Digitally Controlled Oscillator (DCO) • 0-to-16MHz • + 3% tolerance • Factory calibration in Flash
G2xxx - No Crystal Required DCO // Setting the DCO to 1MHzif (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF) while(1); // Erased calibration data? Trap! BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation • G2xx1 devices have 1MHz DCO constants only. Higher frequencies must be manually calibrated • G2xx2 & G2xx3 have all 4 constants + calibration values for the ADC & temperature sensor
Run Time Calibration of the VLO Calibrate the VLO during runtime Clock Timer_A runs on calibrated 1MHz DCO Capture with rising edge of ACLK/8 from VLO fVLO = 8MHz/Counts Code library on the web (SLAA340)
System MCLK & Vcc • Match needed clock speed with required Vcc to achieve the lowest power • External LDO regulator required • Unreliable execution results if Vcc < the minimum required for the selected frequency • All G2xxx device operate up to 16MHz
Lab2: Basic Clock Configure • Lab2 • Import Lab2 project to Workspace • Setup DCO = 1MHz • Use DCO/8 as MCLK, LED Blink • Use VLO/8 as MCLK, LED Blink
Lab 2: // Configure Basic Clock BCSCTL1 = __________; // Set range DCOCTL = ___________;// Set DCO step + modulation BCSCTL3 |= LFXT1S_2;// Set LFXT1 • Reference User’s Guide, Datasheet & Schematic // Configure MCLK BCSCTL2 |= ________ + DIVM_3; // Set MCLK
Agenda • Introduction to Value Line • Code Composer Studio • CPUX and Basic Clock Module • Interrupt and GPIO • TimerA and WDT+ • Low-Power Optimization • ADC10 and Comparator_A+ • Serial Communications • Grace • Capacitive Touch Solution
Interrupts and the Stack Entering Interrupts Any currently executing instruction is completed The PC, which points to the next instruction, is pushed onto the stack The SR is pushed onto the stack The interrupt with the highest priority is selected The interrupt request flag resets automatically on single-source flags; Multiple source flags remain set for servicing by software The SR is cleared; This terminates any low-power mode; Because the GIE bit is cleared, further interrupts are disabled The content of the interrupt vector is loaded into the PC; the program continues with the interrupt service routine at that address
ISR Coding #pragma vector=WDT_VECTOR __interrupt void WDT_ISR(void) { IE1 &= ~WDTIE; // disable interrupt IFG1 &= ~WDTIFG; // clear interrupt flag WDTCTL = WDTPW + WDTHOLD; // put WDT back in hold state BUTTON_IE |= BUTTON; // Debouncing complete } #pragma vector - the following function is an ISR for the listed vector _interrupt void - identifies ISR name No special return required
Controlling GPIO Ports Input Register PxIN Output Register PxOUT Direction Register PxDIR Function Select PxREN Function Select PxSEL Function Select PxSEL2 Interrupt Edge PxIES For GPIO Int Interrupt Enable PxIE Interrupt Flags PxIFG GPIO Register GPIO Code Example P1DIR |= BIT4; P1SEL |= BIT4; P1DIR |= BIT0; P1OUT |= BIT0; 26
Pin Muxing Each pin has multiple functions Register bits select pin function See device specific datasheet
Lab3: GPIO • Lab3 • Setup P1.3 to Button • Setup P1.0 to LED control • LED toggle with Button
Lab 3: P1DIR |= BIT0; // Set P1.0 to output direction P1IES |= BIT3; // P1.3 Hi/lo edge _____ &= ~BIT3; // P1.3 IFG cleared _____ |= BIT3; // P1.3 interrupt // Port1 interrupt service routine #pragma vector = __________ __interrupt void Port_1(void) // Port1 interrupt service routine P1OUT ^= BIT0; // P1.0 = toggle ______ &= ~BIT3; // P1.3 IFG cleared
Agenda • Introduction to Value Line • Code Composer Studio • CPUX and Basic Clock Module • Interrupt and GPIO • TimerA and WDT+ • Low-Power Optimization • ADC10 and Comparator_A+ • Serial Communications • Grace • Capacitive Touch Solution
Timer_A • Asynchronous16-Bit timer/counter • Continuous,up-down,up count modes • Multiple capture/compare registers • PWM outputs • Interrupt vectorregister for fastdecoding • Can trigger DMA transfer • On all MSP430s 70
Timer_A Counting Modes Stop/Halt Timer is halted Continuous Timer continuously counts up 0FFFFh 0h Up Timer counts between 0 and CCR0 Up/Down Timer counts between 0 and CCR0 and 0 0FFFFh CCR0 0h CCR – Count Compare Register 71
Timer_A Interrupts TACCR0 CCIFG The Timer_A Capture/Comparison Register 0 Interrupt Flag (TACCR0) generates a single interrupt vector: TIMERA0_VECTOR No handler required TACCR1, 2 and TA interrupt flags are prioritized and combined using the Timer_A Interrupt Vector Register (TAIV) into anotherinterrupt vector TACCR1 CCIFG TACCR2 CCIFG TAIV TIMERA1_VECTOR TAIFG Your code must contain a handler to determine which Timer_A1 interrupt triggered 72
TAIV Handler Example 0 x x x 0 0 0 x 0 0 0 0 0 0 0 0 Source TAIV Contents No interrupt pending 0 TACCR1 CCIFG 02h TACCR2 CCIFG 04h Reserved 06h Reserved 08h TAIFG 0Ah Reserved 0Ch Reserved 0Eh TAIV 15 0 #pragma vector = TIMERA1_VECTOR __interrupt void TIMERA1_ISR(void) { switch(__even_in_range(TAIV,10)) { case 2 : // TACCR1 CCIFG P1OUT ^= 0x04; break; case 4 : // TACCR2 CCIFG P1OUT ^= 0x02; break; case 10 : // TAIFG P1OUT ^= 0x01; break; } } 0xF814 add.w &TAIV,PC 0xF818 reti 0xF81A jmp 0xF824 0xF81C jmp 0xF82A 0xF81E reti 0xF820 reti 0xF822 jmp 0xF830 0xF824 xor.b #0x4,&P1OUT 0xF828 reti 0xF82A xor.b #0x2,&P1OUT 0xF82E reti 0xF830 xor.b #0x1,&P1OUT 0xF834 reti Assembly code IAR C code 73
Timer_A PWM Example CCR2 CCR2 CCR2 MSP430F11x1 TEST TA2/P1.7 P1.6 Vcc P1.5 P2.5 P1.4 Vss P1.3 XOUT TA1/P1.2 XIN P1.1 CCR1 CCR1 CCR1 RST P1.0 P2.0 P2.4 P2.1 P2.3 CCR0 CCR0 CCR0 P2.2 • Completely automatic • Independent frequencies with different duty cycles can be generated for each CCR • Code examples on the MSP430 website 74