RTC problem with MCF52234 (Clock doesn't start to run)

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

RTC problem with MCF52234 (Clock doesn't start to run)

2,019 Views
BlackIP
Contributor I
Hello,

I am having trouble by initializing the RTC on the MCF52234.
There is an external oscillator (25 MHz) and now I want to access the registers onto the processor.
I added a screenshot from my Codewarrior window.
My problem is that I don't know where to place the code. In the Main-file?
Or in a function? Do I need a loop.
The market code did I find on the net.

The TCP/IP-Stack is working fine.
There are only a few information according to the RTC on the net.

Perhaps you can give me a hint or name a website.
Thank you.

BlackIP


Message Edited by BlackIP on 2008-05-27 02:20 PM
Labels (1)
0 Kudos
6 Replies

534 Views
mjbcswitzerland
Specialist V
Hi BlackIP

The only thing needed when the program starts is to set the correct 1Hz value:
MCF_CLOCK_RTCDR = (OSCCLK-1);
The RTC will run per default so it doesn't need to be started. It will however start with all count values as 0, so you may want to set these - depending on your application.

There is a further discussion here:
http://www.utasker.com/forum/index.php?topic=35.0


Regards

Mark

www.uTasker.com



0 Kudos

534 Views
BlackIP
Contributor I
Hello again.

Thank you for your help. The Clock is running now.
And you are right, I want to set the clock.
I'm sending the clock values (hour, minute, second) to the MCF52234 by the Ethernet-Stack.
The Values are stored in a buffer and then in values.

But how can I write them to the RTC?
My assignments always types out an lvalue-error.

Here some code I tried:

Code:
MCF_RTC_HOURMIN_HOURS = hour;
MCF_RTC_HOURMIN_MINUTES = minutes;
MCF_RTC_SECONDS_SECONDS = sec;

Code:
(UINT8)((MCF_RTC_HOURMIN  & 0x00001F00)>>8) = hour;(UINT8)(MCF_RTC_HOURMIN & 0x0000003F) = minutes;(UINT8)(MCF_RTC_SECONDS & 0x0000003F) = sec;

 
I think its only a little thing, but to hard for a beginner..

Thank you for your help!

BlackIP


EDIT:

I don't even have the "app_hw_m5223x.h" file exposed in the other thread.
Where do I get it?


 



Message Edited by BlackIP on 2008-05-28 01:29 PM
0 Kudos

534 Views
mjbcswitzerland
Specialist V
Hi

Don't forget that the day counter counts from 0..64k so it is necessary to add Gregorian date conversion when setting the data, and the opposite when displaying it. You don't seem to be using the data counter at the moment and you will have only time of day.

I think that you can simply set the time by doing the following:
MCF_RTC_HOURMIN_HOURS   = hour;     // alternatively (hour & 0x1f)
MCF_RTC_HOURMIN_MINUTES = minutes;  // alternatively (minutes & 0x3f)
MCF_RTC_SECONDS_SECONDS = sec;      // alternatively (minutes & 0x3f)
I didn't check the defines used above but basically there are 2 x 32 registers:
- SECONDS containing just seconds
- HOURMIN containing hours and minutes
I suspect that you have defines like RTC_HOURMIN_HOURS and RTC_HOURMIN_MINUTES allowing byte accesses to the corresponding parts of the HOURMIN register.
Alternatively you can probably do a single access to the complete register
MCF_RTC_HOURMIN = ((hour << 8) | minutes);
It seems that some of the code which you show is syntactically incorrect but also probably not relevant for what you want to do.

app_hw_m5223x.h is a hardware configuration file from the uTasker project (which you are not using). We are presently adding RTC support for the M5221X which has an external 32k crystal and battery back-up support, making the RTC much more  attractive - here we also use Gregorian date conversions so that the calendar date is managed correctly. Our experience has shown that most M5223X projects with RTC requirements are solved by using an external RTC (eg. via I2C) with battery backup but this will certainly change with the battery backup support in newer devices.

Regards

Mark

www.uTasker.com








0 Kudos

534 Views
BlackIP
Contributor I
Hi,

Thank you for the advice but I don't need the day counter now, perhaps later.

I think you mean this defines:

Code:
#ifndef __MCF5223_RTC_H__
#define __MCF5223_RTC_H__

/*********************************************************************
*
* Real-time Clock (RTC)
*
*********************************************************************/

/* Register read/write macros */
#define MCF_RTC_HOURMIN              (*(vuint32*)(&__IPSBAR[0x0003C0]))
#define MCF_RTC_SECONDS              (*(vuint32*)(&__IPSBAR[0x0003C4]))
#define MCF_RTC_ALRM_HM              (*(vuint32*)(&__IPSBAR[0x0003C8]))
#define MCF_RTC_ALRM_SEC             (*(vuint32*)(&__IPSBAR[0x0003CC]))
#define MCF_RTC_CR                   (*(vuint32*)(&__IPSBAR[0x0003D0]))
#define MCF_RTC_ISR                  (*(vuint32*)(&__IPSBAR[0x0003D4]))
#define MCF_RTC_IER                  (*(vuint32*)(&__IPSBAR[0x0003D8]))
#define MCF_RTC_STPWCH               (*(vuint32*)(&__IPSBAR[0x0003DC]))
#define MCF_RTC_DAYS                 (*(vuint32*)(&__IPSBAR[0x0003E0]))
#define MCF_RTC_ALRM_DAY             (*(vuint32*)(&__IPSBAR[0x0003E4]))

/* Bit definitions and macros for MCF_RTC_HOURMIN */
#define MCF_RTC_HOURMIN_MINUTES(x)   (((x)&0x0000003F)<<0)
#define MCF_RTC_HOURMIN_HOURS(x)     (((x)&0x0000001F)<<8)

/* Bit definitions and macros for MCF_RTC_SECONDS */
#define MCF_RTC_SECONDS_SECONDS(x)   (((x)&0x0000003F)<<0)

/* Bit definitions and macros for MCF_RTC_ALRM_HM */
#define MCF_RTC_ALRM_HM_MINUTES(x)   (((x)&0x0000003F)<<0)
#define MCF_RTC_ALRM_HM_HOURS(x)     (((x)&0x0000001F)<<8)
.
.
. and so on..

Here I added my code for setting and reading the time from RTC:
The reading works fine. I will make no changes here.
Codewarrior gets an error by compiling this:

Code:
//********** Set Time ********************************************************//// Sets Time and Date // // Arguments: Time  ////*****************************************************************************void set_time(u_char *pBuffer){ int hour, minutes, sec;  pBuffer++; hour = (u_char)*pBuffer;  pBuffer++; minutes = (u_char)*pBuffer;  pBuffer++; sec = (u_char)*pBuffer;  MCF_RTC_HOURMIN_HOURS =  hour;   // hour & 0x1f MCF_RTC_HOURMIN_MINUTES = minutes; // minutes & 0x3f  MCF_RTC_SECONDS_SECONDS = sec; // sec & 0x3f}//********** Read Time ********************************************************//// Sends Time and Date to the TCP/IP Client// // Arguments: Time  ////*****************************************************************************void read_time(){ int time_temp; int rtc_hrs; int rtc_min; int rtc_sec;  rtc_hrs = (UINT8)((MCF_RTC_HOURMIN  & 0x00001F00)>>8); rtc_min = (UINT8)(MCF_RTC_HOURMIN & 0x0000003F) ; rtc_sec = (UINT8)(MCF_RTC_SECONDS & 0x0000003F) ;  buffer[0]=0xFF; asm {nop} buffer[1]=rtc_hrs; asm {nop} buffer[2]=rtc_min;  asm {nop} buffer[3]=rtc_sec; asm {nop} m_send( emg_tcp_communication_socket, (char*)&buffer[0], 4 ); }

 
Codewarrior has the following errors:

undefined identifier MCF_RTC_HOURMIN_HOURS
undefined identifier MCF_RTC_HOURMIN_MINUTES
undefined identifier MCF_RTC_HOURMIN_SECONDS

I don't understand why I'm getting these errors. In the reading-function everything works fine.
And I'm just using the same defines.

So I need help again.

Thank you and regards.


Btw: Which code do you mean is incorrect? I'm just practising and learning by doning :smileywink:
0 Kudos

534 Views
mjbcswitzerland
Specialist V
Hi

Now I see. You are using the macros incorrectly - I think that they need to be used as follows:

MCF_RTC_SECONDS= MCF_RTC_SECONDS_SECONDS(sec);
MCF_RTC_HOURMIN = MCF_RTC_HOURMIN_HOURS(hour) | MCF_RTC_HOURMIN_MINUTES(minutes);


However I see no real advantage of the macros - they are also not really accurate in restricting the value (hour &= 0x1f) will still allow a value of 25 to be written (for example).
I would simply check the values before writing (eg.):
if (hours >= 24) {
    // bad parameter
    hours = 0;   // limit
}
if (minutes >= 60) {
    // bad parameter
    minutes= 0;   // limit
}
Then
MCF_RTC_HOURMIN = ((hour << 8) | minutes);


Regards

Mark

www.uTasker.com



0 Kudos

534 Views
BlackIP
Contributor I
Hi,

it's working now.  :smileyhappy:

I tried the following options:
Code:
MCF_RTC_SECONDS = MCF_RTC_SECONDS_SECONDS(sec);MCF_RTC_HOURMIN = MCF_RTC_HOURMIN_HOURS(hour) | MCF_RTC_HOURMIN_MINUTES(minutes);
and
Code:
MCF_RTC_HOURMIN = ((hour << 8) | minutes);MCF_RTC_SECONDS = (sec);

 They are similar.

Now I'm thinking about realizing the day counter.
It should run with this line:

MCF_RTC_DAYS_DAYS(days)

Perhaps you can give me some information for integrating the gregorean calendar.


I have to thank you for your help!

Best regards,

BlackIP

 




Message Edited by BlackIP on 2008-05-29 10:34 AM
0 Kudos