Presentation is loading. Please wait.

Presentation is loading. Please wait.

UBI >> Contents Chapter 6 General Purpose Input/Output MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro.

Similar presentations


Presentation on theme: "UBI >> Contents Chapter 6 General Purpose Input/Output MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro."— Presentation transcript:

1 UBI >> Contents Chapter 6 General Purpose Input/Output MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar, António Espírito Santo, Bruno Ribeiro, Humberto Santos University of Beira Interior, Electromechanical Engineering Department Copyright 2009 Texas Instruments All Rights Reserved

2 UBI >> Contents 2 Copyright 2009 Texas Instruments All Rights Reserved Contents Introduction I/O port registers I/O port registers Interruptible ports Interruptible ports Laboratory 2: Blinking the LED: Laboratory 2: Blinking the LED Lab2A: Blinking the LED LAB2B: Blinking the LED at ½ speed Lab2C: Toggle the LED state by button press Lab2D: Enable/disable LED blinking by button press Quiz

3 UBI >> Contents 3 Copyright 2009 Texas Instruments All Rights Reserved Introduction (1/3) Up to ten 8-bit digital Input/Output (I/O) ports, P1 to P10 (depending on the MSP430 device); I/O ports P1 and P2 have interrupt capability; Each interrupt for these I/O lines can be individually configured: To provide an interrupt on a rising or falling edge; All interruptible I/O lines source a single interrupt vector. The available digital I/O pins for the hardware development tools: eZ430-F2013: 10 pins - Port P1 (8 bits) and Port P2 (2 bits); eZ430-RF2500: 32 pins - Port P1 to P4 (8 bits); Experimenters board: 80 pins – Port P1 to P10 (8 bits).

4 UBI >> Contents 4 Copyright 2009 Texas Instruments All Rights Reserved Introduction (2/3) Each I/O port can be: Programmed independently for each bit; Combine input, output, and interrupt functionality; Edge-selectable input interrupt capability for all 8 bits of ports P1 and P2; Read/write access to port-control registers is supported by all two- or one-address instructions; Individually programmable pull-up/pull-down resistor (2xx family only).

5 UBI >> Contents 5 Copyright 2009 Texas Instruments All Rights Reserved Introduction (3/3) The port pins can be individually configured as I/O for special functions, such as: USART – Universal Synchronous/Asynchronous Receive/Transmit for serial data; Input comparator for analogue signals; Analogue-to-Digital converter; Others functions (see specific datasheet for details).

6 UBI >> Contents 6 Copyright 2009 Texas Instruments All Rights Reserved Registers (1/6) Independent of the I/O port type (non-interruptible or interruptible), the operation of the ports is configured by user software, as defined by the following registers: Direction Registers (PxDIR): Read/write 8-bit registers; Select the direction of the corresponding I/O pin, regardless of the selected function of the pin (general purpose I/O or as a special function I/O); For other module functions, must be set as required by the other function. PxDIR configuration: Bit = 1: the individual port pin is set as an output; Bit = 0: the individual port pin is set as an input.

7 UBI >> Contents 7 Copyright 2009 Texas Instruments All Rights Reserved Registers (2/6) Input Registers (PxIN): When pins are configured as GPIO, each bit of these read-only registers reflects the input signal at the corresponding I/O pin; PxIN configuration: Bit = 1: The input is high; Bit = 0: The input is low; Tip: Avoid writing to these read-only registers because it will result in increased current consumption.

8 UBI >> Contents 8 Copyright 2009 Texas Instruments All Rights Reserved Registers (3/6) Output Registers (PxOUT): Each bit of these registers reflects the value written to the corresponding output pin. PxOUT configuration: Bit = 1: The output is high; Bit = 0: The output is low. –Note: the PxOUT Register is read-write. This means that the previous value written to it can be read back and modified to generate the next output signal.

9 UBI >> Contents 9 Copyright 2009 Texas Instruments All Rights Reserved Registers (4/6) Pull-up/down Resistor Enable Registers (PxREN): Only available for the 2xx family; Each bit of this register enables or disables the pull- up/pull-down resistor of the corresponding I/O pin. PxREN configuration: –Bit = 1: Pull-up/pull-down resistor enabled; –Bit = 0: Pull-up/pull-down resistor disabled. –When pull-up/pull-down resistor is enabled: –In this case Output Registers (PxOUT) select: »Bit = 1: The pin is pulled up; »Bit = 0: The pin is pulled down.

10 UBI >> Contents 10 Copyright 2009 Texas Instruments All Rights Reserved Registers (5/6) Function Select Registers: (PxSEL) and (PxSEL2): Some port pins are multiplexed with other peripheral module functions (see the device-specific datasheet); These bits: PxSEL and PxSEL2 (see specific device datasheet), are used to select the pin function: –I/O general purpose port; –Peripheral module function. PxSEL configuration: Bit = 0: I/O Function is selected for the pin; Bit = 1: Peripheral module function enabled for pin.

11 UBI >> Contents 11 Copyright 2009 Texas Instruments All Rights Reserved Registers (6/6) Function Select Registers: (PxSEL) and (PxSEL2): The 2xx family of devices provide the PxSEL2 bit to configure additional features of the device; The PxSEL and PxSEL2 bits in combination provide the following configuration: –Bit = 0: I/O function is selected for the pin; –Bit = 1: Peripheral module function is selected for the pin. PxSELPxSEL2Pin Function 00Selects general purpose I/O function 01Selects the primary peripheral module function 10Reserved (See device-specific data sheet) 11Selects the secondary peripheral module function Note: P1 and P2 configured as peripheral module function (PxSEL = 1 and/or PxSEL2) -> interrupts disabled.

12 UBI >> Contents 12 Copyright 2009 Texas Instruments All Rights Reserved Interruptible ports (P1 and P2) (1/2) Each pin of ports P1 and P2 is able to make an interrupt request; Pins are configured with additional registers: Interrupt Enable (PxIE): Read-write register to enable interrupts on individual pins; PxIE configuration: Bit = 1: The interrupt is enabled; Bit = 0: The interrupt is disabled. Each PxIE bit enables the interrupt request associated with the corresponding PxIFG interrupt flag; Writing to PxOUT and/or PxDIR can result in setting PxIFG.

13 UBI >> Contents 13 Copyright 2009 Texas Instruments All Rights Reserved Interruptible ports (P1 and P2) (2/2) Interrupt Edge Select Registers (PxIES): Selects the transition on which an interrupt occurs (if PxIE and GIE are set); PxIES configuration: Bit = 1: Interrupt flag is set on a high-to-low transition; Bit = 0: Interrupt flag is set on a low-to-high transition. Interrupt Flag Registers (PxIFG) Set automatically when an the programmed signal transition (edge) occurs; PxIFG flag can be set and must be reset by software. PxIFG configuration: Bit = 0: No interrupt is pending; Bit = 1: An interrupt is pending.

14 UBI >> Contents 14 Copyright 2009 Texas Instruments All Rights Reserved Laboratory 2: Blinking the LED Configure the I/O ports to use inputs from push buttons to control the output lines feeding LEDs; The following exercises have been developed for the hardware development tools: Experimenters board; eZ430-RF2500; eZ The main differences between these development tools are the specific ports used for the input push buttons and output LEDs.

15 UBI >> Contents 15 Copyright 2009 Texas Instruments All Rights Reserved Lab2A: Blinking the LED (1/6) Procedure: Check schematics for LED port location (Consult the Hardware Development Tool User's Guide); Port control registers: Set LED pin port as an output; Switch the port state between low and high state during program execution. Configure the watchdog timer to prevent a Power-Up Clear (PUC); Use an infinite loop to modify the state of the port; Use a software delay loop to generate the pause interval (a software delay loop with a long time period is used here for simplicity - in real applications a timer would be used).

16 UBI >> Contents 16 Copyright 2009 Texas Instruments All Rights Reserved Lab2A: Blinking the LED (2/6) Schematics: MSP-EXP430FG4618SOLUTION Using the MSP-EXP430FG4618 Development Tool and the MSP430FG4618 device, blink LED1.

17 UBI >> Contents 17 Copyright 2009 Texas Instruments All Rights Reserved Lab2A: Blinking the LED (3/6) LED1 is connected to Port 2.2; Port control registers: P2DIR: Port 2.2 is set as an output: P2DIR |= 0x04 {to force the pin setting, an OR operation ( | ) is performed using P2DIR and 0x04. This makes bit 2 -> 1, without affecting any other port pins. }. P2OUT: P2OUT ^= 0x04 ; To switch the port state between low and high states, an XOR operation ( ^ ) is performed using P2OUT and 0x04. This reads the value previously written to P2OUT and makes bit 2 change state from 0 -> 1 and 1 -> 0. MSP-EXP430FG4618SOLUTION Using the MSP-EXP430FG4618 Development Tool and the MSP430FG4618 device, blink LED1.

18 UBI >> Contents 18 Copyright 2009 Texas Instruments All Rights Reserved Lab2A: Blinking the LED (4/6) To prevent a PUC, the watchdog timer: Must be stop and write 0x5A to the eight MSBs of the Watchdog Timer Control Register, WDTCTL : WDTCTL = WDTHOLD | WDTPW Since no clock has been defined, the device will use a kHz watch crystal: To implement a blinking LED rate of one transition per second, the software delay loop should count to approximately { 30000/ sec }. MSP-EXP430FG4618SOLUTION Using the MSP-EXP430FG4618 Development Tool and the MSP430FG4618 device, blink LED1.

19 UBI >> Contents 19 Copyright 2009 Texas Instruments All Rights Reserved Lab2A: Blinking the LED (5/6) The LED1 is connected to Port 1.1; The programming code follows the same sequence as given for the MSP-EXP430FG4618, requiring only configuration of this port pin. eZ430-RF2500SOLUTION Using the eZ430-RF2500 Development Tool, blink the red LED.

20 UBI >> Contents 20 Copyright 2009 Texas Instruments All Rights Reserved Lab2A: Blinking the LED (6/6) The LED is connected to Port 1.0; The programming code follows the same sequence as given for the MSP-EXP430FG4618, requiring only configuration of this port pin. eZ430-F2013SOLUTION Using the Ez430-F2013 Development Tool, blink the LED.

21 UBI >> Contents 21 Copyright 2009 Texas Instruments All Rights Reserved Lab2B: Blinking the LED 1/2 the speed Procedure: Using the previous example as a starting point, re-write the code to reduce the value of the software delay to half its previous value; As the LED changes state once per second, the software delay loop should count to approximately { 15000/ sec }.

22 UBI >> Contents 22 Copyright 2009 Texas Instruments All Rights Reserved Lab2C: Toggle the LED state by pressing the button (1/5) Procedure: Analyse the schematics for the locations of the ports used for the LED and button S1 (Consult the Hardware Development Tool User's Guide); Port control registers: Set button pin port as an input; Enable interrupts on this port pin. Configure the watchdog timer to prevent a PUC; Configure a low power mode.

23 UBI >> Contents 23 Copyright 2009 Texas Instruments All Rights Reserved Lab2C: Toggle the LED state by pressing the button (2/5) LED1 configuration is given in Lab 2A; Button S1 is connected to Port 1.0; Port control registers: P1DIR: Port 1.0 is set as an input: P1DIR &= ~0x01 {to force the pin setting to 0, it uses an AND operation ( & ) between P1DIR and 0xFE }. MSP-EXP430FG4618SOLUTION Use the S1 button of the development tool to toggle the state of LED1. You must use interrupts to detect the button press and you should ensure that the MSP430 is in Low Power Mode 3 when it is not in use.

24 UBI >> Contents 24 Copyright 2009 Texas Instruments All Rights Reserved Lab2C: Toggle the LED state by pressing the button (3/5) Port control registers: P1IE: Enable interrupt to port 1.0. PIIES: Call the port interrupt in a high-to-low transition. Configure Watchdog timer. MSP-EXP430FG4618SOLUTION Use the S1 button of the development tool to toggle the state of LED1. You must use interrupts to detect the button press and you should ensure that the MSP430 is in Low Power Mode 3 when it is not in use.

25 UBI >> Contents 25 Copyright 2009 Texas Instruments All Rights Reserved Lab2C: Toggle the LED state by pressing the button (4/5) Enable Global Interrupts; Configure the low power mode 3; Create an ISR, that includes: Toggle LED1 pin port; Delay for button debounce; Clear interrupt flag. MSP-EXP430FG4618SOLUTION Use the S1 button of the development tool to toggle the state of LED1. You must use interrupts to detect the button press and you should ensure that the MSP430 is in Low Power Mode 3 when it is not in use.

26 UBI >> Contents 26 Copyright 2009 Texas Instruments All Rights Reserved Lab2C: Toggle the LED state by pressing the button (5/5) Follow the same sequence as given previously, taking note that: Button S1 is connected to Port 1.2. Port control registers: The eZ430-RF2500 uses a device in the 2xx family, so you need to additionally configure the Port 1.2 with a pull-up or pull-down, in the P1REN register. eZ430-RF2500SOLUTION Use the button of the development tool to toggle the state of the red LED. You must use interrupts to detect the button press and you should ensure that the MSP430 is in Low Power Mode 3 when it is not in use.

27 UBI >> Contents 27 Copyright 2009 Texas Instruments All Rights Reserved Lab2D: Enable/disable LED blinking by button press (1/3) Procedure: Improve the last exercise (Lab 2C) to enable the LED blinking with a button press; Use the previous configuration; Include a control flow program variable that detects whether the LED is blinking or not when the button is pressed.

28 UBI >> Contents 28 Copyright 2009 Texas Instruments All Rights Reserved Lab2D: Enable/disable LED blinking by button press (2/3) Follow the same sequence as given in Lab 2C; Detect if the button is pressed: if (!(P1IN & 0x01)) ; Define a variable that indicates whether the LED is blinking; Set the program flow depending on the state of this variable. MSP-EXP430FG4618SOLUTION Use the S1 button of the development tool to start and stop the LED blinking. It is not necessary to use Lower Power Modes in this exercise.

29 UBI >> Contents 29 Copyright 2009 Texas Instruments All Rights Reserved Lab2D: Enable/disable LED blinking by button press (3/3) Follow the same sequence as given in Lab 2C for this hardware development tool and the additional steps provided above. eZ430-RF2500SOLUTION Use the button in the development tool to start and stop the LED blinking. It is not necessary to use Low Power Modes in this exercise.

30 UBI >> Contents 30 Copyright 2009 Texas Instruments All Rights Reserved Quiz (1/4) In the MSP430 system all I/O ports: (a) Are initially set as outputs when the system powers up; (b) Remain constant as the application program proceeds; (c) Vary with each step of the program; (d) Are initially set as inputs when the system powers up. 2. To set an I/O port pin as output, the: (a) PxDIR direction register bit is set; (b) PxSEL function-select register bit is set; (c) PxIN register bit is set; (d) PxOUT register bit is set.

31 UBI >> Contents 31 Copyright 2009 Texas Instruments All Rights Reserved Quiz (2/4) 3. An input pin on the MSP430 I/O port configuration requires: (a) Reset the direction register bit, if it previously was set; (b) Set the PxIN register bit to whatever the input data dictates; (c) PxOUT register bit inactive; (d) All of above. 4. For the 2xx family hardware development tools (eZ430-F2013 and eZ430-RF2500), an output pin is pulled down when: (a) PxDIR and PxREN are set; (b) PxDIR is set, PxREN is reset; (c) PxDIR, PxREN and PxOUT are set; (d) PxDIR and PxOUT are reset.

32 UBI >> Contents 32 Copyright 2009 Texas Instruments All Rights Reserved Quiz (3/4) 5. The eZ430-F2013 Port 1 I/O pin as Sigma/Delta ADC (SD16_A) positive analogue input A0 requires: (a) Set P1SEL bit 0 and P1DIR bit 0; (b) Set P1OUT bit 1 and reset P1DIR bit 1; (c) Set P1IN bit 2 and reset P1DIR bit 2; (d) Set P1SEL bit 1 and reset P1DIR bit To configure an I/O Port 2 to generate an interrupt request during an low-to-high transition: (a) Set the P2DIR, P2IE and P2IES associated bits; (b) Set the P2IE associated bit and reset the P2DIR and P2IES associated bits; (c) Set the P2IE and P2DIR associated bits and reset the P2IES associated bits; (d) None of the above.

33 UBI >> Contents 33 Copyright 2009 Texas Instruments All Rights Reserved Quiz (4/4) Answers: 1. (d) Are initially set as inputs when the system powers up. 2. (a) PxDIR direction register bit set. 3. (a) Reset the direction register bit, if it was previously set. 4. (b) PxDIR is set, PxREN is reset. 5. (a) Set P1SEL bit 0 (P1SEL = 0x01h) and P1DIR bit 0 (P1DIR = 0x01h). 6. (b) Set the P2IE associated bit and reset the P2DIR and P2IES associated bits.


Download ppt "UBI >> Contents Chapter 6 General Purpose Input/Output MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro."

Similar presentations


Ads by Google