'Sequence on embedded C code skipping certain flags
I am developing some code for the MSP-EXP430FR5994, specifically code using the MSP430's ADC. My plan for the ADC is to run a dual-channel ADC capture. However, I have only been able to run the code within the first channel.
Here is my relevant ADC code.
#include <msp430.h>
#include <stdio.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// GPIO Setup
P1OUT &= ~BIT0; // Clear LED to start
P1DIR |= BIT0 | BIT1 | BIT2 ;
P1SEL1 |= BIT3 | BIT4 ;
P1SEL0 |= BIT3 | BIT4 ; // 1.2 set to TA1.1, 1.3 and 1.4 set to ADC input (A3, A4)
P1SEL0 |= BIT2 ; // Check p88-90_s for what the hell we're doing in the last 3 lines
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
P1OUT |= BIT0;
// Clock System Setup
CSCTL0_H = CSKEY_H; // Unlock CS registers
CSCTL1 = DCOFSEL_3; // Set DCO to 4MHz (p105)
CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK; // Set clock source
CSCTL3 = DIVA__1 | DIVS__4 | DIVM__1; // Set all dividers, clock speed 1MHz
CSCTL0_H = 0;
ADC12CTL0 = ADC12SHT0_0 | ADC12MSC | ADC12ON; // Sampling time, S&H=4, ADC12 on [p893, CTL0 = control 0, SHT0_0 = sample & hold time, knowledge of register value from p88_s]
ADC12CTL1 = ADC12SHP | ADC12SHS_4 | ADC12CONSEQ_3; // Use TA1.1 to trigger, (SHP means using sample timer (p897), SHS means "sample-and-hold source select" (p895, p84_s)
// which selects which source is used to activate sampling (4 being TA1.1 because of p84_s), CONSEQ_3 = Conversion sequence select,
// 3 means repeated-multiple-channel which means multiple channels are converted and sampled, memory gets overriden everytime (p881)
ADC12CTL2 |= ADC12RES_2; // 12-bit conversion results, p897
ADC12CTL3 |= ADC12CSTARTADD_3; // Use MEM3/MCTL3 as first, p898
ADC12MCTL3 = ADC12INCH_3; // A3 ADC input select from Input Channel 3 (p901), output to MEM3
ADC12MCTL4 = ADC12INCH_4 | ADC12EOS; // A4 ADC input select, also setting End of sequence bit at A4
ADC12IER0 |= ADC12IE3 | ADC12IE4 ; // Enable ADC interrupt [IER = interrupt enable, for IFG0 bit, which tells us when the sequence is complete]
ADC12CTL0 |= ADC12ENC | ADC12SC; // Start sampling/conversion
// Configure TimerA1.1 to periodically trigger the ADC12
TA1CCR0 = 31250-1; // PWM Period for TA1, change to 32Hz, 31250/1000000 = /32
TA1CCTL1 = OUTMOD_3; // TACCR1 set/reset (Shape of set/reset in p652)
TA1CCR1 = 15625; // TACCR1 PWM Duty Cycle
TA1CTL = TASSEL__SMCLK | MC__UP; // SMCLK, up mode
__bis_SR_register(LPM0_bits | GIE); // Enter LPM0, enable interrupts
}
// ADC12 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC12_B_VECTOR
__interrupt void ADC12ISR (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_B_VECTOR))) ADC12ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(ADC12IV, ADC12IV__ADC12RDYIFG))
{
//Some other flags that were not in use have been removed from this sample. Please let me know if these flags are needed to replicate my code.
case ADC12IV__ADC12IFG3: // Vector 18: ADC12MEM3
//P1OUT ^= BIT5;
printf("Got here 3.\n");
break;
case ADC12IV__ADC12IFG4: // Vector 20: ADC12MEM4
//P1OUT ^= BIT5;
printf("Got here 4.\n");
ADC12MCTL4 |= ADC12EOS;
break;
default: break;
}
}
Please let me know if there's any obvious C syntax I have misplaced. I am aware this is embedded systems (while this is Stackoverflow) but I'm reluctant to dismiss any possibilities. Also, please let me know if any more information is needed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
