楼主准备参见今年的电赛,选题方向呢是有关电源类的,往年一直用5529,今年入手了MSP432,就准备选这款做主控了,经过几天努力,准备好了代码,现在来和大家分享下
楼主一向习惯用库函数,这次当然也不例外啦,首先打开CCS的MSPWARE,新建一个工程
在此基础上我们可以一步步移植库函数的例子,首先呢就从时钟系统开始吧,感兴趣的同志们去研读下芯片手册,432的时钟系统叫CS,
吓了一跳当时也是,首先看这两个例子,clock_Init和HFxt_start
我们可以看到这两段代码:
int main(void)
{
/* Halting the Watchdog */
MAP_WDT_A_holdTimer();
/* Configuring pins for peripheral/crystal usage and LED for output */
MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ,
GPIO_PIN3 | GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION);
MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
/* Setting the external clock frequency. This API is optional, but will
* come in handy if the user ever wants to use the getMCLK/getACLK/etc
* functions
*/
CS_setExternalClockSourceFrequency(32000,48000000);
/* Starting HFXT in non-bypass mode without a timeout. Before we start
* we have to change VCORE to 1 to support the 48MHz frequency */
MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);
MAP_FlashCtl_setWaitState(FLASH_BANK0, 2);
MAP_FlashCtl_setWaitState(FLASH_BANK1, 2);
CS_startHFXT(false);
/* Initializing MCLK to HFXT (effectively 48MHz) */
MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
/* Configuring SysTick to trigger at 24000000 (MCLK is 48MHz so this will
* make it toggle every 0.5s) */
MAP_SysTick_enableModule();
MAP_SysTick_setPeriod(24000000);
MAP_Interrupt_enableSleepOnIsrExit();
MAP_SysTick_enableInterrupt();
/* Enabling MASTER interrupts */
MAP_Interrupt_enableMaster();
while (1)
{
MAP_PCM_gotoLPM0();
}
}
void systick_isr(void)
{
MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
}
和
int main(void)
{
/* Halting WDT */
MAP_WDT_A_holdTimer();
/* Initializing the clock source as follows:
* MCLK = MODOSC/4 = 6MHz
* ACLK = REFO/2 = 16kHz
* HSMCLK = DCO/2 = 1.5Mhz
* SMCLK = DCO/4 = 750kHz
* BCLK = REFO = 32kHz
*/
MAP_CS_initClockSignal(CS_MCLK, CS_MODOSC_SELECT, CS_CLOCK_DIVIDER_4);
MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_2);
MAP_CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2);
MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_4);
MAP_CS_initClockSignal(CS_BCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
/*
* Getting all of the frequency values of the CLK sources using the
* convenience functions */
aclk = CS_getACLK();
mclk = CS_getMCLK();
smclk = CS_getSMCLK();
hsmclk = CS_getHSMCLK();
bclk = CS_getBCLK();
/*
* Staying in active mode so that the user can see the values that are put
* in the above registers through the debugger
*/
while (1)
{
}
}
类似的呢我们可以完成ADC,TIMER,SYSTICK,等的配置,我就不一一说明啦,这里附上自己的成品,加上一个PI算法控制输出电压恒定的代码,大家今年电赛加油啊,有什么问题的直接回复好啦
需要注意的是,432的库函数的中断要在这个文件中修改中断表才可以写自己的中断函数
给楼主献上膝盖了,对了,想问一下楼主这个维持电压恒定的硬件电路咋搭的