MSP 430 Programming

Here I collect some information about MSP 430 programming. I'm using the eZ430-F2013 development kit with an F2012 connected and sometimes the F2013 that comes with the USB stick in de development kit.

Testing Timer A

Example I created to test the Timer A interrupt. The example flashes the Led approximately each second. (In my case about 7 times per 10 seconds..)

/*
 * Testing the MSP430 Timer_A interrupt
 * Based on J H Davies timintC1.c example from the book
 * MSP430 Controller Basics
 */
#include <io430x20x2.h>
#include <intrinsics.h>

#define LED BIT0 // Assign P1.0 to LED

int isSecond = 0;

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  P1OUT = LED;                          // Preload LED on
  P1DIR = LED;                          // Set LED pin to output

  TACCR0 = 49999;                       // Counter limit which triggers the interrupt
  TACCTL0 = CCIE;                       // Enable counter interrupt CCR0
  TACTL = MC_1|ID_3|TASSEL_2|TACLR;     // Setup timer to CCR0, divide 1 Mhz by 8, use 1 Mhz SMCLK clock and clear the timer
  //__enable_interrupt();               // No need to enable the interrupts, enabled by entering low power mode

  // Loop forever
  for (;;) {
     // Low power mode, automatically enables interrupts in MSP family
    __low_power_mode_0();
  }
}

// Interrupt that goes of every 0.5 second
#pragma vector = TIMERA0_VECTOR
__interrupt void TIMER_INTERRUPT_ACTION (void) {
    // Toggle led each second
    if(isSecond) {
        // Toggle LED
        P1OUT ^= LED;
        isSecond = 0;
    } else {
        isSecond = 1;
    }
}

Testing Port1 Interrupts

My colleague created a development board for me which I can connect to the eZ430U Usb stick. The board has a led and 3 buttons. Here I test interrupts for any of the 3 buttons.

/*
 * Testing the MSP430 PORT1 interrupts
 * Based on J H Davies butled4.c example
 * from the book 'MSP430 Controller Basics'
 */
#include <io430x20x2.h>
#include <intrinsics.h>


// My test board with a F2012:
//
// P1.0 - Led (active high)
// P1.3 - connected to RX (out) of an Ipod
// P1.4 - connected to TX (in) of an Ipod
// P1.5 - switch button 1, active low
// P1.6 - switch button 2, active low
// P1.7 - switch button 3, active low

int main(void) {
  // Stop watchdog timer
  WDTCTL = WDTPW | WDTHOLD;

  P1OUT_bit.P1OUT_0 = 0; // Led off
  P1DIR_bit.P1DIR_0 = 1; // Led pin to output mode

  // Button 1
  // Enable interrupts on edge
  P1IE_bit.P1IE_5   = 1;
  // Sesitive to negative edge (High -> Low)
  P1IES_bit.P1IES_5 = 1;

  // Button 2 and 3
  P1IE_bit.P1IE_6   = 1;
  P1IES_bit.P1IES_6 = 1;
  P1IE_bit.P1IE_7   = 1;
  P1IES_bit.P1IES_7 = 1;

  // Clear any pending interrupts
  do {
    P1IFG = 0;
  } while (P1IFG != 0);

  // Loop forever
  for (;;) {
      // Low power mode, automatically enables interrupts in MSP family
      // Mode 4: all clocks off, ram suspend mode
      __low_power_mode_4();
  }
}

#pragma vector = PORT1_VECTOR
__interrupt void PORT_1_INTERRUPT_ACTION (void) {
    P1OUT_bit.P1OUT_0 ^= 1; // Led On / off

    // Show led on as long as the button is pressed:
    P1IES_bit.P1IES_5 ^= 1; // Toggle edge sensitivity
    P1IES_bit.P1IES_6 ^= 1; // Toggle edge sensitivity
    P1IES_bit.P1IES_7 ^= 1; // Toggle edge sensitivity

    // Clear any pending interrupts
    do {
      P1IFG = 0;
    } while (P1IFG != 0);
}
msp430programming.txt · Last modified: 2012/04/14 15:14 (external edit)
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki