俺点把火希望大家跟进,坛友一起来学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);
}
/*******************************************************************************
* MSP432 Power Lab - Cycle through available power states & measure power
*
* Description: The goal of the lab is
详情回复
发表于 2015-6-23 23:10
实验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"
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;
/* 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);