Texas Instruments Texas Instruments

How to use MSP430 DriverLib ROM 


    Steps to utilize DriverLib in ROM from a user application
  1. Please locate rom_driverlib.h. A copy can be found inside driverlib/{FAMILY}

  2. Optional but recommended step: Please locate rom_map_driverlib.h. A copy can be found inside driverlib/{FAMILY}

  3. Please locate rom_headers/ directory. A copy can be found inside driverlib/{FAMILY}

  4. By default, the rom_driverlib.h you use must be at same directory level as rom_headers/

  5. Make sure #include "driverlib.h" is present in the application code



#include "driverlib.h"
#include "Board.h"

void main (void)
{
    //Stop Watchdog Timer
    //NOTE: Example of what to do if you need to execute from ROM; use ROM_ prefix
    //NOTE: You may get a build error if particular function is not in ROM
    ROM_WDT_A_hold(WDT_A_BASE);

    //Set A7 as an input pin.
    //Set appropriate module function
    //NOTE: Example of what to do if you need to execute from FRAM; leave out ROM_ and MAP_ prefix
    //NOTE: You will need to provide DriverLib source for this function
    GPIO_setAsPeripheralModuleFunctionInputPin(
            GPIO_PORT_ADC7,
            GPIO_PIN_ADC7,
            GPIO_FUNCTION_ADC7);

    //Set LED1 as an output pin.
    //NOTE: Using MAP_ will execute from ROM if available, FRAM if not available
    MAP_GPIO_setAsOutputPin(
            GPIO_PORT_LED1,
            GPIO_PIN_LED1);

    //Set LED2 as an output pin.
    MAP_GPIO_setAsOutputPin(
            GPIO_PORT_LED2,
            GPIO_PIN_LED2);

    /*
     * Disable the GPIO power-on default high-impedance mode to activate
     * previously configured port settings
     */
    MAP_PMM_unlockLPM5();

    //Initialize the ADC Module
    /*
     * Base Address for the ADC Module
     * Use internal ADC bit as sample/hold signal to start conversion
     * USE MODOSC 5MHZ Digital Oscillator as clock source
     * Use default clock divider of 1
     */
    MAP_ADC_init(ADC_BASE,
            ADC_SAMPLEHOLDSOURCE_SC,
            ADC_CLOCKSOURCE_ADCOSC,
            ADC_CLOCKDIVIDER_1);

    MAP_ADC_enable(ADC_BASE);

    /*
     * Base Address for the ADC Module
     * Sample/hold for 16 clock cycles
     * Do not enable Multiple Sampling
     */
    MAP_ADC_setupSamplingTimer(ADC_BASE,
            ADC_CYCLEHOLD_16_CYCLES,
            ADC_MULTIPLESAMPLESDISABLE);

    //Configure Memory Buffer
    /*
     * Base Address for the ADC Module
     * Use input A7
     * Use positive reference of AVcc
     * Use negative reference of AVss
     */
    MAP_ADC_configureMemory(ADC_BASE,
            ADC_INPUT_A7,
            ADC_VREFPOS_AVCC,
            ADC_VREFNEG_AVSS);

    MAP_ADC_clearInterrupt(ADC_BASE,
            ADC_COMPLETED_INTERRUPT);

    //Enable Memory Buffer interrupt
    MAP_ADC_enableInterrupt(ADC_BASE,
            ADC_COMPLETED_INTERRUPT);

    for (;;)
    {
        //Delay between conversions
        __delay_cycles(5000);

        //Enable and Start the conversion
        //in Single-Channel, Single Conversion Mode
        MAP_ADC_startConversion(ADC_BASE,
                ADC_SINGLECHANNEL);

        //LPM0, ADC10_ISR will force exit
        __bis_SR_register(CPUOFF + GIE);
        //For debug only
        __no_operation();


    }
}

//ADC10 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(ADC_VECTOR)))
#endif
void ADC_ISR (void)
{
    switch (__even_in_range(ADCIV,12)){
        case 0: break; //No interrupt
        case 2: break; //conversion result overflow
        case 4: break; //conversion time overflow
        case 6: break; //ADC10HI
        case 8: break; //ADC10LO
        case 10: break; //ADC10IN
        case 12:        //ADC10IFG0
                 //(Automatically clears ADC10IFG0 by reading memory buffer)
                 if (MAP_ADC_getResults(ADC_BASE) < 0x1FF){

                     //Turn LED1 off
                     MAP_GPIO_setOutputLowOnPin(
                             GPIO_PORT_LED1,
                             GPIO_PIN_LED1
                             );

                     //Turn LED2 off
                     MAP_GPIO_setOutputLowOnPin(
                             GPIO_PORT_LED2,
                             GPIO_PIN_LED2
                             );
                 }
                 else {
                     //Turn LED1 on
                     MAP_GPIO_setOutputHighOnPin(
                             GPIO_PORT_LED1,
                             GPIO_PIN_LED1
                             );

                     //Turn LED2 on
                     MAP_GPIO_setOutputHighOnPin(
                             GPIO_PORT_LED2,
                             GPIO_PIN_LED2
                             );
                 }

                 //Clear CPUOFF bit from 0(SR)
                 //Breakpoint here and watch ADC_Result
                 __bic_SR_register_on_exit(CPUOFF);
                 break;
        default: break;
    }
}