Hi all
我在做一个项目,需要用到RTC的低功耗模式 ,但我实测发现上电后的功耗是0.4uA,但执行完第一次中断程序后,之后不管进入多少次中断,进入RTC低功耗模式都是12.6uA。我试过和定时时间没关系,第一次中断前都是0.4uA。请问是我需要在每次再次进入低功耗时都需要重新配置下RTC吗?
// MSP430FR413x Demo - RTC, device enter LPM3.5 and toggle P1.0 in RTC interrupt handling every 1s
//
//
// Description: Device enter LPM3.5 after configuring the RTC. The RTC wakes
// the device up from LPM3.5 every second and toggles P1.0.
// It also stores the state of P0OUT in the Backup RAM Registers.
//
// ACLK = XT1 = 32kHz, MCLK = SMCLK = default DCODIV = ~1MHz.
//
// MSP430FR4133
// -----------------
// /|\| |
// | | |
// | | XIN(P4.1)|--
// --|RST | ~32768Hz
// | XOUT(P4.2)|--
// | |
// | P4.5|-->LED
//
// Wei Zhao
// Texas Instruments Inc.
// March 2015
// Built with IAR Embedded Workbench v6.20 & Code Composer Studio v6.1
//******************************************************************************
#include <msp430.h>
void initGpio(void);
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
initGpio(); // Configure GPIO
// Initialize XT1 32kHz crystal
P4SEL0 |= BIT1 | BIT2; // set XT1 pin as second function
do
{
CSCTL7 &= ~(XT1OFFG | DCOFFG); // Clear XT1 and DCO fault flag
SFRIFG1 &= ~OFIFG;
} while (SFRIFG1 & OFIFG); // Test oscillator fault flag
// First determine whether we are coming out of an LPMx.5 or a regular RESET.
if (SYSRSTIV == SYSRSTIV_LPM5WU) // When woken up from LPM3.5, reinit
{
// If MCU wakes up from LPM3.5, re-init and then return to LPM3.5 again.
// Restore P1OUT value from backup RAM memory, keep P1OUT after LPMx.5 reset
P4OUT = *(unsigned int *)BKMEM_BASE;
__enable_interrupt(); // The RTC interrupt should trigger now...
}
else
{
// Device powered up from a cold start.
// It configures the device and puts the device into LPM3.5
// Configure backup memory
*(unsigned int *)BKMEM_BASE = 0;
// Initialize RTC
// Interrupt and reset happen every 1024/32768 * 32 = 1 sec.
RTCMOD = 960-1;
RTCCTL = RTCSS__XT1CLK | RTCSR | RTCPS__1024 | RTCIE;
// Store P1OUT value in backup memory register before enter LPM3.5
*(unsigned int *)BKMEM_BASE = P4OUT;
}
// Enter LPM3.5 mode with interrupts enabled. Note that this operation does
// not return. The LPM3.5 will exit through a RESET event, resulting in a
// re-start of the code.
PMMCTL0_H = PMMPW_H; // Open PMM Registers for write
PMMCTL0_L |= PMMREGOFF; // and set PMMREGOFF
__bis_SR_register(LPM3_bits | GIE);
__no_operation();
return 0;
}
void initGpio(void)
{
P1DIR |= 0x1F;
P2DIR |= 0xFF;
P3DIR |= 0xFF;
P4DIR |= 0xFF;
P5DIR |= 0xFF;
P6DIR |= 0xFF;
P7DIR |= 0xFF;
P8DIR |= 0xFD;
P1OUT |= 0x1F;
P2OUT |= 0xFF;
P3OUT |= 0xFF;
P3OUT &= ~0x87;
P4OUT |= 0xFF;
P5OUT |= 0xFF;
P6OUT |= 0xFF;
P7OUT |= 0xFF;
P8OUT |= 0xFD;
P8DIR &= ~0x02;
P8REN &= ~0x02;
//Motor P1.6 1.7 1.5
P1DIR &= ~0xE0;
P1REN &= ~0xE0;
P2DIR &= ~0xF3;
P2REN &= ~0xF3;
// Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = RTC_VECTOR
__interrupt void RTC_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(RTC_VECTOR))) RTC_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(RTCIV, RTCIV_RTCIF))
{
case RTCIV_NONE : break; // No interrupt pending
case RTCIV_RTCIF: // RTC Overflow
// Toggle LED on P1.0
P4OUT ^= BIT5;
// Store P1OUT value in backup memory register
*(unsigned int *)BKMEM_BASE = P4OUT;
__bis_SR_register(LPM3_bits | GIE);
break;
default: break;
}
}