/* Arrays to store SD16_A conversion results */
/* NOTE: arrays need to be global to */
/* prevent removal by compiler */
static unsigned int results[Num_of_Results];
void main(void)
{
volatile unsigned int i; // Use volatile to prevent removal
// by compiler optimization
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
FLL_CTL0 |= XCAP14PF; // Configure load caps
for (i = 0; i < 10000; i++); // Delay for 32 kHz crystal to
// stabilize
P1SEL = 0; //GPIO
P1DIR = 0xff; //out
SD16CTL = SD16REFON+SD16SSEL0; // 1.2V ref, SMCLK
SD16INCTL0 |= SD16INTDLY_0; // Interrupt on 4th sample
SD16CCTL0 |= SD16IE ; // Enable interrupt
for (i = 0; i < 0x3600; i++); // Delay for 1.2V ref startup
_EINT(); // Enable general interrupts
SD16CCTL0 |= SD16SC; // Set bit to start conversion
_BIS_SR(LPM0_bits); // Enter LPM0
}
#pragma vector=SD16_VECTOR
__interrupt void SD16ISR(void)
{
static unsigned int index = 0;
switch (SD16IV)
{
case 2: // SD16MEM Overflow
break;
case 4: // SD16MEM0 IFG
results[index] = SD16MEM0; // Save CH0 results (clears IFG)
P1OUT = 0x03; //Pin 0,1 out 1
if (++index == Num_of_Results)
{
index = 0; // SET BREAKPOINT HERE
//SD16CCTL0 &=~ SD16SC;
P1OUT = 0x00; //Pin 0,1 out 0
}
break;
}
}