Part Number: MSP430F133
Hello,
It seems like I've beaten my head against the wall trying to get a simple program working. I started with the simple FET140_ADC12_01.C program and added a PORT2 interrupt handler for switches wired to p2.0, p2.1, p2.2, p2.4, p2.5 & p2.6.
The board I am working with has LEDs wired to p3.0, p3.1, p3.2, p3.4.
I am expecting the ADC interrupt to toggle P3.4 at some frequency. (I don't know how long the ADC takes with SHT0_2).
And I am expecting P3.0, P3.1, and P3.2 to toggle when P2.0, P2.1, and P2.2 are shorted to ground by the keypad. This is done in the Port 2 ISR.
When the program first starts I would expect only P3.4 to be toggling at the ADC refresh rate but P3.0, P3.1 and P3.2 off.
Unexpectedly, when the program first comes up, all P3 GPIO are high... P3.4 is NOT toggling at any ADC rate.
If I short P2.0 to ground I get multiple P3.0, P3.1, and P3.2 all transitioning from high to low. Sometimes that kills the program but sometimes the P2 interrupt continues to fire for a couple more key presses.
Any thoughts greatly appreciated....
- Dave
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = SHT0_2 + ADC12ON; // Set sampling time, turn on ADC12
ADC12CTL1 = SHP; // Use sampling timer
P6SEL |= 0x01; // P6.0 ADC option select
// diagnostics
P1DIR |= 0x01; // P1.0 output
P3DIR |= 0xff; // P3.0 .. P3.3 output to LEDs
P3OUT = 0; // all debug pins low
P2DIR &= ~0xff; // all input inputs on P2
P2IFG &= ~0xff; // clear all flags
P2IES |= 0x77; // Set high to low transitions
P2IE |= 0x77; // enable interrupts P2.0,1,2 4,5,6
for (;;)
{
if ((P2IE & 0x77) == 0) // int was triggered and enable cleared in ISR so reenable
{
P2IFG &= ~0xff; // clear int flag.
P2IE |= 0x77; // enable interupts
}
if ((ADC12IE & 0x01) == 0) // int was triggered and enable cleared in ISR so reenable
{
ADC12IFG &= ~0xff; // clear all flag
ADC12IE |= 0x01; // Enable interrupt
ADC12CTL0 |= ENC; // Conversion enabled
ADC12CTL0 |= ADC12SC; // Sampling start
}
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC12_ISR or Port 2 int will force exit
}
}
// ADC12 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=PORT2_VECTOR
__interrupt void PORT2_ISR (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(PORT2_VECTOR))) PORT2_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch (P2IFG){ // what was the cause of the interrupt?
case 0x01: // P2.0 has been triggered
P3OUT ^= 0x01; // Set P3.2 LED on
break;
case 0x02: // P2.1 has been triggered
P3OUT ^= 0x02; // Set P3.2 LED on
break;
case 0x04: // P2.2 has been triggered
P3OUT ^= 0x04; // Set P3.2 LED on
break;
default: // any other interrupt cause that hasn't been handled?
; // then do nothing
}
P2IFG &= ~0x77; // clear int flags
P2IE &= ~0x77; // disable interupts
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
// ADC12 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
#else
#error Compiler not supported!
#endif
{
P3OUT ^= ~0x08; // toggle pin
ADC12CTL0 &= ~ENC; // Conversion disabled
ADC12IFG &= ~0xff; // clear all flags
ADC12IE &= ~0x01; // Disable interrupt
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}