AnsweredAssumed Answered

MCF52259 RTC issues - can anyone clarify correct operation?

Question asked by FridgeFreezer on Dec 14, 2010
Latest reply on Feb 13, 2013 by TomE

Micro is MCF52259 LQFP144, IDE is CW7.2 using C.


Having got things up & running on our first run of prototype boards, I've just programmed code into a 2nd gen prototype and the RTC fails to start. Using the same init routines on a working board, I can't make the RTC stop!


The circuity is exactly the same on both; RTC is using an external 32.768KHz crystal across RTC_EXTAL/RTC_XTAL and backup battery on VSTBY.


I suspect that during the struggle to get the RTC working in development, the RTC registers have been written with the magic combination to make it work, and then the backup battery has preserved the settings for posterity. The reference manual (Rev.2) for the mirco has a couple of cryptic references to things which are not explained:



The real-time clock control (RTCCTL) register is used to enable the real-time clock module and specify
the reference frequency information for the prescaler


This register is only shown as having two bits implemented: 0x80 for RTC_Enable and 0x01 for RTC_Software_Reset. Althgough my init routine sets this register to 0x80, a read of it returns 0x01 on both working & non-working boards. There is no mention of anything to do with the prescaler.



9.4.1 RTC Register Access Protocol
1. Perform dummy read access to a non-RTC address location.
2. Perform dummy read to the targeted RTC address location.
3. Perform actual read or write access to the targeted RTC address location.
Steps 1 and 2 can be combined into one cycle that is a dummy read access to a non-RTC but targeted RTC
address location. Then the protocol is:
1. Perform dummy read access to a non-RTC, targeted RTC address location.
2. Perform actual read or write access to targeted RTC address location.


No further explanation is given on this, and frankly I'm clueless as to what it really means, can anyone shed any light on what sort of routine one is expected to use to conform to this protocol?


Third, and not helping my befuddlement:

Figure 9-15 shows sample code for initializing the RTC.
MCF_RTCGOCL = 0x00002000; //32KHz
MCF_RTC_HOURMIN = MCF_RTC_HOURMIN_HOURS(((uint32)time_temp % 24));
MCF_RTC_HOURMIN = MCF_RTC_HOURMIN_MINUTES(((uint32)time_temp % 60));
MCF_RTC_SECONDS = MCF_RTC_SECONDS_SECONDS(((uint32)time_temp % 60));


Not much help as I can't see any dummy reads or indeed any configuration of the RTCCTL register.


My init routine currently looks like this:


MCF_CLOCK_RTCCR = 0    | MCF_CLOCK_RTCCR_RTCSEL    // Crystal source
                        | MCF_CLOCK_RTCCR_REFS        // External xtal
                        | MCF_CLOCK_RTCCR_OSCEN        // Oscillator enabled
                        | MCF_CLOCK_RTCCR_EXTALEN;    // EXTAL enabled
MCF_RTC_RTCGOCU = 0x00000000;
MCF_RTC_RTCGOCL = 0x00002000; // 32.768KHz XTAL

Not that it's much use as the boards which have a running RTC just keep running and the ones that don't won't!


I have searched back and a there are a couple of threads on this subject but none seem to contain a solution or the full answers.


I have looked at the Freescale code examples and haven't found any great insights, here are a couple of snippets:

(from rtc_main.c)

void rtc_write_prescaler (uint32 value)
    // Set RTC clk source, enable RTC etc.
     MCF_CLOCK_RTCCR = 0x57; // This is = ~(ENABLE | RESET) so disabling the RTC
     MCF_RTC_RTCGOCU = 0x00000000;
     MCF_RTC_RTCGOCL = value;


The RTC is then enabled again later with:



But when I do the same thing the RTC doesn't spring into life.


I'm sure there's something daft I'm missing but I can't for the life of me see what it is.