cancel
Showing results for 
Search instead for 
Did you mean: 

Having some trouble setting TR in the RTC

sjenyart
Associate II
Posted on December 05, 2012 at 22:35

I'm working with a mix of STM drivers and in in-house drivers, some of which we have written, some of which we inherited.  I am trying to set the date and time in the RTC, starting with TR.  It is not working.

Here is what I am doing:

1) Starting with enabling backup domain reset.  Confirmed that BDRST changes to set. I am doing this because I wanted to simulate a POR and see all of the register values change- it appeared that a debugger reset would not.

2) Unlocking backup domain write protection.  

3) Disabling backup domain reset. Confirmed BDRST is clear. The reason I did this after step 2) was that if I did it right after step 1), I was not seeing RTCSEL change to default after step 1).  When I moved this to after step 2), I did.  Not sure why.

4) Select LSI as clock source.  Confirmed RTSSEL set to LSI (0x2).

5) Enabled the RTC clock.  Confirmed RTCEN changes to enabled. I don't set LSION because it was already enabled for the watchdog.

6) Unlocked the RTC registers by writing 0xCA and 0x53 in sequence to WPR (write only). 

7) Activate init mode and wait for it.  Confirmed INIT and INITF both change to set.

8) Try to write to TR.  Nothing happens.

Looking through RM0090 and and AN3371, this looks like what needs to be done, more or less, to set TR and DR but I am obviously missing something.  I did not adjust the pre-scalers, assuming that I was ''close enough'' for a sanity check with LSI.

#rtc-tr-stm32
3 REPLIES 3
sjenyart
Associate II
Posted on December 05, 2012 at 22:44

By the way, I should add that I am using LSI as a short-term measure.  There will be another ECU in our system that will use an external clock and will periodically calibrate us with a good time.  I just need to use LSI to get by between those intervals.

Posted on December 06, 2012 at 01:01

Isn't step 9) to clear INIT so the counters start using TR/DR, and you just read back shadow registers

''Counters are stopped and start counting from the new value when INIT is reset.''

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sjenyart
Associate II
Posted on December 07, 2012 at 14:40

Yes, definitely step 9 would be to clear init so that I can read the shadow registers.  However, TR and DR should reflect their initialization values before clearing INIT, should they not?