cancel
Showing results for 
Search instead for 
Did you mean: 

Save my RTC

hervett
Associate II
Posted on January 14, 2009 at 13:25

Save my RTC

11 REPLIES 11
hervett
Associate II
Posted on May 17, 2011 at 12:58

Hello everybody and an happy new year !!!

I still have problems with my I²C but it's not my question for the moment.

I wonder how can I save my calendar when my device is off. I explain:

I'm using the intern RTC for my calendar. I work with seconds, minutes, hours, day, month and year.

I can save the RTC when the device is off( it is 05:54:45, I switch off during 15s and when I switch on, I have 05:56:00. It work fine !

I have a cell of 3V for the RTC.

But if I switch off my device two or three days, it can't recover the changement of day, or month.

My IT is enable for second in my code, so my counter get +1 for each second.

Have I to enable IT for minutes, hours, day, month and year in order to recover the changement ?

Can I enable all these IT's at the same time ?

Or easier, it is possible to save my calendar with the RTC of the STM32 ?

Thank you everybody 🙂

relaxe
Associate II
Posted on May 17, 2011 at 12:59

You should do it the Unix way:

Use the 32 bits RTC register to save the number of seconds since 1et jan. 1970.

Ok, now that you've calmed down: This is the ''standart'' unix-C method. Doing so will allow you to use the to it's full potential: you can use the tm struct to populate month, date, year, etc. , then use mktime to transfer the struct to a value, or convert back to a u32, print formatted date with ctime(), etc.

Just google around for time.h, you'll see.

Ah, yes, doing so will ''only'' be valid until 2038, so enjoy those 29 years left!

-Relaxe

hervett
Associate II
Posted on May 17, 2011 at 12:59

And if I don't want use the unix way ?

Because I havn't knowledges in that, my code is now started since a long time and I don't want to restart from the beginning

jj
Associate II
Posted on May 17, 2011 at 12:59

Please do report your results - good or bad - so that the forum learns from your ''process.'' When we ''close the loop'' the forum is more valuable to all. Thanks...

hervett
Associate II
Posted on May 17, 2011 at 12:59

I just find the application note AN2821 added recently . So I think it will answer at all my questions, I will be back here if I have problems again !!

Thanks

hervett
Associate II
Posted on May 17, 2011 at 12:59

I watched this application note and thought about that problem. I think it is not possible to save the calendar if I switch off totally the STM32. It is possible in standbymode or stop mode but not in off mode! You can save the RTC counter when you switching off the system and recover it updated after the power on ( acutally working on my device ). But when the RTC counter go to zero, you don't have something to tell you that WHEN THE DEVICE IS OFF. So you can't count day, and month or year when the device is off. You can save the time but not the date. But maybe there is an overflow flag after the reset of the RTC, but it have to be save automaticly in the BKP domain when the device is off in order to recover it. Beause when you make the overflow flag yourself in the stm32it.c, the code is not executed during the power off.

Whem i'm talking of the power off, I suppose that there is not the 3,3V on VCC but there is the cell of 3V for the RTC and the BKP domain.

So in order to make my OWN conclusion, I think it is possible to save the calendar and recover it updated only after a standby mode or stop mode but NOT if you switch totally off the device .

It is only based with my knowledges !

So for my application I think I will do that with a M41T56 or something like that !!

I'm waiting for comments.

hervett
Associate II
Posted on May 17, 2011 at 12:59

No problems !

relaxe
Associate II
Posted on May 17, 2011 at 12:59

Is your RTC calibrated to save a ''number of seconds''? If so, why not just let it count, then add a small condition to your startup loop:

if (RTC_GetCounter() >= (60*60*24)) //Timer counted for more than a day

DaysPassedInHibernate = (RTC_GetCounter() / (60*60*24));

Then remove the ''excess days'' from the counter.

hervett
Associate II
Posted on May 17, 2011 at 12:59

I'M SO STUPIDD !!

I had already that solution programed on my STM32 ( solution of relaxe ) but I did mistakes in my calculation. I was persuaded that this solution didn't work if the device was off more than two weeks. But I did again my calculations and found 136 years !!!!

And I don't think that my device will be off more than 136 years, and I don't know too if someone will be here in 136 years in order to switch on the device !! ^^

I'm so stupid and I'm sorry to have made you waste your time !...and mine too !

So I will continu to use that and make my calendar system with that !!

Thank you relaxe to have switched the right button in my brain !!