EmbeddedRelated.com
Forums

RTC in LPC2106

Started by acetoel January 6, 2005

Hello, I have set up the RTC and make a simple program to test it. But
it doesn't work! Here is the code... on the PC (connected to the
serial port) I always view the same time 19:8:51
Thanks
Ezequiel

#include "LPC210x.h"
#include "Init.h"
#include "UART.h"
#include "Delayus.h"

#define Boton 0x80000000
#define LED1 0x10000000
#define LED2 0x20000000
#define LED3 0x40000000

UInt8 contador;
UInt16 Counter2;
UInt32 Hour,Min,Sec; int main (void)
{
/*Initialize the system*/
InitLPC2106();
InitCom(); //115200 bauds
IODIR=0x70000000;
IOCLR=0x70000000;

RTC_CCR=0;
RTC_CIIR=0x00000000;
RTC_AMR=0x00000000;
//real date time setting
RTC_SEC=0x00000033;
RTC_MIN=0x00000008;
RTC_HOUR=0x00000013;
RTC_DOM=0x00000006;
RTC_DOW=0x00000004;
RTC_DOY=0x00000004;
RTC_MONTH=0x00000001;
RTC_YEAR=0x000007D5;
//alarm setting
RTC_ALSEC=0x00000001;
RTC_ALMIN=0x00000001;
RTC_ALHOUR=0x00000001;
RTC_ALDOM=0x00000001;
RTC_ALDOW=0x00000001;
RTC_ALDOY=0x00000001;
RTC_ALMON=0x00000001;
RTC_ALYEAR=0x000007D0;
//start rtc
RTC_CCR=0x00000001;

contador=0x00;
IOSET = LED2;
IOSET = LED3;
printf ("Ezequiel L. Acetp %c%c",'\n','\r');
//printf("Ezequiel L. Aceto\n");
//printf("Sunixs Microsystems\n");
while(1)
{
IOSET = LED1;
delayus(1000); //0.5 Sec delay
IOCLR = LED1;
delayus(1000);
Hour = RTC_HOUR;
Min = RTC_MIN;
Sec = RTC_SEC;
printf("%2d : %2d : %2d ",Hour, Min, Sec,'\n','\r');
Hour = 0x00;
Min = 0x00;
Sec = 0x00;
}
}



An Engineer's Guide to the LPC2100 Series


Hi Ezequiel,

have you set the prescaler registers RTC_PREINT and RTC_PREFRAC to
divide down your pclk to 32.768 kHz?

Cheers,
Rolf --- In , "acetoel" <acetoel@y...> wrote:
>
> Hello, I have set up the RTC and make a simple program to test it. But
> it doesn't work! Here is the code... on the PC (connected to the
> serial port) I always view the same time 19:8:51
> Thanks
> Ezequiel
>
> #include "LPC210x.h"
> #include "Init.h"
> #include "UART.h"
> #include "Delayus.h"
>
> #define Boton 0x80000000
> #define LED1 0x10000000
> #define LED2 0x20000000
> #define LED3 0x40000000
>
> UInt8 contador;
> UInt16 Counter2;
> UInt32 Hour,Min,Sec; > int main (void)
> {
> /*Initialize the system*/
> InitLPC2106();
> InitCom(); //115200 bauds
> IODIR=0x70000000;
> IOCLR=0x70000000;
>
> RTC_CCR=0;
> RTC_CIIR=0x00000000;
> RTC_AMR=0x00000000;
> //real date time setting
> RTC_SEC=0x00000033;
> RTC_MIN=0x00000008;
> RTC_HOUR=0x00000013;
> RTC_DOM=0x00000006;
> RTC_DOW=0x00000004;
> RTC_DOY=0x00000004;
> RTC_MONTH=0x00000001;
> RTC_YEAR=0x000007D5;
> //alarm setting
> RTC_ALSEC=0x00000001;
> RTC_ALMIN=0x00000001;
> RTC_ALHOUR=0x00000001;
> RTC_ALDOM=0x00000001;
> RTC_ALDOW=0x00000001;
> RTC_ALDOY=0x00000001;
> RTC_ALMON=0x00000001;
> RTC_ALYEAR=0x000007D0;
> //start rtc
> RTC_CCR=0x00000001;
>
> contador=0x00;
> IOSET = LED2;
> IOSET = LED3;
> printf ("Ezequiel L. Acetp %c%c",'\n','\r');
> //printf("Ezequiel L. Aceto\n");
> //printf("Sunixs Microsystems\n");
> while(1)
> {
> IOSET = LED1;
> delayus(1000); //0.5 Sec delay
> IOCLR = LED1;
> delayus(1000);
> Hour = RTC_HOUR;
> Min = RTC_MIN;
> Sec = RTC_SEC;
> printf("%2d : %2d : %2d ",Hour, Min, Sec,'\n','\r');
> Hour = 0x00;
> Min = 0x00;
> Sec = 0x00;
> }
> }





Ups... I didn't do that... how can I set it up, if I have a PCLK and
CCLK of 60Mhz?
Thanks
Ezequiel

--- In , "lpc_bavaria" <lpc_bavaria@y...> wrote:
>
> Hi Ezequiel,
>
> have you set the prescaler registers RTC_PREINT and RTC_PREFRAC to
> divide down your pclk to 32.768 kHz?
>
> Cheers,
> Rolf > --- In , "acetoel" <acetoel@y...> wrote:
> >
> > Hello, I have set up the RTC and make a simple program to test it. But
> > it doesn't work! Here is the code... on the PC (connected to the
> > serial port) I always view the same time 19:8:51
> > Thanks
> > Ezequiel
> >
> > #include "LPC210x.h"
> > #include "Init.h"
> > #include "UART.h"
> > #include "Delayus.h"
> >
> > #define Boton 0x80000000
> > #define LED1 0x10000000
> > #define LED2 0x20000000
> > #define LED3 0x40000000
> >
> > UInt8 contador;
> > UInt16 Counter2;
> > UInt32 Hour,Min,Sec;
> >
> >
> > int main (void)
> > {
> > /*Initialize the system*/
> > InitLPC2106();
> > InitCom(); //115200 bauds
> > IODIR=0x70000000;
> > IOCLR=0x70000000;
> >
> > RTC_CCR=0;
> > RTC_CIIR=0x00000000;
> > RTC_AMR=0x00000000;
> > //real date time setting
> > RTC_SEC=0x00000033;
> > RTC_MIN=0x00000008;
> > RTC_HOUR=0x00000013;
> > RTC_DOM=0x00000006;
> > RTC_DOW=0x00000004;
> > RTC_DOY=0x00000004;
> > RTC_MONTH=0x00000001;
> > RTC_YEAR=0x000007D5;
> > //alarm setting
> > RTC_ALSEC=0x00000001;
> > RTC_ALMIN=0x00000001;
> > RTC_ALHOUR=0x00000001;
> > RTC_ALDOM=0x00000001;
> > RTC_ALDOW=0x00000001;
> > RTC_ALDOY=0x00000001;
> > RTC_ALMON=0x00000001;
> > RTC_ALYEAR=0x000007D0;
> > //start rtc
> > RTC_CCR=0x00000001;
> >
> > contador=0x00;
> > IOSET = LED2;
> > IOSET = LED3;
> > printf ("Ezequiel L. Acetp %c%c",'\n','\r');
> > //printf("Ezequiel L. Aceto\n");
> > //printf("Sunixs Microsystems\n");
> > while(1)
> > {
> > IOSET = LED1;
> > delayus(1000); //0.5 Sec delay
> > IOCLR = LED1;
> > delayus(1000);
> > Hour = RTC_HOUR;
> > Min = RTC_MIN;
> > Sec = RTC_SEC;
> > printf("%2d : %2d : %2d ",Hour, Min, Sec,'\n','\r');
> > Hour = 0x00;
> > Min = 0x00;
> > Sec = 0x00;
> > }
> > }




Hi Ezequiel,

you find the formulas in the User Manual (Chapter 15,
Reference clock divider).

For a 60 MHz PCLK you obtain:

RTC_PREINT = int( 60e6/32768 ) - 1 = 1830
RTC_PREFRAC = 60e6 - ((1830 + 1) * 32768) = 1792

For the widely used 14.7456 MHz crystal, where you can
set CCLK and PCLK to 58.9824 MHz, you obtain
RTC_PREINT99, RTC_PREFRAC=0

Cheers,
Rolf --- acetoel <> wrote:

>
> Ups... I didn't do that... how can I set it up, if I
> have a PCLK and
> CCLK of 60Mhz?
> Thanks
> Ezequiel
>
> --- In , "lpc_bavaria"
> <lpc_bavaria@y...> wrote:
> >
> > Hi Ezequiel,
> >
> > have you set the prescaler registers RTC_PREINT
> and RTC_PREFRAC to
> > divide down your pclk to 32.768 kHz?
> >
> > Cheers,
> > Rolf
> >
> >
> > --- In , "acetoel"
> <acetoel@y...> wrote:
> > >
> > > Hello, I have set up the RTC and make a simple
> program to test it. But
> > > it doesn't work! Here is the code... on the PC
> (connected to the
> > > serial port) I always view the same time 19:8:51
> > > Thanks
> > > Ezequiel
> > >
> > > #include "LPC210x.h"
> > > #include "Init.h"
> > > #include "UART.h"
> > > #include "Delayus.h"
> > >
> > > #define Boton 0x80000000
> > > #define LED1 0x10000000
> > > #define LED2 0x20000000
> > > #define LED3 0x40000000
> > >
> > > UInt8 contador;
> > > UInt16 Counter2;
> > > UInt32 Hour,Min,Sec;
> > >
> > >
> > > int main (void)
> > > {
> > > /*Initialize the system*/
> > > InitLPC2106();
> > > InitCom(); //115200 bauds
> > > IODIR=0x70000000;
> > > IOCLR=0x70000000;
> > >
> > > RTC_CCR=0;
> > > RTC_CIIR=0x00000000;
> > > RTC_AMR=0x00000000;
> > > //real date time setting
> > > RTC_SEC=0x00000033;
> > > RTC_MIN=0x00000008;
> > > RTC_HOUR=0x00000013;
> > > RTC_DOM=0x00000006;
> > > RTC_DOW=0x00000004;
> > > RTC_DOY=0x00000004;
> > > RTC_MONTH=0x00000001;
> > > RTC_YEAR=0x000007D5;
> > > //alarm setting
> > > RTC_ALSEC=0x00000001;
> > > RTC_ALMIN=0x00000001;
> > > RTC_ALHOUR=0x00000001;
> > > RTC_ALDOM=0x00000001;
> > > RTC_ALDOW=0x00000001;
> > > RTC_ALDOY=0x00000001;
> > > RTC_ALMON=0x00000001;
> > > RTC_ALYEAR=0x000007D0;
> > > //start rtc
> > > RTC_CCR=0x00000001;
> > >
> > > contador=0x00;
> > > IOSET = LED2;
> > > IOSET = LED3;
> > > printf ("Ezequiel L. Acetp %c%c",'\n','\r');
> > > //printf("Ezequiel L. Aceto\n");
> > > //printf("Sunixs Microsystems\n");
> > > while(1)
> > > {
> > > IOSET = LED1;
> > > delayus(1000); //0.5 Sec delay
> > > IOCLR = LED1;
> > > delayus(1000);
> > > Hour = RTC_HOUR;
> > > Min = RTC_MIN;
> > > Sec = RTC_SEC;
> > > printf("%2d : %2d : %2d ",Hour, Min,
> Sec,'\n','\r');
> > > Hour = 0x00;
> > > Min = 0x00;
> > > Sec = 0x00;
> > > }
> > > } >
>


__________________________________________________





This looks like the code from our Beta compiler's AppBuilder? If so, the
next release has that fixed...

>--- acetoel <> wrote:
>
> >
> > Ups... I didn't do that... how can I set it up, if I
> > have a PCLK and
> > CCLK of 60Mhz?
> > Thanks
> > Ezequiel
>

// richard (This email is for mailing lists. To reach me directly, please
use richard at imagecraft.com)




In fact, I'm testing some of my GCC code with the beta of Imagecraft.
And also using the AppBuilder. This is the first bug I found in ICC
ARM. The AppBuilder doesn't set the RTC Clock.
See you
Ezequiel

--- In , Richard <richard-lists@i...> wrote:
> This looks like the code from our Beta compiler's AppBuilder? If so,
the
> next release has that fixed...
>
> >--- acetoel <acetoel@y...> wrote:
> >
> > >
> > > Ups... I didn't do that... how can I set it up, if I
> > > have a PCLK and
> > > CCLK of 60Mhz?
> > > Thanks
> > > Ezequiel
> > >
> >
> >
>
> // richard (This email is for mailing lists. To reach me directly,
please
> use richard at imagecraft.com)