安装CCS9.2,SDK包。
https://e2echina.ti.com/question_answer/microcontrollers/msp430/f/55/t/179621
开ADC 和开1s定时器A中断:
// * --|RST P5.5 |<--- A0 (Analog Input)
// * | P1.0|-->LED
/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
/* Statics */
static volatile uint16_t curADCResult;
static volatile float normalizedADCRes;
/* Timer_A UpMode Configuration Parameter */
const Timer_A_UpModeConfig upConfig = {
TIMER_A_CLOCKSOURCE_ACLK, //aclk
TIMER_A_CLOCKSOURCE_DIVIDER_1, //32768hz
32768, // 1 s clock
TIMER_A_TAIE_INTERRUPT_DISABLE, // Disable Timer interrupt
TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE, // Enable CCR0 interrupt
TIMER_A_DO_CLEAR // Clear value
};
int main(void)
{
/* Halting the Watchdog */
MAP_WDT_A_holdTimer();
/* Initializing Variables */
curADCResult = 0;
/* Setting Flash wait state */
MAP_FlashCtl_setWaitState(FLASH_BANK0, 1);
MAP_FlashCtl_setWaitState(FLASH_BANK1, 1);
/* Setting DCO to 48MHz */
MAP_PCM_setPowerState(PCM_AM_LDO_VCORE1);
MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);
/* Enabling the FPU for floating point operation */
MAP_FPU_enableModule();
MAP_FPU_enableLazyStacking();
//![Single Sample Mode Configure]
/* Initializing ADC (MCLK/1/4) */
MAP_ADC14_enableModule();
MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_4,
0);
/* Configuring GPIOs (5.5 A0) */
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5,
GPIO_TERTIARY_MODULE_FUNCTION);
/* Configuring ADC Memory */
MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true);
MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS,
ADC_INPUT_A0,
false);
/* Configuring Sample Timer */
MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION);
/* Enabling/Toggling Conversion */
MAP_ADC14_enableConversion();
MAP_ADC14_toggleConversionTrigger();
//![Single Sample Mode Configure]
/* Enabling interrupts */
MAP_ADC14_enableInterrupt(ADC_INT0);
MAP_Interrupt_enableInterrupt(INT_ADC14);
/* Configuring Timer_A1 for Up Mode */
MAP_Timer_A_configureUpMode(TIMER_A1_BASE, &upConfig);
/* Enabling interrupts and starting the timer */
MAP_Interrupt_enableSleepOnIsrExit();
MAP_Interrupt_enableInterrupt(INT_TA1_0);
MAP_Timer_A_startCounter(TIMER_A1_BASE, TIMER_A_UP_MODE);
/* Configuring P1.0 as output */
MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
/* Enabling MASTER interrupts */
MAP_Interrupt_enableMaster();
while (1)
{
//MAP_PCM_gotoLPM0();
}
}
void ADC14_IRQHandler(void)
{
uint64_t status = MAP_ADC14_getEnabledInterruptStatus();
MAP_ADC14_clearInterruptFlag(status);
if (ADC_INT0 & status)
{
curADCResult = MAP_ADC14_getResult(ADC_MEM0);
normalizedADCRes = (curADCResult * 3.3) / 16384; //normalizedADCRes就是最后电压
MAP_ADC14_toggleConversionTrigger();
}
}
void TA1_0_IRQHandler(void)
{
MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
MAP_Timer_A_clearCaptureCompareInterrupt(TIMER_A1_BASE,TIMER_A_CAPTURECOMPARE_REGISTER_0);
}