MCF52259 RTC problems

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MCF52259 RTC problems

Jump to solution
2,786 Views
vier_kuifjes
Senior Contributor I

I am still trying to get the RTC of the 52259 CPU running, but still without luck. I can write the time in the registers but the time does not advance.

 

It's not clear to me how the 52259 RTC has to be programmed to make it work. The reference manual doesn't really help here either. I'm sure a particular sequence has to be followed but I don't really understand the explanation in the manual.

 

Any help is appreciated.

Labels (1)
0 Kudos
1 Solution
652 Views
vier_kuifjes
Senior Contributor I

I finally got it running!!

 

It appeared to be yet another bug in Coldfire Lite. The definitions of the registers MCF_RTC_RTCGOCU and MCF_RTC_RTCGOCL were wrong; they were defined as 16 bits wide, while they actually have to be addressed as 32-bit registers (even though both only contain 16 bits).

 

The error resides in the file MCF52259_RTC.h.

 

The lines...

 

#define MCF_RTC_RTCGOCU  (*(vuint16*)(0x40180034))
#define MCF_RTC_RTCGOCL  (*(vuint16*)(0x40180038))

 ...should become...

 

#define MCF_RTC_RTCGOCU  (*(vuint32*)(0x40180034))
#define MCF_RTC_RTCGOCL  (*(vuint32*)(0x40180038))

 

 

 

 

View solution in original post

0 Kudos
11 Replies
653 Views
vier_kuifjes
Senior Contributor I

I finally got it running!!

 

It appeared to be yet another bug in Coldfire Lite. The definitions of the registers MCF_RTC_RTCGOCU and MCF_RTC_RTCGOCL were wrong; they were defined as 16 bits wide, while they actually have to be addressed as 32-bit registers (even though both only contain 16 bits).

 

The error resides in the file MCF52259_RTC.h.

 

The lines...

 

#define MCF_RTC_RTCGOCU  (*(vuint16*)(0x40180034))
#define MCF_RTC_RTCGOCL  (*(vuint16*)(0x40180038))

 ...should become...

 

#define MCF_RTC_RTCGOCU  (*(vuint32*)(0x40180034))
#define MCF_RTC_RTCGOCL  (*(vuint32*)(0x40180038))

 

 

 

 

0 Kudos
652 Views
mjbcswitzerland
Specialist V

Hi Marc

 

I also had some difficulties with the word size (which I pointed out due to that reason) and I think that it is also not possible to get it running by manipulating the registers in the debugger (which is often useful to test the values) since the debugger obviously performs the wrong access width and so also doesn't work.

 

Thanks for the note about the secret bit. This is documented in the Kirin3 manual but not in the M52211 manual (which I originally wrote the code for - al least not in the manual version that I used). I believe that someone from Freescale gave me the tip at the time... I will rename the bit in the project at the next occassion (there was a new release today with a new graphic library - uGLCDLIB V1.1) but I read your note after this had been committed...(next time..;-)

 

Regards

 

Mark

 

 

 

 

 

 

0 Kudos
652 Views
vier_kuifjes
Senior Contributor I

Thanks, Mark!

 

One more thing... could it be that the initialisation in the uTasker code is wrong when using the system clock as source for the RTC? When I set RTCGOCU/RTCGOCL to 48000000 (as in the uTasker code), the RTC runs too slow. When I set it to 20000000 (= 80000000 / 4), it runs at the correct speed. This makes sense, as when using the 32.768 kHz crystal, the divider also has to be set to 1/4th the crystal frequency.

0 Kudos
652 Views
mjbcswitzerland
Specialist V

Hi Marc

 

Sorry about the delay in getting back.

Yes, you are of course correct. The clock is from the system clock divided by 4 and not from the oscillator. (Studing the user manual it is clear that it is derived from the system clock - that is the PLL output, if used, but the divide by 4 is not obious but exact by measurements).

 

Therefore the correct RTC divide is 

    RTCGOCU = (unsigned short)((BUS_CLOCK/4) >> 16);

    RTCGOCL = (unsigned short)(BUS_CLOCK/4);

 

My feeling is that the RTC is really only used in the 32kHz mode (otherwise it looses time on power down) on this chip and probably it was not noticed for that reason...

 

Thanks again.

 

Regards

 

Mark

 

P.S. Did you ever try the USB support in the uTasker package? And have you seen the new uGLCDLIB V1.1 (graphics library)? The M52259 connected to an ET024006DHU via Mini-FlexBus makes for simple TFT solution - see http://demo.uTasker.com -> then TFT page; this is acting as an Internet enabled picture frame (see the image in the TFT and upload new ones to it)

0 Kudos
652 Views
vier_kuifjes
Senior Contributor I
Ah... I just noticed there is a NEW version available! Have to check that out right away then...
0 Kudos
652 Views
vier_kuifjes
Senior Contributor I

mjbcswitzerland wrote:

My feeling is that the RTC is really only used in the 32kHz mode (otherwise it looses time on power down) on this chip and probably it was not noticed for that reason...



 

That is correct of course, but in my case it doesn't matter. My app is a weather station that goes on line frequently to download weather data. This data also contains date and time, and that is what I use to set the RTC. So basically, when the device has internet access it has the time available. If it doesn't have access it doesn't make any sense to have it running at all. So I chose for the simplest configuration for the RTC.

 

Personally I'm not really into USB. At least not at the moment :smileyhappy:...

But the graphics display driver did get my full attention as I'd like to create a graphical version of my weather station. The hardest part of creating a graphical version seems to be to create some nice graphics to display the weather phenomena!

 

I did not forget about the uTasker! The main reason that I started using Coldfire Lite is because there was an application note available that exactly fitted my needs. It's definitely not the best choice though. There's hardly any support from Freescale, so if there is a problem you're basically on your own. And I did encounter some important problems that made my weather station lock up frequently. I managed to fix them (wasn't easy) and communicated them to Freescale a couple of times but I don't think they did anything with it. My guess is they're no longer interested in CF Lite...

0 Kudos
652 Views
PaoloRenzo
Contributor V
Is the RTC power pin connected? Can you generate a valid 32.768Khz clock?
0 Kudos
652 Views
vier_kuifjes
Senior Contributor I
I guess so, I'm running this on the 52259DEMO board. But it should also be possible to run the RTC from the main CPU clock, and that doesn't work either...
0 Kudos
652 Views
mjbcswitzerland
Specialist V

Hi Marc

 

Here is the code in the uTasker project to initialise the RTC:

 

    if (MCF_CLOCK_RTCCR != (SECRET_BIT | RTCSEL_OSC | RTC_LPEN | RTC_REFS | KHZEN_KHZ | RTC_OSCEN)) { // only on first start initialise 32k
        RTCCTL = RTC_ENABLE; [0x80]
        MCF_CLOCK_RTCCR = (SECRET_BIT | RTCSEL_OSC | RTC_LPEN | RTC_REFS | KHZEN_KHZ | RTC_OSCEN); [0x57]
        RTCGOCL = (unsigned short)(32768/4); [0x2000]
        MCF_CLOCK_RTCCR = (SECRET_BIT | RTCSEL_OSC | RTC_LPEN | RTC_REFS | KHZEN_KHZ | RTC_OSCEN);
    }

 

The values in [] are the values written to the registers in case you want to try the sequence in the debugger. The SECRET_BIT (0x40) seems to be an undocumented bit which is needed to be set to get the 32k RTC counting.

 

I am not sure about the double-write to RTCCR - it may be left over code after a change some time...(?)

 

 

To run from the main clock:

 

    RTCCTL = RTC_ENABLE; [0x80]
    MCF_CLOCK_RTCCR = 0;                                                 // select system clock for RTC
    RTCGOCU = (unsigned short)((CRYSTAL_FREQ) >> 16); [0x02dc]
    RTCGOCL = (unsigned short)(CRYSTAL_FREQ); [0x6c00]

 

If I remember correctly it is important to write to RTCGOCU and RTCGOCL as 32 bit registers (although the content is only 16 bit width). If the code writes them as 16 bit registers the writes aren't accepted and so it doesn't run.

 

I believe that the code has been successfully used on M5221X, M521XX and M5225X devices so tell me if you have any problems.

 

Regards

 

Mark

 

www.uTasker.com
- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."

 

 

0 Kudos
652 Views
vier_kuifjes
Senior Contributor I

Thanks Mark, I will try it out as soon as I finish my current work on my project.

 

Actually, I already checked the uTasker code on how it sets up the RTC (yes, I have the uTasker, remember me? :smileyhappy: but I never actually tried that piece of code out yet. If the secret bit is the clue, I wonder why it isn't documented, and I also wonder how you figured that out! :smileyhappy:

 

Anyway, getting the RTC to run on a 52259 seems a lot harder than getting it to run on a 5223x, on which it runs as soon as the prescaler is set.

0 Kudos
652 Views
vier_kuifjes
Senior Contributor I

Nope, no matter what I try, the RTC does not want to run! I tried by following the reference manual, used the code from the uTasker, used the code from MQX and also tried the code generated by the processor expert. But nothing seems to work. I tried running the RTC from the 32kHz xtal and from the main 48MHz clock. Nothing works.

There must be SOMETHING I'm overlooking. It's not a defective board. I have 2 52259DEMO boards and they both act the same.

 

By the way Mark, the "secret bit"  is named EXTALEN in the reference manual. So it's not really secret anymore!

0 Kudos