Test Clk32

 Simple program to test if the Clk32 clock is operating ok

 If operates ok blinks Green LED (changes every second)

 If operates bad fixes Red LED of Green LED blinks at different rate

 02/05/2012: Corrected a confict with P1DIR that was accessed by the

                 WDT Timer Interrupt and the main program.


// Include the register definitions.

// msp430h calls the msp430g2553h, but this last file is

// included also to ease the eclipse error checker

#include <msp430.h>

//#include <msp430g2231.h>

#include <msp430g2553.h>

#include <legacymsp430.h>   // Needed for interrupts

#include "io430masks.h"         // My SET/RESET macros

// Defines --------------------------------------------------

#define LED_RED         BIT0 // Red LED at P1.0            Pulses with the Reed switch

#define LED_GREEN   BIT6 // Green LED at P1.6

// Functions ------------------------------------------------

// Simple delay function

void simpleDelay()




// Tries to Start of the Clk32 clock

// Uses default value of DIVA_0

void startClk32()





    CLEAR_FIELD(BCSCTL3,LFXT1S_MASK);         // Set mode 0



   while (BCSCTL3&LFXT1OF); // Loop while faulty


// Configure all the peripherals

void configureAll()


 // Set LEDs as output


 // Red Led while not operating the 32k Clock


 // If device has port 3 but 20 pins

 #ifdef __MSP430_HAS_PORT3_R__



 // Start the 32k clock


 // If started turn off red led


 // Configure WDT as a timer

 WDTCTL=WDT_ADLY_1000;  // t=32768/fACLK=1s

 SET_FLAG(IE1,WDTIE);   // Enable WDT interrupt


int main()        // The main function


 // Disable the watchdog.


 // Configure all the peripherals


 // Enable interrupts


 // do forever:

 while (1)




    if (BCSCTL3&LFXT1OF)






 return 0;


/****************** RSI Functions **********************/

// Watchdog timer interrupt

// Called each second

interrupt(WDT_VECTOR) WDT_ISR(void)


 // Don't need to clear any flag

 // Toggle GREEN Led