[MSP432] MSP432固件库入门实验(点把火)

平湖秋月   2015-6-23 21:25 楼主
俺点把火希望大家跟进,坛友一起来学MSP432...
会AMR Cortex M4的坛友,看看MSP432手册,再看看其固件库函数,
一两天应该可以看懂MSP432的程序滴。。。。
* Description: Experiment with different MSP432 DCO clock frequencies
* DCO:
*      - Cycle through different DCO clock frequencies in active mode.
*      - A SysTick interval is configured to wake up & toggle the LED P1.0 output.
*      - Different LED toggling rate indicates a change in DCO clock frequency.
*      - Using MSP432 DriverLib built library (msp432p4xx_driverlib.lib)
*      - instead of using source like lab 1---功能
*
*
*
*                MSP432P401R
*             ------------------
*         /|\|                  |
*          | |                  |
*          --|RST         P1.0  |---> P1.0 LED闪烁灯
*            |                  |
*            |            P4.3  |---> MCLK [Optional]
*            |                  |
*            |            P1.1  |<--- Push Button
*
*   Dung Dang
*   Texas Instruments Inc.
*   April 2014
*   Built with Code Composer Studio V6.0
*******************************************************************************/
#include "msp432.h"
#include "driverlib.h"
uint32_t buttonPushed = 0, blink = 0, jj=0;
volatile uint32_t i;
uint32_t frequencyCycle[6] = {  CS_DCO_FREQUENCY_1_5, CS_DCO_FREQUENCY_3,
                                CS_DCO_FREQUENCY_6, CS_DCO_FREQUENCY_12,
                                CS_DCO_FREQUENCY_24, CS_DCO_FREQUENCY_48 };
int main(void)
{
    volatile uint32_t ii, curFrequency;
    WDT_A_holdTimer();                        // Hold watchdog timer
    PCM_setCoreVoltageLevel(PCM_VCORE1);
    FlashCtl_setWaitState(FLASH_BANK0, 2);
    FlashCtl_setWaitState(FLASH_BANK1, 2);
    GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P4,
            GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
    P4DIR |= BIT2 | BIT3;
    P4SEL0 |= BIT2 | BIT3;                         // Output ACLK & MCLK
    P4SEL1 &= ~(BIT2 | BIT3);
    P1DIR |= BIT0;
    /* Configuring P1.0 as output and P1.1 (switch) as input */
    GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
    /* Confinguring P1.1 as an input and enabling interrupts */
    GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
    GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1);
    GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1);
    GPIO_interruptEdgeSelect(GPIO_PORT_P1, GPIO_PIN1, GPIO_HIGH_TO_LOW_TRANSITION);
    Interrupt_enableInterrupt(INT_PORT1);
    SysTick_enableModule();
    SysTick_setPeriod(1500000);             // @ 1.5MHz, interrupt once per second
    SysTick_enableInterrupt();
    Interrupt_enableMaster();
    curFrequency = 0;
    /* Initialize MCLK to run from DCO with divider = 1*/
//    #error "Insert your code here to invoke MSP432 DriverLib API to initialize MCLK to be sourced by DCO / 1"
    CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);

    /* Set DCO calibrated center frequency to the option #0 from the frequencyCycle array
     * In other words, use the value frequencyCycle[0] */
    // Hint #1: frequencyCycle is an array with different DCO ranges
    // Hint #2: The API used to set the DCO to the calibrated center frequency is currently
    //          referred to as xxxxxxxxFrequencyRange.
//    #error "Insert MSP432DriverLib API call to set DCO Center Frequency to the 0th value in the frequencyCycle array"
    CS_setDCOCenteredFrequency (frequencyCycle[0]);
// frequencyCycle[0] = CS_DCO_FREQUENCY_1_5
    while (1)
    {
        /* Cycle through DCO frequencies */
        if (buttonPushed)
        {
            buttonPushed = 0;
            /* Set DCO center frequency to the option #curFrequency from the frequencyCycle array*/
//            #error "Insert MSP432DriverLib API call to set DCO Center Frequency to the value frequencyCycle[curFrequency]"
            CS_setDCOCenteredFrequency(frequencyCycle[curFrequency]);
            if (++curFrequency==6)
                curFrequency = 0;
            GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1);
        }
        PCM_setPowerState(PCM_LPM0_LDO_VCORE0);
        __no_operation();
    }
}
/* Port 1 ISR */
void Port1IsrHandler(void)
{
    uint32_t status;
    status = GPIO_getEnabledInterruptStatus(GPIO_PORT_P1);
    GPIO_clearInterruptFlag(GPIO_PORT_P1, status);
    //disable interrupt for a while
    GPIO_disableInterrupt(GPIO_PORT_P1, GPIO_PIN1);
    /* Toggling the output on the LED */
    buttonPushed = 1;
    /* Wake up from GPIO interrupt */
    Interrupt_disableSleepOnIsrExit();
}
/* SysTick ISr */
void SysTickIsrHandler(void)
{
    GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
}



回复评论 (13)

导入.out文件到launchpad开发板中 本帖最后由 平湖秋月 于 2015-6-23 21:36 编辑
  • 步骤.PNG
  • 导入.out文件.PNG
  • 运行.PNG
点赞  2015-6-23 21:31
引用: 平湖秋月 发表于 2015-6-23 21:31
导入.out文件到launchpad开发板中


  • 灭.PNG
  • 结果1.PNG
点赞  2015-6-23 21:51
实验1 /******************************************************************************* * MSP432 Power Lab - Cycle through available power states & measure power * * Description: The goal of the lab is to explore and use the power API to * exercise various power states available on the MSP432P401. * The program will start up in default mode PCM_AM_LDO_VCORE0. * Push button P1.1 can be used to cycle to the next power mode from the below. * P1.0 LED blinks to indicate the power state transition. * * In each power state, use EnergyTrace+ Tool to measure the energy consumption * of that power state. Document results across all 13 different states. * * * - \b PCM_AM_LDO_VCORE0, [Active Mode, LDO, VCORE0] * - \b PCM_AM_LDO_VCORE1, [Active Mode, LDO, VCORE1] * - \b PCM_AM_DCDC_VCORE0, [Active Mode, DCDC, VCORE0] * - \b PCM_AM_DCDC_VCORE1, [Active Mode, DCDC, VCORE1] * - \b PCM_AM_LPR_VCORE0, [Active Mode, Low Frequency, VCORE0] * - \b PCM_AM_LPR_VCORE1, [Active Mode, Low Frequency, VCORE1] * - \b PCM_LPM0_LDO_VCORE0, [LMP0, LDO, VCORE0] * - \b PCM_LPM0_LDO_VCORE1, [LMP0, LDO, VCORE1] * - \b PCM_LPM0_DCDC_VCORE0, [LMP0, DCDC, VCORE0] * - \b PCM_LPM0_DCDC_VCORE1, [LMP0, DCDC, VCORE1] * - \b PCM_LPM0_LPR_VCORE0, [LMP0, Low Frequency, VCORE0] * - \b PCM_LPM0_LPR_VCORE1, [LMP0, Low Frequency, VCORE1] * - \b PCM_LPM3, [LPM3] * - \b PCM_LPM35_VCORE0, [LPM3.5 VCORE 0] * * * Once Deep Sleep mode is entered, the next transition will start again with * PCM_AM0_LDO. * * * Power mode transition is accomplished using DriverLib API: PCM_setPowerState() * Other related APIs: PCM_setPowerMode(), PCM_gotoSleep(), PCM_gotoDeepSleep() * * * MSP432P401 * ------------------ * /|\| | * | | | * --|RST P1.1 |<--Toggle Switch * | | * | P1.0 |----> LED (red) * | | * | | * | | * * Dung Dang * Texas Instruments Inc. * April 2014 * Built with Code Composer Studio V6.0 *******************************************************************************/ #include "driverlib.h" /* Application Data */ volatile uint32_t curPowerState, ledState=0; volatile bool stateChange; volatile uint32_t ledBlinkCount, ledBlinkMax=0; #define NUMBER_OF_POWER_STATES 13 void InitializeDevice(void); int main(void) { /* Halting the Watchdog */ WDT_A_holdTimer(); InitializeDevice(); curPowerState=0; while (1) { /* If we have a state change request... */ if (stateChange) { Interrupt_disableMaster(); stateChange = false; Interrupt_enableMaster(); /* Step 1: Find the correct Power API to change power state * Step 2: Fill in different switch cases to change device to different power states * Step 3: Notice special clock handling for the Low-Power Run modes where MCLK * is restricted to <=128kHz * Hint: Comment out the #error line after adding your solution code */ switch (curPowerState) { case 0: PCM_setPowerState(PCM_AM_LDO_VCORE0); // Active Mode, LDO, VCORE0 break; case 1: PCM_setPowerState(PCM_AM_LDO_VCORE1); // Active Mode, LDO, VCORE1 break; case 2: PCM_setPowerState(PCM_AM_DCDC_VCORE0); // Active Mode, DCDC, VCORE0 break; case 3: PCM_setPowerState(PCM_AM_DCDC_VCORE1); // Active Mode, DCDC, VCORE1 break; case 4: /* Switch all clocks to low-frequency operation prior to LF operations */ CS_initClockSignal(CS_MCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_initClockSignal(CS_SMCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1); PCM_setPowerState(PCM_AM_LF_VCORE0); break; case 5: PCM_setPowerState(PCM_AM_LF_VCORE1); break; case 6: /* Switch back to using LDO regulator first before increasing the clocks */ PCM_setPowerState(PCM_AM_LDO_VCORE0); /* Switch clocks back to high-frequency operation */ CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); PCM_setPowerState(PCM_LPM0_LDO_VCORE0); break; case 7: PCM_setPowerState(PCM_LPM0_LDO_VCORE1); break; case 8: PCM_setPowerState(PCM_LPM0_DCDC_VCORE0); break; case 9: PCM_setPowerState(PCM_LPM0_DCDC_VCORE1); break; case 10: /* Switch all clocks to low-frequency operation prior to LF operations */ CS_initClockSignal(CS_MCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_initClockSignal(CS_SMCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1); PCM_setPowerState(PCM_LPM0_LF_VCORE0); break; case 11: PCM_setPowerState(PCM_LPM0_LF_VCORE1); break; case 12: /* Switch back to using LDO regulator first before increasing the clocks */ PCM_setPowerState(PCM_AM_LDO_VCORE0); /* Switch clocks back to high-frequency operation */ CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); PCM_setPowerState(PCM_LPM3); break; default: break; } } } } /* * Port 1 interrupt handler. This handler is called whenever the switch attached * to P1.1 is pressed. A status flag is set to signal for the main application * to change power states */ void Port1IsrHandler(void) { uint32_t status = GPIO_getEnabledInterruptStatus(GPIO_PORT_P1); GPIO_clearInterruptFlag(GPIO_PORT_P1, status); if (status & GPIO_PIN1) { Interrupt_disableInterrupt(INT_PORT1); if (curPowerState == 12) /*Power State is PCM_DSL[Deep Sleep Mode]*/ { curPowerState = 0; } else { curPowerState++; } ledBlinkMax = (curPowerState) * 2; ledBlinkCount = 0; if (++ledState==8) ledState = 1; P2OUT &= ~(0x07); Interrupt_enableInterrupt(INT_TA0_0); Timer_A_startCounter(TIMER_A0_MODULE,TIMER_A_UP_MODE); } } /* Flashes LED */ void Timer_AIsrHandler(void) { Timer_A_clearCaptureCompareInterrupt(TIMER_A0_MODULE, TIMER_A_CAPTURECOMPARE_REGISTER_0); if (ledBlinkMax>0) P2OUT ^= ledState; ledBlinkCount++; if ( (ledBlinkCount == ledBlinkMax) || (ledBlinkMax==0)) { stateChange = true; Timer_A_stopTimer(TIMER_A0_MODULE); Interrupt_disableInterrupt(INT_TA0_0); /* Re-enabling port pin interrupt */ GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1); Interrupt_enableInterrupt(INT_PORT1); } } void TerminateGPIO(void) { P1DIR = 0x00; P2DIR = 0x00; P3DIR = 0x00; P4DIR = 0x00; P5DIR = 0x00; P6DIR = 0x00; P7DIR = 0x00; P8DIR = 0x00; P9DIR = 0x00; P10DIR = 0x00; P1REN = 0xff; P2REN = 0xff; P3REN = 0xff; P4REN = 0xff; P5REN = 0xff; P6REN = 0xff; P7REN = 0xff; P8REN = 0xff; P9REN = 0xff; P10REN = 0xff; P1OUT = 0x00; P2OUT = 0x00; P3OUT = 0x00; P4OUT = 0x00; P5OUT = 0x00; P6OUT = 0x00; P7OUT = 0x00; P8OUT = 0x00; P9OUT = 0x00; P10OUT = 0x00; PSS_setHighSidePerformanceMode(PSS_NORMAL_PERFORMANCE_MODE); //PSS_setLowSidePerformanceMode(PSS_NORMAL_PERFORMANCE_MODE); PCM_enableRudeMode(); } void InitializeDevice(void) { /* TimerA UpMode Configuration Parameter */ Timer_A_UpModeConfig upConfig = { TIMER_A_CLOCKSOURCE_ACLK, // SMCLK Clock SOurce TIMER_A_CLOCKSOURCE_DIVIDER_1, // SCLK/1 = 3MHz 16000, // 50000 tick period TIMER_A_TAIE_INTERRUPT_DISABLE, // Disable Timer interrupt TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE , // Enable CCR0 interrupt TIMER_A_SKIP_CLEAR // Clear value }; Interrupt_disableMaster(); TerminateGPIO(); /* Initializing Variables */ curPowerState = 0; stateChange = false; ledBlinkCount = 0; /* Setting the Reference Oscillator to 128KHz. For Low Power Run modes, the * MCLK frequency is required to be scaled back to 128KHz. */ CS_setReferenceOscillatorFrequency(CS_REFO_128KHZ); /* Setting up TimerA to be sourced from ACLK and for ACLK to be sourced from * the 128Khz REFO. Since the frequency of MCLK will be changed when we go * into LPR mode, we want to make our LED blink look consistent. */ CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1); Timer_A_configureUpMode(TIMER_A0_MODULE, &upConfig); Timer_A_enableCaptureCompareInterrupt(TIMER_A0_MODULE, TIMER_A_CAPTURECOMPARE_REGISTER_0); /* Configuring P2 as output and P1.1 (switch) as input */ GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 ); /* Confinguring P1.1 as an input and enabling interrupts */ GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1); GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1); GPIO_interruptEdgeSelect(GPIO_PORT_P1, GPIO_PIN1, GPIO_HIGH_TO_LOW_TRANSITION); Interrupt_enableInterrupt(INT_PORT1); Interrupt_disableSleepOnIsrExit(); SysCtl_enableSRAMBankRetention(SYSCTL_SRAM_BANK7); Interrupt_enableMaster(); } 本帖最后由 平湖秋月 于 2015-6-23 23:23 编辑
点赞  2015-6-23 23:10
引用: 平湖秋月 发表于 2015-6-23 23:10 /******************************************************************************* * MSP432 Power ...
本帖最后由 平湖秋月 于 2015-6-23 23:20 编辑
  • 1.PNG
点赞  2015-6-23 23:15
给力  手头有432的朋友 行动起来吧
加油!在电子行业默默贡献自己的力量!:)
点赞  2015-6-24 09:15
文档的排版要优化呀
点赞  2015-6-25 23:36
固件库哪里下载的,之前没用过TI的MCU
点赞  2016-1-27 09:10
楼主,你好!固件库函数在哪里下载的?能分享一下吗?谢谢!
点赞  2016-10-9 16:23
固件库是什么东西?怎么用
点赞  2016-12-15 11:42
引用: yifenghao 发表于 2016-10-9 16:23
楼主,你好!固件库函数在哪里下载的?能分享一下吗?谢谢!

有固件库函数介绍手册吗
点赞  2017-2-14 16:53
楼主有固件库函数介绍手册吗
点赞  2017-2-14 16:53
MSP432的功耗确实低,做仪表是非常合适的
做适合中国宝贝的教育机器人
点赞  2017-2-28 08:53
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复