Re: MCF52259 RTC problems

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

Re: MCF52259 RTC problems

1,723 Views
TomE
Specialist II

Hi

We have a problem with the RTC on MCF52259.

We put a crystal 32.768Hz between the RTC-EXTAL and RTC-XTAL pins. A battery backup (3V button lithium) to the VSTBY pin.

The RTC works only in battery backup mode. In this case it is possible to see a 32K768 oscillation on pin RTC-XTAL. When we put the the micro in normal operation (power supply from 3.3V), the oscillation on RTC-XTAL is stopped and the RTC stop to work.

How is possible? Can you help us, as soon as possible?

Thank you

 

 

BY: Marco Maioli

 

 

Searching the manual for "RTC" finds:

 

7.3.2 RTC ModeA dedicated RTC oscillator can be selected to run the RTC circuitry. In normal operation, this oscillator is powered by the VDDPLL and VSSPLL pins. When the part is shut down, this oscillator is powered by the VSTBY pin.

 

I guess those other voltages have to be present or your chip probably wouldn't work properly when on.

 

7.7.1.9 Real-Time Clock Control Register (RTCCR) The RTCCR is used to configure the RTC oscillator. The EXTALEN bit enables and disables the RTC_EXTAL pin, RTC registers are reset only once, during the first power-on reset (POR), and are never reset again as long as the power source is connected.

This bit resets to the OFF state. So does the OSCEN bit. The oscillator is disabled on a power on reset. Is your code enabling the oscillator and pin? It has to do this somewhere.

 

Where it says "as long as the power source is connected" it doesn't say WHICH power supply they're talking about. If these registers are all powered from VSTBY then it you need to turn the oscillator on on every Reset, and the bits should stay that way. If they reset when the 3V3 goes off it wouldn't be a very useful design. It should state which supply, but it doesn't.


There's nothing in the Reference Manual or Data Sheet detailing how this works or how to use it. There are no App Notes on this subject.

 

You'll have to find someone who has worked this out already (why you're asking in the forum), or you'll have to experiment and reverse-engineer it yourself. This happens a lot with Freescale chips. I've spend months doing this.

 

I'd recommend you change the design to use an external RTC chip on an SPI or I2C bus. They come with documentation.

 

Although not for your chip, you might like to read AN4503.

 

Tom

 


 

Message was edited by: Monica Arvizu

Labels (1)
0 Kudos
9 Replies

647 Views
marcomaioli
Contributor II

Hi Tom

Thank you for you good informations

We are checking what you wrote.

 

I am sorry Tom, but I forget a thing to say:

to try something else, we have placed on RTC_EXTAL a 32K768 external oscillator (powered at 3V3) and

programmed the register with this setup.

All works correctly when the 3V3 power supply is on and, of course, the RTC stop to work when

all goes in backup battery mode (because the oscillator is not powered).

All this as opposed to when we use an external crystal powered by Vbstby

and the registers are programmed for this setup (the RTC works only in Vstby and not when power 3V3 is on).

Why occurs this?

Marco

0 Kudos

647 Views
TomE
Specialist II

What does the RTCCR register contain when the 3V3 supply is on? I suspect the contents of that register might show the oscillator is disabled.

Tom

0 Kudos

647 Views
marcomaioli
Contributor II

When the power supply is on, RTCCR value is 0x57.

I have tested other values,  for example I have tried to change the source of RTC (RTCCR = 0x56), I have disabled (RTCCR = 0x47) and than enabled (RTCCR = 0x57) the EXTALEN pin, but in any cases the RTC doesn't count.

For completeness I enclosed the battery backup section:

MAX6366.bmp

the connection to microcontroller:

Collegamento micro.bmp

and the RTC section:

RTC.bmp

As you can see, the power 3V3 and the Vbatt (3V from lithium battery) are managed through a supervisor MAX6366 for the Vstby. The RTC power supply sections are always active. In fact, when the power 3V3 is off, there is an oscillation and so there is an increment of count...

I hope I have given useful information, waiting for news, I wish you a good day.

Diego


0 Kudos

647 Views
marcomaioli
Contributor II

Hi,

after some attempt I have succeeded to start the RTC.

I have done some passages, but I have repeated the entire procedure for 6 devices and all of them work now.

As I mentioned before I have mounted the MAX6366 to manage the battery. So first of all I have tested this device:

    -I have mounted the battery;

    -I have connected the power supply;

    -I have disconnected the power supply.

At this point the MAX6366 is ok, in fact without the power supply there is the oscillation on pin RTC_EXTAL.

So I have loaded the software in this mode:

    -I have disconnected the battery

    -I have connected the power supply

    -I have loaded the software with the procedure of initialization of RTC:

        RTCCR = 0x57;

        RTCGOCU = 0x0;

        RTCGOCL = 0x00001FFF;

        At this point the RTC should count. Note that at this point the value of the register RTCCTL was 0x80 (RTC enabled);

    -without disconnect the power I have connected the battery;

    -I have switched off the device.

Now, when I power on the device, the RCT works. If I power on the device without the battery the RTC works again correctly but, rightly, starts from zero.

Thank you for your support,

Diego. 


0 Kudos

647 Views
TomE
Specialist II

You "solution" doesn't seem to be workable in practice. You can't be made to remove the battery in order to reset the unit. Do you have software control of that power-monitor chip? Maybe you can turn it off from software when you need to reset things. There's still something wrong here.

I'd have a close look at the following in case it is causing you problems. I have no idea what "non-RTC, targeted RTC address location" means. Anyone?

9.4 Initialization/Application Information
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.

Then "Figure 9-14. Flow Chart of RTC Operation" says to set Days, then Seconds, then Hrs/Min.

Then "9.4.3 Code Example for Initializing the Real-Time Clock" accesses the registers in a different order to the flowchart, seemingly ignores the "RTC Register Access Protocol" completely, and then sets "days" to "seconds % 24" instead of "seconds % (24 * 60 * 60) and sets the Seconds and Minutes the same. Doesn't anyone even LOOK at the sample code, let alone actually run it to see if it works?

MCF_CLOCK_RTCCR=0b01010110; //RTCCC
MCF_RTCGOCL = 0x00002000; //32KHz
MCF_CLOCK_RTCCR=0b01010111; //RTCCC

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));

That doesn't inspire confidence in the rest of the chapter, or the rest of the manual.

Apart from the more-bugs-than-lines-of-code, there's something suspicious in the above.

Note how it programs RTCCR to the System Clock, THEN programs RTCGOCL, THEN programs RTCCR to the RTC Oscillator. Maybe you can't change some registers in this module unless it has a running clock. Note the manual says the 1Hz clock is disabled if RTCGOCx is zero.

> RTCGOCL = 0x00001FFF;

Why that value? Have you found that your crystals are running 30ppm slow? The Reference Manual shows 0x2000.

Of course your not the first with this problem. You (and I) should have searched these forums first:

MCF52259 RTC issues - can anyone clarify correct operation?

Tom

0 Kudos

647 Views
marcomaioli
Contributor II

Hi Tom,

today I have tried to load the same software that I wrote yesterday.

I have followed the same sequence that I have described you, but today the RTC doesn't work and I don't understand why...

I have done several tests and I have noted a thing.

I load the software by USB and one time I have connect first the USB, after power supply. I have loaded the software and the RTC has worked right...

Hence, I have done these passages:

    -First I have connected the battery;

    -Then I have connected the USB;

    -I have connected the power supply;

    -So I have loaded the software.

I have tried to load the software in this mode on other 4 devices and all work rigth...

Don't you think that there is a particular power-up sequency to follow?

Thank you again,

have a nice day.


0 Kudos

647 Views
TomE
Specialist II

Have you searched this forum? Have you read the linked article I provided in my answer? If you did do what I suggested, then please say so in your response.

MCF52259 RTC issues - can anyone clarify correct operation?

The "Correct Answer" in the above noted that the Freescale-provided header files are wrong, and declare some of the registers as 16-bits instead of 32-bits. All registers have to be written as 32 bits or they don't work. That might explain your USB-vs-code differences.

Tom

0 Kudos

647 Views
marcomaioli
Contributor II

Hi Tom,

yesterday morning I have read your linked articles, but then I have concentrated on other things about my problem. So when I have written on forum, I haven't answered your questions...Sorry...

However, I write the registers as 32bits, I had already encountered this issue...

Regarding 9.4 Initialization/Application Information

I think that if you want to read an RTC address location, you must:

- do a read in an address that isn't an RTC address,

- do a read in an RTC address, but is not the wanted RTC address,

- do a read of the wanted RTC address.

About the procedure of RTC initialization

I have tried to do the same things wrote in the manual, but the RTC didn't start however. I have solved my problem only with the procedure that I have explained to you. The value  RTCGOCL = 0x00001FFF, doesn't make sense, I have assigned 0x00002000 to the RTCGOCL register.

About the USB, I have forgotten to explain to you 2 things:

-When I disconnect power supply of device (230Vac), I can supply it by USB. In this case there is about 2.5V on chip.

-I use the USB to load the software, after that I disconnect the USB cable.

Given that when I connect only USB there is 2.5V on chip, I have thought that if I do this procedure:

-connect only USB (2.5V on chip),

-connect power supply (3V3 on chip),

-load the software,

-disconnect USB

and the RTC works. Since the RTC works and the voltage on chip pass from 2,5V to 3.3V, maybe I must to do a power-up procedure?What do you think about?

Diego


0 Kudos

647 Views
TomE
Specialist II

> What do you think about?

I think that nobody could build a commercial product that required everyone to do that to get it working.

Do you have a Development Board for that chip, or is what you're using the Development Board? These boards are the "working reference" for these chips, and you can find out a lot more from the schematics on how to use the chip than you'll ever find in the Reference Manual. In practice, the safest thing to do is to exactly copy the way the Development Board does things, even if you don't know why.

If you don't have a board you should get one and see if you can get the RTC working on it. If it works, find the critical difference between your design and it, then change your design. If you can't do this, then the specific difference between the boards may suggest a better workaround.

If the development board doesn't work you should be able to get support from Freescale with this problem. Since they have to try and duplicate any reported problem, you have to demonstrate it on the same boards that they have. If you can send them a project they can directly load onto their boards it makes it a lot easier for them and you.

Tom

0 Kudos