This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430I2041: msp430i2041

Part Number: MSP430I2041


Tool/software: Code Composer Studio

Dear All,

I am struggling with comprehending the complete process of "SD24 interrupts". So, this is the following code that I have been using:

#include "driverlib.h"

uint16_t results[320];                       // SD24 Conversion and Temp Results
                                                // results[0] = raw SD24 results
                                                // results[1] = temp in K
                                                // results[2] = temp in C
                                                // results[3] = temp in F
uint8_t Flag_1 = 0;                        //Flag 1 for ADC
uint8_t Flag_2 = 0;                        //Flag 2 for Data ready
uint16_t start_timer_counter;
uint16_t stop_timer_counter;
uint16_t ticks_timer_counter;

uint16_t result0_ADC;
uint16_t square_ADC;
uint16_t sum_square_ADC;


void main(void)
{
    uint16_t i = 0;
    // Stop WDT
    WDT_hold(WDT_BASE);

    // Internal ref
    SD24_init(SD24_BASE, SD24_REF_INTERNAL);

    //Ch0 single mode, internal temp sensor
    SD24_initConverterAdvancedParam param = {0};
    param.converter = SD24_CONVERTER_0;
    param.conversionMode = SD24_CONTINUOUS_MODE;
    param.groupEnable = SD24_NOT_GROUPED;
    param.inputChannel = SD24_INPUT_CH_ANALOG;
    param.dataFormat = SD24_DATA_FORMAT_BINARY;
    param.interruptDelay = SD24_FOURTH_SAMPLE_INTERRUPT;
    param.oversampleRatio = SD24_OVERSAMPLE_256;
    param.gain = SD24_GAIN_16;
    SD24_initConverterAdvanced(SD24_BASE, &param);
    SD24_enableInterrupt(SD24_BASE, SD24_CONVERTER_0, SD24_CONVERTER_INTERRUPT);

    // Delay ~200us for 1.2V ref to settle
    __delay_cycles(3200);

    // Start conversion
    SD24_startConverterConversion(SD24_BASE, SD24_CONVERTER_0);

    while(1)
   {
        __bis_SR_register(LPM0_bits | GIE);
        __no_operation();
        if (Flag_1 == 1)
        {
             Flag_1 = 0;
        }
   }
}

//----------------------------------------------------------------------------------------------------------------
//Interrupt Functions
//---------------------------------------------------------------------------------------------------------------
//ADC
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=SD24_VECTOR
__interrupt void SD24_ISR(void) {
#elif defined(__GNUC__)
void __attribute__ ((interrupt(SD24_VECTOR))) SD24_ISR (void)
{
#else
#error Compiler not supported!
#endif
    switch (__even_in_range(SD24IV,SD24IV_SD24MEM3))
    {
        case SD24IV_NONE: break;
        case SD24IV_SD24OVIFG: break;
        case SD24IV_SD24MEM0:
                   // Save CH0 results (clears IFG)
                    result0_ADC = SD24_getHighWordResults(SD24_BASE, SD24_CONVERTER_0);
                    results[i] = result0_ADC;
                    i=i+1;
                    if (i>319)
                    {
                        i = 0;
                        Flag_1 = 1;
                    }
                    __no_operation();//breakpoint
                   break;
        case SD24IV_SD24MEM1: break;
        case SD24IV_SD24MEM2: break;
        case SD24IV_SD24MEM3: break;
        default: break;
    }
    
    __bic_SR_register_on_exit(LPM0_bits);       // Wake up from LPM0

}

1. here's what I think is happening: The SD24 starts conversion before entering the while loop, as soon the data is ready, interrupt is raised and the SD24 starts the next conversion. While the next conversion goes on, the interrupt routine is performed; i.e. storing the ADC value to array, checking if i>319, and finally raising/waking up the CPU.

2. Once the CPU is woken up, it checks the flag and goes back to LPM0.

Please correct me if I am wrong and shed more light on it.

Thank you

Regards,
Neal

  • 1. here's what I think is happening: The SD24 starts conversion before entering the while loop, as soon the data is ready, interrupt is raised and the SD24 starts the next conversion. While the next conversion goes on, the interrupt routine is performed; i.e. storing the ADC value to array, checking if i>319, and finally raising/waking up the CPU.

    2. Once the CPU is woken up, it checks the flag and goes back to LPM0.

    Please correct me if I am wrong and shed more light on it.

    Thank you

    Regards,
    Neal
  • I think you've described it completely.

    Once flag_1 == 1, you have a full buffer (320 samples) to work with. You should probably grab results[0] fairly soon since the next conversion(ISR call) will overwrite it.

**Attention** This is a public forum