俺点把火希望大家跟进,坛友一起来学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);
}