Hello,
I am relatively new to the MSP430 series and am currently using the F5529 chip. I just getting my feet wet with some really basic code, right now I can successfully fire the timerA interrupt and the ADC12 interrupt separately but when I try to combine the code neither of the interrupts work. I was wondering if it is simply impossible to join them (although I can't see why you wouldn't be able to) or if I have some basic flaw in my code. Please note that I am a beginner so there may be a very simplistic and basic explanation for this. I will post my code below, much of which is basically copied more or less directly from the resource manager sample code.
<code>
/*Basic sandbox experimentation */
//List of include files
#include <msp430f5529.h>
//Declare local sub-routines and functions
void init_Pins(void);
void init_WD_timer(void);
void init_Timer(void);
void init_ADC(void);
//Declare global variables
volatile int i; //used in the timer A0 interrupt service routine
//Main program
void main(void) {
//Initialization sub-routines
init_WD_timer();
init_Pins();
init_Timer();
init_ADC();
while(1){
ADC12CTL0 |= ADC12SC; // Start sampling/conversion
// Enter low power mode, enable interrupts
__bis_SR_register(LPM0_bits + GIE);
__no_operation(); // For debugger
}
}
//////////////////////////////////////
//INTERNAL FUNCTIONS
//////////////////////////////////////
void init_ADC(void){
ADC12CTL0 = ADC12SHT02 + ADC12ON; // 64 CLK cycles sampling time, ADC12 on
ADC12CTL1 = ADC12SHP; // SAMPCON is sourced from sampling timer
ADC12IE = 0x01; // Enable interrupt on ADC12IE0
ADC12CTL0 |= ADC12ENC; // Enable a conversion
P6SEL |= 0x01; //Enable P6.0 as ADC input (p93, 5529 datasheet)
}
void init_Timer(void){
TA0CCTL0 = CCIE; //enable interrupt
TA0CCR0 = 50000; //set timer counter to 50000 (16-bit, max is 65536)
TA0CTL = TASSEL_2 + MC_1 + TACLR; //Using SMCLK, use upmode and reset the clock divider
}
void init_WD_timer(void){
//Stop watchdog timer
WDTCTL = WDTPW + WDTHOLD;
}
void init_Pins(void){
P1OUT = 0x00;
P1DIR = 0xFF;
P2OUT = 0x00;
P2DIR = 0xFF;
P3OUT = 0x00;
P3DIR = 0xFF;
P4OUT = 0x00;
P4DIR = 0xFF;
P5OUT = 0x00;
P5DIR = 0xFF;
P6OUT = 0x00;
P6DIR = 0xFE;
P7OUT = 0x00;
P7DIR = 0xFF;
P8OUT = 0x00;
P8DIR = 0xFF;
}
//////////////////////////////////////
//INTERRUPT SERVICE ROUTINES
//////////////////////////////////////
//ADC12 interrupt service routine
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: // Vector 6: ADC12IFG0
if (ADC12MEM0 >= 0x7ff) // ADC12MEM = A0 > 0.5AVcc?
P1OUT |= BIT0; // P1.0 = 1
else
P1OUT &= ~BIT0; // P1.0 = 0
__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12: break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}
// Timer0 A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
{
i++;
if(i == 10){
P1OUT ^= BIT0; // Toggle P1.0
i = 0;
}
}
</code>