我最近使用MSP430F5418发现即使程序刚开始运行就进入LPM3,我三伏的供电也耗电300多uA。 程序就是找到的一个例子如下:
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR = 0xFF; P2DIR = 0xFF; P3DIR = 0xFF; P4DIR = 0xFF; P5DIR = 0xFF;
P6IR = 0xFF; P7DIR = 0xFF;P8DIR = 0xFF;P9DIR = 0xFF;P10DIR = 0xFF;P11DIR = 0xFF;
P1OUT = 0x00;P2OUT = 0x00;P3OUT = 0x00;P4OUT = 0x00;P5OUT = 0x00;P6OUT = 0x00; P7OUT = 0x00;P8OUT = 0x00;P9OUT = 0x00;P10OUT = 0x00;P11OUT = 0x00;
LPM3; // Enter LPM3
while (1);
}
这是为什么呢?
具体看数据手册中,看看LPM3下,不同条件下的测试的电流
对不起。上次我的程序没有说全。我在进入LPM3之前还初始化了定时器A和两个串口。今天我又捣鼓了一下。发现如果不初始化定时器A和两个串口,LPM3的电流消耗是6.5个uA。虽然还没有达到资料上说的2uA,但已经很不错了。至于在进入LPM3之前如何设置定时器A和两个串口才能保持不大于6.5个uA的功耗还在继续探讨。
重大发现
要想实现真正意思上的低功耗在进入LPM3之前应当关闭所有已经打开的功能模块。比如串口,定时器,AD等。再就是要把所有I/O的特殊功能关闭,设置成输出,输出值为低。否则是不会达到说明书上所给的低功耗指标。比如LPM3电流2uA。我在初始化时使用了定时器A, AD12, 两个串口。为了保持MSP430F5418的RTC在纽扣电池供电时继续工作。在进入LPM3前我是这样做的:
void turnOFF()
{
TA1CTL = 0; // stop TimerA
ADC12CTL0 = 0; // stop ADC12
UCA0CTL1 |= UCSWRST;
UCA1CTL1 |= UCSWRST;
P1SEL = P2SEL = P3SEL = P4SEL = P5SEL = P6SEL = P7SEL = P8SEL = P9SEL = P10SEL = P11SEL = 0;
P1DS = P2DS = P3DS = P4DS = P5DS = P6DS = P7DS = P8DS = P9DS = P10DS = P11DS = 0;
P1DIR = P2DIR = P3DIR = P4DIR = P5DIR = P6DIR = P7DIR = P8DIR = P9DIR = P10DIR = P11DIR = 0xFF;
P1OUT = P2OUT = P3OUT = P4OUT = P5OUT = P6OUT = P7OUT = P8OUT = P9OUT = P10OUT = P11OUT = 0x00;
P1DIR &= ~BIT4; //P1.4 input pin
P1IE |= BIT4; //P1.4 interrupt ena××e
P1IES &= ~BIT4; //P1.4 low-to-high edge
LPM3; //MSP430F5418 standby
}
经测量。此时单片机在3V钮扣电池供电的情况下为6个uA