MSP430F5438A单片机低功耗设置,以进入LPM3为例:
1、MSP430F5438A外部时钟分别为8M和32.768,程序正常运行时选择8M主时钟,当程序需要进入低功耗时,需要将主时钟切换为32.768,代码如下(自己试着改的。。)
void InitClock()
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
//P11DIR |= 0x07; // ACLK, MCLK, SMCLK set out to pins
//P11SEL |= 0x07; // P11.0,1,2 for debugging purposes.
__bis_SR_register(SCG0); // Disable the FLL control loop +OSCOFF
// Initialize LFXT1 ,XT2
// P5SEL |= 0x0C; // Port select XT2
P7SEL |= 0x03; // Port select XT1
// UCSCTL6 &= ~(XT1OFF + XT2OFF); // Set XT1 & XT2 On
UCSCTL6 &= ~(XT1OFF);
UCSCTL6 |= XCAP_3; // Internal load cap
// Loop until XT1,XT2 & DCO fault flag is cleared
do
{
UCSCTL7 &= ~(XT1LFOFFG + XT1HFOFFG + DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
}while (SFRIFG1 & OFIFG); // Test oscillator fault flag
UCSCTL6 &= ~XT2DRIVE0; // Decrease XT2 Drive according to
// expected frequency
//UCSCTL5 |= DIVS_0; // SMCLK/1=8Mhz
//UCSCTL4 |= SELS_5 + SELM_5+SELA__XT1CLK; // SMCLK=MCLK=XT2=8Mhz
UCSCTL4 |= SELS__XT1CLK + SELM__XT1CLK+SELA__XT1CLK; // SMCLK=MCLK=XT2=8Mhz
UCSCTL6 |= (XT1OFF);
P5SEL &= ~0x0C;
P5DIR|=0X0C;P5OUT&=~0X0C;
delay(50);
}
void InitClockgs()
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
//P11DIR |= 0x07; // ACLK, MCLK, SMCLK set out to pins
//P11SEL |= 0x07; // P11.0,1,2 for debugging purposes.
__bis_SR_register(SCG0); // Disable the FLL control loop +OSCOFF
// Initialize LFXT1 ,XT2
P5SEL |= 0x0C; // Port select XT2
P7SEL |= 0x03; // Port select XT1
UCSCTL6 &= ~(XT1OFF + XT2OFF); // Set XT1 & XT2 On
//UCSCTL6 &= ~(XT1OFF);
UCSCTL6 |= XCAP_3; // Internal load cap
// Loop until XT1,XT2 & DCO fault flag is cleared
do
{
UCSCTL7 &= ~(XT2OFFG +XT1LFOFFG + XT1HFOFFG + DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
}while (SFRIFG1 & OFIFG); // Test oscillator fault flag
UCSCTL6 &= ~XT2DRIVE1; // Decrease XT2 Drive according to
// expected frequency
UCSCTL5 |= DIVS_0; // SMCLK/1=8Mhz
UCSCTL4 |= SELS_5 + SELM_5+SELA__XT1CLK; // SMCLK=MCLK=XT2=8Mhz
// UCSCTL4 |= SELS__XT1CLK + SELM__XT1CLK+SELA__XT1CLK; // SMCLK=MCLK=XT2=8Mhz
delay(50);
}
2、进入低功耗之前,需要设置所有的IO引脚为固定的输入输出状态,引脚的不确定状态会增加单片机的功耗;
3、如果引脚连接有相关外设,比如上拉电阻,进入低功耗之前,引脚状态应该设置输出、高;如果是下拉电阻,则设置为输出低,可以hi降低一部分功耗;如果引脚用控制某些设备的电源开关,要先将其关掉(如果允许);
4、单片机片上外设进入低功耗之前也需要先将其关掉,如串口:进入低功耗之前,需要先将其引脚设置为输出低和关闭串口功能;
5、程序唤醒用的定时器时钟选择32.768低速时钟,当定时时间到时,定时器中断中唤醒单片机进入正常运行状态;
实测,两节干电池供电,不经过LDO,4UA电流。
一点总结,不对处多交流。
|