This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi All,
I have a similar problem, that was in e2e.ti.com/.../1728640 post, but my RTC don't reset after power off - it stop and continue after power on.
I connect 3V battering to AUXVCC3 pin via diode. I try to transfer code to LPM3.5 before power off, but it not work.
I found good example, that realy work on my device -
void main (void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT AUX3CHCTL = AUXCHKEY | AUXCHC_1 | AUXCHV_1 | AUXCHEN; // Enable Charger for AUX3 to enable RTC if (SYSRSTIV == SYSRSTIV_LPM5WU) { // When woken up from LPM3.5, reinit since LPMx.5 will cause a BOR. PMMCTL0_H = PMMPW_H; // open PMM PM5CTL0 &= ~LOCKIO; // Clear LOCKBAK and enable ports PMMCTL0_H = 0x00; // close PMM } // Initialize LFXT1 UCSCTL6 &= ~(XT1OFF); // Enable XT1 UCSCTL6 |= XCAP_3; // Internal load cap // Loop until XT1, XT2 & DCO fault flag is cleared do { UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG); // Clear XT2,XT1,DCO fault flags SFRIFG1 &= ~OFIFG; // Clear fault flags } while (SFRIFG1 & OFIFG); // Test oscillator fault flag // Configure RTC_C RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module RTCCTL1 |= RTCHOLD; // BCD mode, RTC hold, Set RTCTEV for 1 minute alarm // event interrupt RTCYEAR = 2016; // Year = 0x2011 RTCMON = 10; // Month = 0x10 = October RTCDAY = 07; // Day = 0x07 = 7th RTCDOW = 05; // Day of week = 0x05 = Friday RTCHOUR = 11; // Hour = 0x11 RTCMIN = 27; // Minute = 0x59 RTCSEC = 00; // Seconds = 0x45 RTCCTL1 &= ~(RTCHOLD); // Start RTC calendar mode RTCCTL0_H = 0; // Enter LPM3.5 UCSCTL6 |= XT1OFF; // Turn off clock for LPMx.5 operation. ACLK will still // remain active PMMCTL0_H = PMMPW_H; // Open PMM Registers for write PMMCTL0_L |= PMMREGOFF; // and set PMMREGOFF __disable_interrupt(); __bis_SR_register(LPM4_bits); // Enter LPM3.5 mode with interrupts enabled __no_operation(); // Code should NOT get here. This means that LPM3.5 was not properly entered. // Ensure that an external power supply was ued. Or else JTAG will put the CPU // in LPM0 mode. // Stop the RTC RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module RTCCTL1 |= RTCHOLD; // RTC hold RTCCTL0_H = 0; // Lock RTC_C module while(1) { __delay_cycles(1000); // Delay } }
In this example RTC continue count after power off, but if I add(for example) some initialization of somethig(for example TimerA3) I'll get old problem
void main (void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
AUX3CHCTL = AUXCHKEY | AUXCHC_1 | AUXCHV_1 | AUXCHEN; // Enable Charger for AUX3 to enable RTC
if (SYSRSTIV == SYSRSTIV_LPM5WU)
{
// When woken up from LPM3.5, reinit since LPMx.5 will cause a BOR.
PMMCTL0_H = PMMPW_H; // open PMM
PM5CTL0 &= ~LOCKIO; // Clear LOCKBAK and enable ports
PMMCTL0_H = 0x00; // close PMM
}
// Initialize LFXT1
UCSCTL6 &= ~(XT1OFF); // Enable XT1
UCSCTL6 |= XCAP_3; // Internal load cap
// Loop until XT1, XT2 & DCO fault flag is cleared
do
{
UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
} while (SFRIFG1 & OFIFG); // Test oscillator fault flag
// Configure RTC_C
RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module
RTCCTL1 |= RTCHOLD; // BCD mode, RTC hold, Set RTCTEV for 1 minute alarm
// event interrupt
RTCYEAR = 2016; // Year = 0x2011
RTCMON = 10; // Month = 0x10 = October
RTCDAY = 07; // Day = 0x07 = 7th
RTCDOW = 05; // Day of week = 0x05 = Friday
RTCHOUR = 11; // Hour = 0x11
RTCMIN = 27; // Minute = 0x59
RTCSEC = 00; // Seconds = 0x45
RTCCTL1 &= ~(RTCHOLD); // Start RTC calendar mode
RTCCTL0_H = 0;
TA3CTL = TASSEL_2 | MC_2 | TACLR;
// Enter LPM3.5
UCSCTL6 |= XT1OFF; // Turn off clock for LPMx.5 operation. ACLK will still
// remain active
PMMCTL0_H = PMMPW_H; // Open PMM Registers for write
PMMCTL0_L |= PMMREGOFF; // and set PMMREGOFF
__disable_interrupt();
__bis_SR_register(LPM4_bits); // Enter LPM3.5 mode with interrupts enabled
__no_operation();
// Code should NOT get here. This means that LPM3.5 was not properly entered.
// Ensure that an external power supply was ued. Or else JTAG will put the CPU
// in LPM0 mode.
// Stop the RTC
RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module
RTCCTL1 |= RTCHOLD; // RTC hold
RTCCTL0_H = 0; // Lock RTC_C module
while(1)
{
__delay_cycles(1000); // Delay
}
}
Who knows why this is happening? Thanks
Hi Ryan, thank for reply
I know that TA3 will not work in LPM 3.5, I init it only for example. I try to init comparator_B, TA0, TA2 and get non-working RTC after power off. This programm is example from ti.com site with some corrections ( ) and it's works, but if I want to add some code RTC is breaks.
If you're interesting how I check RTC working look at this code-
#include <msp430.h> void main (void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT AUX3CHCTL = AUXCHKEY | AUXCHC_1 | AUXCHV_1 | AUXCHEN; // Enable Charger for AUX3 to enable RTC if (SYSRSTIV == SYSRSTIV_LPM5WU) { // When woken up from LPM3.5, reinit since LPMx.5 will cause a BOR. PMMCTL0_H = PMMPW_H; // open PMM PM5CTL0 &= ~LOCKIO; // Clear LOCKBAK and enable ports PMMCTL0_H = 0x00; // close PMM } // Initialize LFXT1 UCSCTL6 &= ~(XT1OFF); // Enable XT1 UCSCTL6 |= XCAP_3; // Internal load cap // Loop until XT1, XT2 & DCO fault flag is cleared do { UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG); // Clear XT2,XT1,DCO fault flags SFRIFG1 &= ~OFIFG; // Clear fault flags } while (SFRIFG1 & OFIFG); // Test oscillator fault flag if (RTCMIN > 27) { // Configure RTC_C RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module RTCCTL0_L |= RTCTEVIE; // Enable RTC time event interrupt RTCCTL1 |= RTCHOLD; // BCD mode, RTC hold, Set RTCTEV for 1 minute alarm // event interrupt RTCYEAR = 2016; // Year = 0x2011 RTCMON = 10; // Month = 0x10 = October RTCDAY = 07; // Day = 0x07 = 7th RTCDOW = 05; // Day of week = 0x05 = Friday RTCHOUR = 11; // Hour = 0x11 RTCMIN = 27; // Minute = 0x59 RTCSEC = 45; // Seconds = 0x45 RTCCTL1 &= ~(RTCHOLD); // Start RTC calendar mode RTCCTL0_H = 0; P2DIR |= BIT4; while(1) { P2OUT ^= BIT4; __delay_cycles(1000); } } // Configure RTC_C RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module RTCCTL0_L |= RTCTEVIE; // Enable RTC time event interrupt RTCCTL1 |= RTCHOLD; // BCD mode, RTC hold, Set RTCTEV for 1 minute alarm // event interrupt RTCYEAR = 2016; // Year = 0x2011 RTCMON = 10; // Month = 0x10 = October RTCDAY = 07; // Day = 0x07 = 7th RTCDOW = 05; // Day of week = 0x05 = Friday RTCHOUR = 11; // Hour = 0x11 RTCMIN = 27; // Minute = 0x59 RTCSEC = 45; // Seconds = 0x45 RTCCTL1 &= ~(RTCHOLD); // Start RTC calendar mode RTCCTL0_H = 0; // Enter LPM3.5 UCSCTL6 |= XT1OFF; // Turn off clock for LPMx.5 operation. ACLK will still // remain active PMMCTL0_H = PMMPW_H; // Open PMM Registers for write PMMCTL0_L |= PMMREGOFF; // and set PMMREGOFF __disable_interrupt(); __bis_SR_register(LPM4_bits); // Enter LPM3.5 mode with interrupts enabled __no_operation(); // Code should NOT get here. This means that LPM3.5 was not properly entered. // Ensure that an external power supply was ued. Or else JTAG will put the CPU // in LPM0 mode. // Stop the RTC RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module RTCCTL1 |= RTCHOLD; // RTC hold RTCCTL0_H = 0; // Lock RTC_C module while(1) { __delay_cycles(1000); // Delay } } #pragma vector=RTC_VECTOR __interrupt void rtc_isr(void) { switch (__even_in_range(RTCIV, 16)) { case RTCIV_NONE: // No interrupts break; case RTCIV_RTCOFIFG: // RTCOFIFG break; case RTCIV_RTCRDYIFG: // RTCRDYIFG break; case RTCIV_RTCTEVIFG: // RTCEVIFG break; case RTCIV_RTCAIFG: // RTCAIFG break; case RTCIV_RT0PSIFG: // RT0PSIFG break; case RTCIV_RT1PSIFG: // RT1PSIFG break; // case 14: break; // Reserved case 16: break; // Reserved default: break; } }
I turn on device and check PWM on p2.4. At first start I set 27 minutes and 45 second, then I power cut off and wait 20 second and turn on device again, if I have PWM on p2.4 - RTC is work. And it work before I add some initialization in code
Hi Andrei Zaitsau,
Its great to know that your code working.
From above code which is not working properly, I found some points and would like to focus on it.
1. You will find RTC value as per setting after power off and on, that means your RTC and Crystal block is working and H/W part is perfect.
2. Actually your RTC is Increment the values but, (from your code) You are initialize RTC again at time of Power On and reset the values (Minute =27) (Please check for 5 minutes put your board On then off for 5 minutes then power On and check value If minute = 27 then I am right).
So you need to change it in your code to initialize values of RTC register at once then rest of time only initialize only RTC (without changing the registers value)
I hope it will work.
Regards
Bhavdipsinh
Dear Bhavdipsinh, I think that you read my post not attentively. I can delete initialization of RTC as you advise to me, but it useless. Problem is that RTC stop increment after add some initialization code to my programm. After adding some initialization of something(I test with Timer_A initialization) RTC stop increment after power cut off. If I will not find reason of this problem I want to change msp430f67791 to msp430f67791A or to msp430f6779A in future, I think that it MCU problem
Hi Andrei Zaitsau (4197185)
will you provide result of below condition. I would like to go step by.
" (Please check for 5 minutes put your board On then off for 5 minutes then power On and check value If minute = 27 then I am right)."
Also "If(Minute >27) condition makes reset the values of your RTC parameters values.
Thanks
Bhavdipsinh
Ok, there is result of your advise. I modified programm, I delete
if (RTCMIN > 27) { // Configure RTC_C RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module RTCCTL0_L |= RTCTEVIE; // Enable RTC time event interrupt RTCCTL1 |= RTCHOLD; // BCD mode, RTC hold, Set RTCTEV for 1 minute alarm // event interrupt RTCYEAR = 2016; // Year = 0x2011 RTCMON = 10; // Month = 0x10 = October RTCDAY = 07; // Day = 0x07 = 7th RTCDOW = 05; // Day of week = 0x05 = Friday RTCHOUR = 11; // Hour = 0x11 RTCMIN = 27; // Minute = 0x59 RTCSEC = 45; // Seconds = 0x45 RTCCTL1 &= ~(RTCHOLD); // Start RTC calendar mode RTCCTL0_H = 0; P2DIR |= BIT4; while(1) { P2OUT ^= BIT4; __delay_cycles(1000); } }
and now I have only
// Configure RTC_C RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module RTCCTL1 = RTCMODE + RTCHOLD; // event interrupt RTCYEAR = 2016; // Year = 0x2011 RTCMON = 10; // Month = 0x10 = October RTCDAY = 07; // Day = 0x07 = 7th RTCDOW = 05; // Day of week = 0x05 = Friday RTCHOUR = 11; // Hour = 0x11 RTCMIN = 27; // Minute = 0x59 RTCSEC = 30; // Seconds = 0x45 RTCCTL1 &= ~(RTCHOLD); // Start RTC calendar mode RTCCTL0_H = 0;
on start up programm. And now I make steps, that you told me to do.
I power On device(set 27 minutes) and wait 5 minutes(32 minutes), then power Off device and wait 5 minutes(37 minutes). Before power On I connect MSP FET430UIF to my device and set break point at first line and look at RTC registers -> I saw RTCMIN==37, OK!
But then I add this line before RTC init
TA0CTL = TASSEL_2 | MC_1 | TACLR; // SMCLK, up mode, clear TAR
for example and do again previous steps. Now I see RTCMIN==32.
I tried many kinds of RTC initialization (add RTC events, enable GIE and oth.), but always got this result
thanks for your information.
Sorry, I didnt get your microcontroller number, Please share it with your full code, I will check it and reply.
Regards
Bhavdipsinh
Thank you for reply,
my MCU is MSP430F67791IPZ -
#include <msp430.h> void main (void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT AUX3CHCTL = AUXCHKEY | AUXCHC_1 | AUXCHV_1 | AUXCHEN; // Enable Charger for AUX3 to enable RTC if (SYSRSTIV == SYSRSTIV_LPM5WU) { // When woken up from LPM3.5, reinit since LPMx.5 will cause a BOR. PMMCTL0_H = PMMPW_H; // open PMM PM5CTL0 &= ~LOCKIO; // Clear LOCKBAK and enable ports PMMCTL0_H = 0x00; // close PMM } // Initialize LFXT1 UCSCTL6 &= ~(XT1OFF); // Enable XT1 UCSCTL6 |= XCAP_3; // Internal load cap // Loop until XT1, XT2 & DCO fault flag is cleared do { UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG); // Clear XT2,XT1,DCO fault flags SFRIFG1 &= ~OFIFG; // Clear fault flags } while (SFRIFG1 & OFIFG); // Test oscillator fault flag //TA0CTL = TASSEL_2 | MC_1 | TACLR; // SMCLK, up mode, clear TAR // Configure RTC_C RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module RTCCTL1 = RTCMODE + RTCHOLD; // event interrupt RTCYEAR = 2016; // Year = 0x2011 RTCMON = 10; // Month = 0x10 = October RTCDAY = 07; // Day = 0x07 = 7th RTCDOW = 05; // Day of week = 0x05 = Friday RTCHOUR = 11; // Hour = 0x11 RTCMIN = 27; // Minute = 0x59 RTCSEC = 30; // Seconds = 0x45 RTCCTL1 &= ~(RTCHOLD); // Start RTC calendar mode RTCCTL0_H = 0; // Enter LPM3.5 UCSCTL6 |= XT1OFF; // Turn off clock for LPMx.5 operation. ACLK will still // remain active PMMCTL0_H = PMMPW_H; // Open PMM Registers for write PMMCTL0_L |= PMMREGOFF; // and set PMMREGOFF __disable_interrupt(); __bis_SR_register(LPM4_bits); // Enter LPM3.5 mode with interrupts enabled __no_operation(); // Code should NOT get here. This means that LPM3.5 was not properly entered. // Ensure that an external power supply was ued. Or else JTAG will put the CPU // in LPM0 mode. // Stop the RTC RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module RTCCTL1 |= RTCHOLD; // RTC hold RTCCTL0_H = 0; // Lock RTC_C module while (1) { __delay_cycles(1000); // Delay } } #pragma vector=RTC_VECTOR __interrupt void rtc_isr(void) { switch (__even_in_range(RTCIV, 16)) { case RTCIV_NONE: // No interrupts break; case RTCIV_RTCOFIFG: // RTCOFIFG break; case RTCIV_RTCRDYIFG: // RTCRDYIFG break; case RTCIV_RTCTEVIFG: // RTCEVIFG break; case RTCIV_RTCAIFG: // RTCAIFG break; case RTCIV_RT0PSIFG: // RT0PSIFG break; case RTCIV_RT1PSIFG: // RT1PSIFG break; // case 14: break; // Reserved case 16: break; // Reserved default: break; } }
#include <msp430.h> void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop WTD // Initialize LFXT1 UCSCTL6 &= ~(XT1OFF); // Enable XT1 UCSCTL6 |= XCAP_3; // Internal load cap // Loop until XT1, XT2 & DCO fault flag is cleared do { UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG); // Clear XT2,XT1,DCO fault flags SFRIFG1 &= ~OFIFG; // Clear fault flags } while (SFRIFG1 & OFIFG); // Test oscillator fault flag P1OUT &= ~BIT0; // Clear P1.0 output P1DIR |= BIT0; // Set P1.0 as output for RTC running check // Setup P5.3 ou tput, P1.5 SMCLK, P1.4 MCLK, P1.2 ACLK P5DIR |= BIT3; // Set P5.3 to output direction P5OUT &= ~BIT3; // Clear P5.3 P1DIR |= BIT2 | BIT4 | BIT5; // ACLK, MCLK, SMCLK set out to pins P1SEL0 |= BIT2 | BIT4 | BIT5; // P1.2,4,5 for debugging purposes. // Setup TA0 TA0CCTL0 = CCIE; // CCR0 interrupt enabled TA0CCR0 = 50000; TA0CTL = TASSEL_2 | MC_1 | TACLR; // SMCLK, upmode, clear TAR //Enable the charger for AUXVCC3 AUX3CHCTL = AUXCHKEY + AUXCHEN + AUXCHC_1 + AUXCHV_1; // Configure RTC_C RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module RTCCTL0_L |= RTCTEVIE | RTCAIE | RTCRDYIE; // Enable RTC time event, alarm event, // read ready interrupt RTCCTL1 |= RTCBCD | RTCHOLD; // RTC enable BCD mode, RTC hold RTCYEAR = 0x2011; // Year = 0x2011 = 2011 RTCMON = 0x12; // Month = 0x12 = December RTCDAY = 0x05; // Day = 0x05 = 5th RTCDOW = 0x03; // Day of week = 0x03 = Wednesday RTCHOUR = 0x24; // Hour = 0x12 RTCMIN = 0x59; // Minute = 0x57 RTCSEC = 0x55; // Seconds = 0x36 RTCADOWDAY = 0x3; // RTC Day of week alarm = 0x2 RTCADAY = 0x22; // RTC Day Alarm = 0x22 RTCAHOUR = 0x23; // RTC Hour Alarm RTCAMIN = 0x45; // RTC Minute Alarm RTCCTL1 &= ~(RTCHOLD); // Start RTC calendar mode RTCCTL0_H = 0; // Lock RTC_C module __bis_SR_register(GIE); // interrupts // enabled while(1) { __delay_cycles(1000); // Delay } } // RTC Interrupt Service Routine #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, 16)) { case RTCIV_NONE: // No interrupts break; case RTCIV_RTCOFIFG: // RTCOFIFG break; case RTCIV_RTCRDYIFG: // RTCRDYIFG P1OUT ^= 0x01; // Toggles P1.0 every second break; case RTCIV_RTCTEVIFG: // RTCEVIFG __no_operation(); // Interrupts every minute break; case RTCIV_RTCAIFG: // RTCAIFG __no_operation(); // Interrupts every alarm event break; case RTCIV_RT0PSIFG: // RT0PSIFG break; case RTCIV_RT1PSIFG: // RT1PSIFG break; // case 14: break; // Reserved case 16: break; // Reserved default: break; } } // Timer0_A0 interrupt service routine #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=TIMER0_A0_VECTOR __interrupt void TIMER0_A0_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) TIMER0_A0_ISR (void) #else #error Compiler not supported! #endif { P5OUT ^= BIT3; // Toggle P5.3 }
PFA code, This should work for RTC and Timer both.
Regards
Bhavdipsinh
BHavdipsinh, I don't want to use TimerA, but I noticed that RTC stop work from battery after power Off, if I use Timer
**Attention** This is a public forum