<< Chapter < Page Chapter >> Page >
This module goes over the basics of digital I/O and the digital interface between a microcontroller and the outside world.

Basic digital i/o in the real world

In this lab you'll go over the basics of how to setup and use the GPIO on the MSP430. This will allow you to get data from the outside world, run some processing on it, and then output it again as useful information. You only have one task this week:

  1. Coding in MSP430 assembly, write a simple I/O echo program . Setup the GPIO pins and poll the input switches for any changes. On a change, take the input and display it to the output. Step through this program to observe how it behaves. Assignment Details

Digital i/o basics

Gpio

    Philosophy

  • The MSP430 uses a limited number of GPIO hardware pins that are assignable to several functions depending on your specific model and your program's needs. Our version, the MSP430G2231, can have the Port_1 pins act as digital output, digital input, or ADC input.
  • The pins are organized into ports, with each port usually one byte (8 bits/pins) wide. On larger versions of the processor (different format chips with physically many more pins...) you can encounter several ports, but in this lab you will only be using Port_1 and Port_2
  • You can set each pin's function independently (input or output) by modifying some memory mapped I/O registers. Since we want to do both, we will divide P1 into half inputs and half outputs as needed.

    Usage

  • The I/O ports are memory mapped into the top of the MSP430 address space.
  • There are several registers associated with each port. For now, you only need to worry about four (P1IN, P1OUT, P1DIR, and P1REN).

      P1in

    • The P1IN register is located at address 0x0020 in memory, which you can also refer to using the C symbol &P1IN
    • The register holds the values the MSP430 sees at each pin, regardless of the pin direction setting.
    • To read the register, it is good practice to use a mov.b instruction to avoid accidentally reading adjacent registers
    • If you are looking to test or read just the pins set to input, you will have to mask the P1IN register to zero out the other unwanted/output pins. Reading P1IN reads the entire port, regardless of pin direction.

      P1out

    • The P1OUT register is located at address 0x0021 in memory, which you can also refer to using the C symbol &P1OUT
    • If their direction bits in P1DIR are set to output/ "1", the corresponding pins will output the values set in P1OUT.
    • If a pin's direction bits are set to input in P1DIR and its resistors are enabled in P1REN, P1OUT controls the pin's connection to the pull-up resistor. Setting P1OUT to "1" enables the pull-up, while setting it to "0" leaves the input to float in a high impedance state.
    • To set P1OUT, use a mov.b instruction to set several pins at once. To set individual bits to "1", you can use an or.b instruction with a "1" in the positions you want to set. To clear individual bits/ set them to zero, use an and.b instruction with mostly "1"s except for a "0" for the bits you want to clear.

      P1dir

    • The P1DIR register is located at address 0x0022 in memory, which you can also refer to using the C symbol &P1DIR
    • The value of the bits in P1DIR determines whether the MSP430 hardware leaves the pin in a high impedance state where it responds to external voltage changes (which you can read at P1IN), or in a low impedance state where the MSP430 drives the output voltage to a certain value determined by P1OUT.
    • To set the bit directions all at once, use a mov.b instruction, but to change individual bits regardless of the others, use an and.b or a or.b
    • Set the corresponding bits to "0" to set pins to input mode, or to "1" to set them to output mode.

      P1ren

    • The P1REN register is located at address 0x0027 in memory, which you can also refer to using the C symbol &P1REN
    • P1REN controls whether the MSP430 Launchpad enables the integrated pull-up resistor for a given pin.
    • The pull-up resistors allow the use of single pole switches. They prevent the input signals from floating randomly while the switches are open by loosely tying the inputs to Vcc. When the switch is closed though, the much stronger connection to ground wins out, pulling the inputs down to GND.
    • Set the corresponding bits to "1" to enable a pin's pull-up resistor, or to "0" to disable it (disabled by default).

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Intro to computational engineering: elec 220 labs. OpenStax CNX. Mar 11, 2013 Download for free at http://cnx.org/content/col11405/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Intro to computational engineering: elec 220 labs' conversation and receive update notifications?

Ask