Blinking an LED Using MSP430ware to Control GPIO

Slides:



Advertisements
Similar presentations
Chapter 6 General Purpose Input/Output
Advertisements

ECE 382 Lesson 14 Lesson Outline Polling Multiplexing Intro to Logic Analyzer Debouncing Software Delay Routines Admin Assignment 3b due BOC today Assignment.
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
Renesas Electronics America Inc. © 2011 Renesas Electronics America Inc. All rights reserved. RX210 Multi-Function Pin Controller (MPC) Ver
Raul Cabrera Khaldon Batnij Isaac Zavala
ECE Lecture 1 1 L15 – Digital I/O Department of Electrical and Computer Engineering The Ohio State University ECE 2560.
Chapter 6 – MSP430 Micro-Architecture. BYU CS/ECEn 124Chapter 6 - MSP430 Micro-Architecture2 Concepts to Learn… Computer Architecture MSP430 Micro-Architecture.
Chapter 6 – MSP430 Micro-Architecture
MSP432™ MCUs Training Part 8: Software
MSP432™ MCUs Training Part 9: Porting between MSP430 and MSP432
LAB 7: WDT+ and Low-Power Optimization
Part 1 Using the ARM board And start working with C Tutorial 5 and 6
Silicon Labs ToolStick Development Platform
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
A Simple Tour of the MSP430. Light LEDs in C LEDs can be connected in two standard ways. Active high circuit, the LED illuminates if the pin is driven.
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
1 Lab 1: Introduction. 2 Configure ATMEL AVR Starter Kit 500 (STK500), a prototyping/development board for Lab1. ATmega16 ( V) is the chip used.
Lecture 11: TI MSP430 Timers Compare Modes
ECS642U Embedded Systems Digital I/O William Marsh.
1 LHO 13 The 8051CF020 and the University Daughter Card.
Lecturers: Professor John Devlin Mr Robert Ross
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
IO Subsystem IV Ports and peripherals. IO Subsystem (1) All devices connected to the system buses, other than memory and CPU – Input and output ports.
ECE Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560.
1-3 GPIO_Output(LuminaryLibrary) 1.Alter the output current to 4mA 2.Let LED0 turn on but LED 1 turn off. Modify your program in E:\yourname\arm.
Chapter 2 MSP432 ARM I/O Programming 1. Chapter Review Section 2.1: MSP432 Microcontroller and LaunchPad Section 2.2: GPIO (General Purpose I/O) Programming.
ECE 382 Lesson 32 Lesson Outline Lab 6 Introduction Pulse Width Modulation Capture / Compare Example Lab 6 Tips Admin Lab#6 “prelab” due BOC lesson 33.
NFC Sensor System ECE Winter 2015
ECE 3430 – Intro to Microcomputer Systems
CS4101 嵌入式系統概論 General Purpose IO
Microcontrollers, Basics Tips and Tricks with PIC MCUs
Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values.
Microcontroller basics
Lesson Outline Interrupts Admin Assignment #9 due next lesson
Code review: GPIO, timer, and ISR
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
Mon. Oct 2 Announcements Quiz Postponed to Wednesday – still only on 2.a + 2.b Video lecture for 2.a posted Lab 6 experiment extension You must come to.
CS4101 Introduction to Embedded Systems Lab 1: MSP430 LaunchPad IDE
ECE 3430 – Intro to Microcomputer Systems
Microprocessors Tutorial 1: Arduino Basics
Chapter 6 General Purpose Input/Output
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
Lesson Outline Peripherals Memory-Mapped IO Ports GPIO Multiplexing
GPIO General Purpose Input/output Tiva C TM4C123GH6PM
Refer to Chapter 10 in the reference book
RX Watchdog Timer (WDT)
CS4101 嵌入式系統概論 General Purpose IO
COMP2121: Microprocessors and Interfacing
My First Nios II for Altera DE2-115 Board
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
Roller Coaster Design Project
Internet-of-Things (IoT)
Introducing the PIC Mid-Range Family and the 16F84A
ECE 3567 Microcontroller Lab
Lecture 9: TI MSP430 Interrupts & Low Power Modes
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
8051 Development System Details
Introduction to Arduinos
ECE 3567 Microcontrollers Lab
ECE 3567 Microcontrollers Lab
ECE 3567 Microcontroller Lab
A modular robot for use in the RoboSumo lab
Presentation transcript:

Blinking an LED Using MSP430ware to Control GPIO Chapter 3 MSP430 Design Workshop

Objectives List 3 components of MSP430ware Describe (and name) the GPIO control registers Implement the steps needed to use MSP430ware DriverLib in a CCS project Show how to disable the watchdog timer Lab – Use MSP430ware to blink and LED and read a button on the MSP430 Launchpad

MSP430ware Libraries Examples Software Tools DriverLib* Graphics USB Stack CapTouch MathLib IEC60730 Examples All device generations Development boards Software Tools Grace ULP Optimization Advisor * Other tools/libraries covered in later workshop chapters DriverLib...

Driver Library vs Traditional C Coding (PWM example) Driver Library offers easy-to-understand functions No more cryptic registers to configure Functional coding of peripherals rather than bitwise programming High-level API makes it easy to port code between most MSP430 devices Minimal overhead

MSP430ware DriverLib Modules Software modules tend to match 1-to-1 with hardware peripherals Some of the module names above have been abbreviated Not all devices have all hardware (and thus, software) modules DriverLib is not currently available for MSP430 ValueLine devices Looking at GPIO...

MSP430 GPIO Ports I/O Port 1 GPIO = General Purpose Bit Input/Output 8-bit I/O ports 1 to 12 ports, depending on family and pin-count Each pin is individually controllable Input pins can generate interrupts (Chapter 5) Controlled by memory- mapped registers: IN OUT DIR REN SEL … P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0 I/O Port 1 Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 In or Out?

PxDIR (Pin Direction): Input or Output P1OUT.7 P1DIR.7 “1” 7 6 5 4 3 2 1 P1IN P1OUT P1DIR PxDIR.y: 0 = input  Register example: 1 = output P1DIR |= 0x81; MSP430ware example: #include <driverlib.h> GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 + GPIO_PIN7 ); Set output value...

GPIO Output “1” P1IN.7 P1OUT.7 P1DIR.7 “1” P1IN “1” P1OUT 6 5 4 3 2 1 P1IN x P1OUT P1DIR PxOUT.y: 0 = low  Register example: 1 = high P1OUT |= 0x80; MSP430ware example: GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN7 ); Input…

GPIO Input (Resistors) P1IN.7 P1OUT.7 P1DIR.7 P1REN.7 up/down Enable resistor Input pins are held in high-impedance (Hi-Z) state, so they can react to 0 or 1 When not driven, Hi-Z inputs may float up/down … prevent this with pullup/pulldown resistors PxREN enables resistors PxOUT selects pull-up (1) or -down (0) Lower cost devices may not provide up/down resistors for all ports 7 6 5 4 3 2 1 P1IN x P1OUT P1DIR P1REN unsigned short usiButton = 0; GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P1, GPIO_PIN7 ); usiButton = GPIO_getInputPinValue( GPIO_PORT_P1, GPIO_PIN7 );

Controlling GPIO Ports Most pins on MCU’s are multiplexed to provide you with greater flexibility – which peripherals do you want to use in your system

Pin Flexibility P1IN P1OUT 7 6 5 4 3 2 1 P1IN P1OUT P1DIR P1REN P1DS P1SEL Most pins on MCU’s are multiplexed to provide you with greater flexibility Often, two (or more) digital peripherals are connected to the pin – in this case, some families use PxDIR to select between them, while others have multiple PxSEL registers P1SEL.1 “PxSEL = 0” IN / OUT Peripheral (e.g. Timer) “PxSEL = 1” GPIO_setAsPeripheralModuleFunctionOutputPin( port, pin ); GPIO_setAsPeripheralModuleFunctionInputPin( port, pin );

GPIO Summary: F5529 vs FR5969 vs G2553 PA PB PC PD PJ* (4-bit ) Reset Value (PUC) P1† P2 P3 P4 P5 P6 P7 P8 PxIN  All Four Devices support Ports 1 and 2 F5529 FR4133 FR5969 (only) F5529 (P8 x3-bits) FR4133 (P8 x12-bits) F55 & FR59 undef  PxOUT unchg PxDIR 0x00 PxREN PxDS  PxSEL PxIV   FR5969 (only) PxIES PxIE  PxIFG  F5529/FR4133 only (80-pin)  FR5969 only (48-pin) * PJ: 4-bits shared with JTAG pins  G2553 only (20-pin) † P1: 4-bits shared with JTAG pins (‘G2553) Each numbered port has 8 bits, unless noted otherwise At reset, all I/O pins are set to … input You should initialize all pins (to prevent floating inputs) Analog functions can ‘preempt’ pin function selection

Include Files Like most C programs, we need to include the required header files Each MSP430 device has its own .h file to define various symbols and registers – include this using msp430.h DriverLib defines all peripherals available for each given device – include hw_memmap.h (from /inc folder) But to make DriverLib easy, TI created a single header file to link in: driverlib.h #include <driverlib.h> GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN7); Disable the dog...

Disable WatchDog Timer MSP430 watchdog timer is always enabled at reset Watchdog timer requires modification password (0x5A) Easiest solution: Begin your program with DriverLib (WDT_A) function #include <driverlib.h> WDT_A_hold(WDT_A_BASE); //Stop watchdog timer

Pin UnLocking (Default for FRAM devices) PM5CTL0.LOCKLPM5 bit disconnects registers from pins – allows pin values to remain constant during low power modes (LPM3.5/4.5) Bit automatically set upon entering LPMx.5 mode (see Low Power Chapter) FRxx FRAM devices always power-on with this mode set – you must clear it for pins to respond to your register settings Hint: Unlock pins before clearing and enabling GPIO port interrupts 1 1 1 1 GPIO Control Registers (IN, OUT, etc) LOCKLPM5 pin locking GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN7 ); GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN7 ); PMM_unlockLPM5(); // unlock pins after setting all gpio registers

Lab 3 – Blink with MSP430ware Lab Worksheet… a Quiz, of sorts on: GPIO DriverLib Path Variables Lab 3a – Embedded ‘Hello World’ Create a MSP430ware DriverLib GPIO project Use IDE path variables to make your project portable Write code to enable LED Use simple (inefficient) delay function to create blinking LED Use CCS debugging windows to view registers and memory Lab 3b – Read Launchpad Push Button Test the state of the push button Only blink LED when button is pushed (again, inefficient, but we’ll fix that in Chapter 5)

Launchpad Pins for LEDs/Switches FR4133 FR5969 LED Color LED1 P1.0 P4.6 Red LED (with Jumper) LED2 P4.7 P4.0 Green LED Button 1 P2.1 P1.2 P4.5 Button 2 P1.1 P2.6

Lab3a – Worksheet ________________________________________________ 1. Where is your MSP430ware folder located? ________________________________________________ 2. To use the MSP430ware GPIO and Watchdog API, which header file needs to be included in your source file? #include < ________________________ > 3. Which DriverLib function stops the Watchdog timer? ________________________________________________ ; 4a. Which I/O pin on Port 1 is connected to an LED (on your Launchpad)? 4b. What two GPIO DriverLib functions are required to initialize this GPIO pin (from previous question) as an output and set its value to “1”? 4c. For the FRAM devices, what additional function is needed to make it work (i.e. to connect the I/O to the pin)?

Lab3a – Worksheet ________________________________________________ 1. Where is your MSP430ware folder located? ________________________________________________ 2. To use the MSP430ware GPIO and Watchdog API, which header file needs to be included in your source file? #include < ________________________ > 3. What DriverLib function stops the Watchdog timer? ________________________________________________ ; 4a. Which I/O pin on Port 1 is connected to an LED (on your Launchpad)? 4b. What two GPIO DriverLib functions are required to initialize this GPIO pin (from previous question) as an output and set its value to “1”? 4c. For the FRAM devices, what additional function is needed to make it work (i.e. to connect the I/O to the pin)? Most likely: C:\ti\msp430\MSP430ware_1_97_00_47\ driverlib.h WDT_A_hold( WDT_A_BASE ) F5529/FR5969/FR4133: P1.0 GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ) GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 ) PMM_unlockLPM5();

Lab3a – Worksheet Using the _delay_cycles() intrinsic function (from the last chapter), write the code to blink an LED with a 1 second delay setting the pin (P1.0) high, then low? #define ONE_SECOND 800000 while (1) { //Set pin to “1” (hint, see question 4) _________________________________________________ ; _delay_cycles( ONE_SECOND ); // Set pin to “0” }

Lab3a – Worksheet Using the _delay_cycles() intrinsic function (from the last chapter), write the code to blink an LED with a 1 second delay setting the pin (P1.0) high, then low? #define ONE_SECOND 800000 while (1) { //Set pin to “1” (hint, see question 4) _________________________________________________ ; _delay_cycles( ONE_SECOND ); // Set pin to “0” } GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0) GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0)

Lab3b – Worksheet 1. What 3 function options can be used to set a pin for GPIO input? Hint, one place to look would be the MSP430 Driverlib Users Guide found here: \MSP430ware_1_97_00_47\driverlib\doc\<target>\ _________________________________________ 2. What can happen to an input pin that isn’t tied high or low? 3a. Which I/O pin on Port 1 is connected to a Switch (on your Launchpad)? 3b. Assuming you need a pull-up resistor for a GPIO input, write the line of code required to setup this pin as an input: _________________________________________; or _________________________________________;

Lab3b – Worksheet 1. What 3 function options can be used to set a pin for GPIO input? Hint, one place to look would be the MSP430 Driverlib Users Guide found here: \MSP430ware_1_97_00_47\driverlib\doc\<target>\ _________________________________________ 2. What can happen to an input pin that isn’t tied high or low? 3a. Which I/O pin on Port 1 is connected to a Switch (on your Launchpad)? 3b. Assuming you need a pull-up resistor for a GPIO input, write the line of code required to setup this pin as an input: _________________________________________________; or _______________________________________________; GPIO_setAsInputPin() GPIO_setAsInputPinWithPullDownResistor() GPIO_setAsInputPinWithPullUpResistor() The input pin could end up floating up or down. This uses more power … and can give you erroneous results. F5529/FR5969: P1.1 FR4133: P1.2 GPIO_setAsInputPinWithPullUpResistor ( GPIO_PORT_P1, GPIO_PIN1) GPIO_setAsInputPinWithPullUpResistor ( GPIO_PORT_P1, GPIO_PIN2)

Lab3b – Worksheet Complete the following code to ­read pin P1.1: volatile unsigned short usiButton1 = 0; while(1) { // Read the pin for push-button S2 usiButton1 = _____________________________________; if ( usiButton1 == GPIO_INPUT_PIN_LOW ) { // If button is down, turn on LED GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 ); } else { // Otherwise, if button is up, turn off LED GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); In embedded systems, what is the name given to the way in which we are reading the button? (Hint, it’s not an interrupt) ____________________________

Lab3b – Worksheet Complete the following code to ­read pin P1.1: volatile unsigned short usiButton1 = 0; while(1) { // Read the pin for push-button S2 usiButton1 = ____________________________________; if ( usiButton1 == GPIO_INPUT_PIN_LOW ) { // If button is down, turn on LED GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 ); } else { // Otherwise, if button is up, turn off LED GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); For ‘FR4133 use GPIO_PIN2 GPIO_getInputPinValue ( GPIO_PORT_P1, GPIO_PIN1 ) In embedded systems, what is the name given to the way in which we are reading the button? (Hint, it’s not an interrupt) ____________________________ “Polling”

http://www.ti.com/training