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.

ADC128S102EVM: MSP-EXP430FR5969 Code please

Part Number: ADC128S102EVM

Tool/software:

Hi,

May you share your Code With me?
You can send it to:
Moralas1@gmail.com

Much appreciation,
Thanks,
Moral. 

  • Hi Moral,

    This is the code from the original post. You can try connecting with the original author of the code and seeing if he has made any updates. I'm closing this thread as it looks like the full code is available in the original post.

    #include "driverlib.h"
    
     
    #define ADCVREF 2895 // ADC Vref - measured as 2.895V on the EVM
    
    #define Port_4_nADC_CS                 (0x04)          //  P4.2. !CS for ADC128S102
    
     
    volatile static int index = 0;
    
    volatile unsigned short spiRxDataArr[8] = {0,0,0,0,0,0,0,0};
    
    volatile unsigned char spiTxDataArr[] = {0x00, 0x08, 0x10, 0x18, 0x20,0x28, 0x30, 0x38, 0x00};
    
    volatile static int msbLsbTX = 1;
    
    volatile static int msbLsbRX = 1;
    
    volatile static int firstFlag = 1;
    
    volatile unsigned short adcmVoltage[8] = {0,0,0,0,0,0,0,0};
    
     
    
    void main(void)
    
    {
    
        //Stop watchdog timer
    
        WDT_A_hold(WDT_A_BASE);
    
     
    
        /*
    
         * Select Port 1
    
         * Set Pin 0 as output
    
         */
    
        GPIO_setAsOutputPin(
    
            GPIO_PORT_P1,
    
            GPIO_PIN0
    
        );
    
        /*
    
        * Select Port 1
    
        * Set Pin 0 to output Low.
    
        */
    
        GPIO_setOutputLowOnPin(
    
            GPIO_PORT_P1,
    
            GPIO_PIN0
    
        );
    
     
    
        //Set DCO frequency to 16 MHz DCO setting
    
        CS_setDCOFreq(CS_DCORSEL_1,CS_DCOFSEL_4);
    
        //Select DCO as the clock source for SMCLK with no frequency divider
    
        CS_initClockSignal(CS_SMCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
    
         /*
    
        * Select Port 2
    
        * Set Pin 2 to input Secondary Module Function, (UCB0CLK).
    
        */
    
        GPIO_setAsPeripheralModuleFunctionInputPin(
    
            GPIO_PORT_P2,
    
            GPIO_PIN2,
    
            GPIO_SECONDARY_MODULE_FUNCTION
    
        );
    
     
    
        /*
    
        * Select Port 1
    
        * Set Pin 6, 7 to input Secondary Module Function, (UCB0TXD/UCB0SIMO, UCB0RXD/UCB0SOMI).
    
        */
    
        GPIO_setAsPeripheralModuleFunctionInputPin(
    
            GPIO_PORT_P1,
    
            GPIO_PIN6 + GPIO_PIN7,
    
            GPIO_SECONDARY_MODULE_FUNCTION
    
        );
    
     
    
        /*
    
        * Disable the GPIO power-on default high-impedance mode to activate
    
        * previously configured port settings
    
        */
    
        PMM_unlockLPM5();
    
     
    
        P4DIR |= 0x04;  //  Configure P4.2 (/ADC_CS) as an output.
    
     
    
        //Initialize Master
    
        EUSCI_B_SPI_initMasterParam param1 = {0};
    
        param1.selectClockSource = EUSCI_B_SPI_CLOCKSOURCE_SMCLK;
    
        param1.clockSourceFrequency = CS_getSMCLK();
    
        param1.desiredSpiClock = 8000000; // 8 MHz clock (min requirement for adc128s102)
    
        param1.msbFirst = EUSCI_B_SPI_MSB_FIRST;
    
        param1.clockPhase = EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT;
    
        param1.clockPolarity = EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH;
    
        param1.spiMode = EUSCI_B_SPI_3PIN;
    
        EUSCI_B_SPI_initMaster(EUSCI_B0_BASE, &param1);
    
     
    
        //Enable SPI module
    
        EUSCI_B_SPI_enable(EUSCI_B0_BASE);
    
        EUSCI_B_SPI_clearInterrupt(EUSCI_B0_BASE, EUSCI_B_SPI_RECEIVE_INTERRUPT);
    
        // Enable USCI_B0 RX interrupt
    
        EUSCI_B_SPI_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_SPI_RECEIVE_INTERRUPT);
    
     
    
        //Wait for slave to initialize
    
        __delay_cycles(100);
    
     
    
        P4OUT |= Port_4_nADC_CS;  // /ADC_CS frames the SPI transmission.  Initialize here.
    
        __delay_cycles(2000);
    
        P4OUT &= ~Port_4_nADC_CS;
    
     
    
        //USCI_B0 TX buffer ready?
    
        while (!EUSCI_B_SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_B_SPI_TRANSMIT_INTERRUPT)) ;
    
         //Transmit Data to slave (MSB) - Get the process started
    
        EUSCI_B_SPI_transmitData(EUSCI_B0_BASE, spiTxDataArr[index]);
    
        msbLsbTX = 0;
    
     
    
        __bis_SR_register(LPM0_bits + GIE);      // CPU off, enable interrupts
    
        __no_operation();                       // Remain in LPM0 */
    
    }
    
     
    
     
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    
    #pragma vector=USCI_B0_VECTOR
    
    __interrupt
    
    #elif defined(__GNUC__)
    
    __attribute__((interrupt(USCI_B0_VECTOR)))
    
    #endif
    
    void USCI_B0_ISR (void)
    
    {
    
        volatile unsigned char temp = 0x00; // need to get rid of this - easy to see data in debug
    
        switch (__even_in_range(UCB0IV, USCI_SPI_UCTXIFG))
    
        {
    
            // first 4 bits are zeros, then 12 bit data
    
            case USCI_SPI_UCRXIFG:      // UCRXIFG
    
                //USCI_B0 TX buffer ready?
    
                while (!EUSCI_B_SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_B_SPI_TRANSMIT_INTERRUPT));
    
                 if (firstFlag){ // skip collecting the first 16 bits - garbage
    
                    if(!msbLsbRX){
    
                        firstFlag = 0;
    
                        msbLsbRX = 1;
    
                        index++;
    
                    }
    
                    else
    
                        msbLsbRX = 0;
    
                }
    
                else{
    
                    if(msbLsbRX){//MSB
    
                        temp = EUSCI_B_SPI_receiveData(EUSCI_B0_BASE);
    
                        spiRxDataArr[index-1] = spiRxDataArr[index-1] | temp << 8;
    
                        msbLsbRX = 0;
    
                    }
    
                    else{//LSB
    
                        temp =  EUSCI_B_SPI_receiveData(EUSCI_B0_BASE);
    
                        spiRxDataArr[index-1] = spiRxDataArr[index-1] | temp;
    
                        // SPI bits * Vref (2895 mV)/4096
    
                        adcmVoltage[index-1] = (unsigned short) (((unsigned long)spiRxDataArr[index-1] * ADCVREF)>>12); // divide by 4096
    
                        msbLsbRX = 1;
    
                        index++;
    
                        if (index > 8)
    
                            index = 1;
    
                    }
    
     
    
                }
    
                 //Send next value
    
                if(!msbLsbTX){ //LSB
    
                    EUSCI_B_SPI_transmitData(EUSCI_B0_BASE,0x00);
    
                    msbLsbTX = 1;
    
                    P4OUT |= Port_4_nADC_CS;
    
                }
    
                else{ //MSB
    
                    P4OUT &= ~Port_4_nADC_CS;
    
                    EUSCI_B_SPI_transmitData(EUSCI_B0_BASE,spiTxDataArr[index]);
    
                    msbLsbTX = 0;
    
                }
    
     
    
                break;
    
            default:
    
                break;
    
        }
    
    }