Alarm timer problems with MCF52234

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

Alarm timer problems with MCF52234

1,325 Views
BlackIP
Contributor I
Hi folks,

I want to use the Alarm timer in the MCF52234.
Setting up the minutes and seconds is possible.
But I can't set the hour register.

Perhaps I can set all values correcty and the reading command is wrong.
Setting and reading of minutes and seconds is correctly, The hour-value is always 0.

I added the Code for you : :smileyhappy:

Code:
//********** Set Timer*********************************************************////  Sets the Timer of the RTC//  Firstbyte:  0xAE // ////***************************************************************************** int set_timer(u_char* pBuffer){ int hour, minute, second;   pBuffer++; hour = (u_char)*pBuffer;   pBuffer++; minute = (u_char)*pBuffer;  pBuffer++; second = (u_char)*pBuffer;            MCF_RTC_IER|= MCF_RTC_IER_ALM;  // ENABLE INTERRUPT FOR ALARM      MCF_RTC_ALRM_HM = MCF_RTC_ALRM_HM_HOURS(hour) | MCF_RTC_ALRM_HM_MINUTES(minute);   MCF_RTC_ALRM_SEC = MCF_RTC_ALRM_SEC_SECONDS(second); } //********** Read Timer*********************************************************////  Reads the Timer of the RTC//  Firstbyte:  0xAF // ////***************************************************************************** int read_timer(){ int hour, minute, second;   second =  ((MCF_RTC_ALRM_SEC));   minute =  ((MCF_RTC_ALRM_HM & 0x0000003F)<<0); hour   =  ((MCF_RTC_ALRM_HM & 0x0000001F)<<8); //hour =   ((MCF_RTC_ALRM_HM & 0x0000001F)>>8);  buffer[0]= 0xFF; buffer[1]= minute; buffer[2]= hour; buffer[3]= second; m_send( emg_tcp_communication_socket, (char*)&buffer[0], 4 );}

Perhaps someone can have look on it and give me some hints.
Thank you very much. :smileyhappy:

Best regards.

BlackIP



Message Edited by BlackIP on 2008-07-16 02:46 PM
Labels (1)
0 Kudos
3 Replies

302 Views
RichTestardi
Senior Contributor II
Hi,
 
I think this is your bug:
 
    minute =  ((MCF_RTC_ALRM_HM & 0x0000003F)<<0);
    hour   =  ((MCF_RTC_ALRM_HM & 0x0000001F)<<8);
 
I think you want to be reading from the low byte to get the minutes (as you are actually doing), and then from the next more significant byte to get the hours (where you are currently re-reading the low byte), like:
 
    minute =  ((MCF_RTC_ALRM_HM >> 0) & 0x0000003F);
    hour   =  ((MCF_RTC_ALRM_HM >> 8) & 0x0000001F);
 
-- Rich
 
0 Kudos

302 Views
RichTestardi
Senior Contributor II
And one more note...  Usually in the Freescale header files, they give you macros to *encode* the register values (which you used correctly), like:
 
    /* Bit definitions and macros for MCF_RTC_ALRM_HM */
    #define MCF_RTC_ALRM_HM_MINUTES(x)           (((x)&0x3F)<<0)
    #define MCF_RTC_ALRM_HM_HOURS(x)             (((x)&0x1F)<<0x8)
 
However, they often do not give you the converse macros to *decode* the register values (which you want in this instance), so you have to write them by hand or code them explicitly.
 
In general, the "encode" and "decode" macros will swap the order of the mask and shift, and will change the direction of the shift, like:
 
    #define DECODE_MCF_RTC_ALRM_HM_MINUTES(x)           (((x)>>0)&0x3F)
    #define DECODE_MCF_RTC_ALRM_HM_HOURS(x)             (((x)>>8)&0x1F)

 
 


Message Edited by Rich T on 2008-07-16 12:16 PM
0 Kudos

302 Views
BlackIP
Contributor I
This works now.
Thank you very much. :smileyhappy:

Now I am fighting with the interrupt handler.
Is there any easy opportunity to connect the RTC, which is already setable and running, with the alarm timer?

I need it for a start-stop condition. E.g. defining a time to start and another time to stop some functions.
I hope you see my problem.

There are many things to configure, when I look at this thread:
 http://forums.freescale.com/freescale/board/message?board.id=CFCOMM&message.id=2794&query.id=71515#M...

And the interrupts described in the thread above are all external. I need the internal ones.

Thanks for your help.

BlackIP

0 Kudos