EmbeddedRelated.com
Forums

WOrking of RTC in LPC2148

Started by raju_nem October 28, 2009
HI

i need to use rtc of lpc2148.For every sec, i need to send the time to Hyperterminal.I am using gcc compiler.i searched sample codes.Those are

not working.Any one worked on RTC of lpc2148? help me ,thanks in advance.

An Engineer's Guide to the LPC2100 Series

OK leave the interrupt section.Basic (only) rtc functions i am posting here.plz help whether any thing wrong in the code?thanks in advance.

#include "LPC2148.h"
#include "UART0.h"
#include "pll.h"
#define PCLK 60000000
#define T0_PCLK_DIV 3
#define GERMAN

#ifdef GERMAN
//char* const gWeekDays[] = {"Mo","Di","Mi","Do","Fr","Sa","So"};
char* const gWeekDays[] = {"Mo","Tu","We","Th","Fr","Sa","Su"};
#else
char* const gWeekDays[] = {"Mo","Tu","We","Th","Fr","Sa","So"};
#endif
typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned long uint32_t;
typedef signed long int32_t;
typedef unsigned long long uint64_t;
typedef signed long long int64_t;

struct tTimestamp {
uint16_t y;
uint8_t mo;
uint8_t d;
uint8_t h;
uint8_t mi;
uint8_t s;
uint8_t dow;
};

void def_isr(void)
{
Tx_string("Unknown interrupt");
VICVECTADDR = 0x00000000; //Dummy write to signal end of interrupt
}
void intilalize_timer(void)
{

T0TCR = 0x02; // reset & disable timer 0
T0PR = 2; // set the prescale divider
T0MCR = 0; // disable match registers
T0EMR = 0; // disable external match register
T0TCR = 0x01; // enable timer 0
// sysTICs = 0;///////
}

static void sysInit(void)
{
PLL_init(); // intialization of PLL and PCLK IS 60mhz

VICINTENCLEAR = 0xFFFFFFFF; // clear all interrupts
VICINTSELECT = 0x00000000; // clear all FIQ selections
VICDEFVECTADDR = (uint32_t)def_isr; // point unvectored IRQs to reset()

intilalize_timer(); // initialize the system timer
}

void RTC_InitHardware(void)
{
AMR = 0; //alarm mask register to control the alarm registers
CIIR = 0; //count increment register tells the when interrupt will be generated when count increments
PREINT =((PCLK/32768)-1));
PREFRAC =(( PCLK) − ((PREINT + 1) 32768)); //prescaler fraction register PREFRAC = PCLK − ((PREINT + 1) 32768)

CCR = 0x02; //Reset value in Clock Tick Counter (CTC)
CCR = 0x01; // disabale CTC-Reset and enable clock with CLKEN
}
void RTC_SetDOW(uint8_t dow)
{
DOW = (uint32_t)dow;
}

void RTC_SetDate(uint8_t d, uint8_t mo, uint16_t y)
{
DOM = (uint32_t)d;
MONTH = (uint32_t)mo;
YEAR = (uint32_t)y;
}

void RTC_SetTime(uint8_t h, uint8_t m, uint8_t s)
{
CCR = 0x20;// Reset value in Clock Tick Counter (CTC) and disable clock
SEC = (uint32_t)s;
MIN = (uint32_t)m;
HOUR= (uint32_t)h;
CCR = 0x01; //re-enable RTC
}
void RTC_GetTime(struct tTimestamp *ts)
{
ts->s = (uint8_t)SEC;
ts->mi = (uint8_t)MIN;
ts->h = (uint8_t)HOUR;
ts->d = (uint8_t)DOM;
ts->mo = (uint8_t)MONTH;
ts->y = (uint16_t)YEAR;
ts->dow= (uint8_t)DOW;
}
static void show_clock(uint8_t second_mode)
{
struct tTimestamp ts;
char s[4];


s[2]='\0';
RTC_GetTime(&ts);


}

int main()
{


char work_string[40];

uint8_t oldSecond=0xff, actSecond;

sysInit();

PINSEL0 = 0x00000005;
InitUart0();
Tx_string("WELCOME TO SERIAL PORT DEMO\n");
RTC_InitHardware();
RTC_SetDOW(2);
RTC_SetDate(29,10,2009);
RTC_SetTime(00,00,30);
for(;;)
{
actSecond = (uint8_t)SEC;
if(actSecond != oldSecond)
{
oldSecond = actSecond;
work_string[0] = '\0';
show_clock(2);

}
}
}

uart and PLL code is fine.Problem in above code only.Help me who have worked on RTC.

--- In l..., "raju_nem" wrote:
>
>
>
> HI
>
> i need to use rtc of lpc2148.For every sec, i need to send the time to Hyperterminal.I am using gcc compiler.i searched sample codes.Those are
>
> not working.Any one worked on RTC of lpc2148? help me ,thanks in advance.
>

Here's a very simple test program of mine:

/*
** RTC.c
** Test program for LPC2148 RTC
*/

// Include files

#include
#include
// #defines

#define LF 0x0A
#define CR 0x0D

// Function prototypes

int main(void);
void Initialise(void);

//----------------------- main ----------------------------//

int main(void)
{
Initialise(); // initialisation stuff

// LED off
IO0SET = IO0SET |= (1 << 8);

SEC = MIN = HOUR = 0;
T0IR = 0x10;
T0IR |= 0x01;
asm("nop");

while(1)
{
debug_printf("\n%d %d %d", HOUR, MIN, SEC);

asm("nop");

}

}

//-------------------- initialisation stuff --------------------//

void Initialise(void)
{
// initialise PLL

PLL0CFG=0x24; // Cclk = 60Mhz
PLL0CON=0x01;
PLL0FEED=0xAA;
PLL0FEED=0x55;
while(!(PLL0STAT & 0x0400))
;
PLL0CON=0x3;
PLL0FEED=0xAA;
PLL0FEED=0x55;

// initialise MAM and VPB

MAMTIM=0x3; // 3 cycles to read from FLASH
MAMCR=0x2;
APBDIV=0x02; // Pclk = 30MHz

// initialise RTC

ILR = 3; // Disable 32768 kHz interrupt

CCR = 0x11; // enable time counters, 32768 kHz oscillator

// initialise GPIOs

IO0DIR = IO0DIR | 1 << 8; //P0.8 output
}

Leon

Hi leon Heller,

is sample code working fine?

For interfacing RTC,Memory accelaration module(MAM) is compulsory?

--- In l..., "leon Heller" wrote:
>
> Here's a very simple test program of mine:
>
> /*
> ** RTC.c
> ** Test program for LPC2148 RTC
> */
>
> // Include files
>
> #include
> #include
> // #defines
>
> #define LF 0x0A
> #define CR 0x0D
>
> // Function prototypes
>
> int main(void);
> void Initialise(void);
>
> //----------------------- main ----------------------------//
>
> int main(void)
> {
> Initialise(); // initialisation stuff
>
> // LED off
> IO0SET = IO0SET |= (1 << 8);
>
> SEC = MIN = HOUR = 0;
> T0IR = 0x10;
> T0IR |= 0x01;
> asm("nop");
>
> while(1)
> {
> debug_printf("\n%d %d %d", HOUR, MIN, SEC);
>
> asm("nop");
>
> }
>
> }
>
> //-------------------- initialisation stuff --------------------//
>
> void Initialise(void)
> {
> // initialise PLL
>
> PLL0CFG=0x24; // Cclk = 60Mhz
> PLL0CON=0x01;
> PLL0FEED=0xAA;
> PLL0FEED=0x55;
> while(!(PLL0STAT & 0x0400))
> ;
> PLL0CON=0x3;
> PLL0FEED=0xAA;
> PLL0FEED=0x55;
>
> // initialise MAM and VPB
>
> MAMTIM=0x3; // 3 cycles to read from FLASH
> MAMCR=0x2;
> APBDIV=0x02; // Pclk = 30MHz
>
> // initialise RTC
>
> ILR = 3; // Disable 32768 kHz interrupt
>
> CCR = 0x11; // enable time counters, 32768 kHz oscillator
>
> // initialise GPIOs
>
> IO0DIR = IO0DIR | 1 << 8; //P0.8 output
> }
>
> Leon
>

there is problem in this code- it is in finite loop by printing "rtc init hardware is over2" i am using the messages for debugging puprpose.what is wrong in this RTC code? help thanks in advance

#include "LPC2148.h"
#include "UART0.h"
#include "pll.h"
#define PCLK 60000000
#define T0_PCLK_DIV 3
#define NOW 1792

typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned long uint32_t;
typedef signed long int32_t;
typedef unsigned long long uint64_t;
typedef signed long long int64_t;

struct tTimestamp {
uint16_t y;
uint8_t mo;
uint8_t d;
uint8_t h;
uint8_t mi;
uint8_t s;
uint8_t dow;
};

void def_isr(void)
{
Tx_string("Unknown interrupt");
VICVECTADDR = 0x00000000; //Dummy write to signal end of interrupt
}
void intilalize_timer(void)
{

T0TCR = 0x02; // reset & disable timer 0
T0PR = 2; // set the prescale divider
T0MCR = 0; // disable match registers
T0EMR = 0; // disable external match register
T0TCR = 0x01; // enable timer 0
// sysTICs = 0;///////
}

static void sysInit(void)
{
PLL_init(); // intialization of PLL and PCLK IS 60mhz

VICINTENCLEAR = 0xFFFFFFFF; // clear all interrupts
VICINTSELECT = 0x00000000; // clear all FIQ selections
VICDEFVECTADDR = (uint32_t)def_isr; // point unvectored IRQs to reset()

intilalize_timer(); // initialize the system timer
}

void RTC_InitHardware(void)
{
AMR = 0; //alarm mask register to control the alarm registers
CIIR = 0; //count increment register tells the when interrupt will be generated when count increments
PREINT =1830;
PREFRAC =NOW; //prescaler fraction register PREFRAC = PCLK - ((PREINT + 1) × 32768)

CCR = 0x02; //Reset value in Clock Tick Counter (CTC)
CCR = 0x01; // disabale CTC-Reset and enable clock with CLKEN
}
void RTC_SetDOW(uint8_t dow)
{
DOW = (uint32_t)dow;
}

void RTC_SetDate(uint8_t d, uint8_t mo, uint16_t y)
{
DOM = (uint32_t)d;
MONTH = (uint32_t)mo;
YEAR = (uint32_t)y;
}

void RTC_SetTime(uint8_t h, uint8_t m, uint8_t s)
{
CCR = 0x20;// Reset value in Clock Tick Counter (CTC) and disable clock
SEC = (uint32_t)s;
MIN = (uint32_t)m;
HOUR= (uint32_t)h;
CCR = 0x01; //re-enable RTC
}
void RTC_GetTime(struct tTimestamp *ts)
{
ts->s = (uint8_t)SEC;
ts->mi = (uint8_t)MIN;
ts->h = (uint8_t)HOUR;
ts->d = (uint8_t)DOM;
ts->mo = (uint8_t)MONTH;
ts->y = (uint16_t)YEAR;
ts->dow= (uint8_t)DOW;
Tx_string("rtc init hardware is over4\n");
Tx_char(ts->s);
Tx_char(ts->mi);
Tx_string("rtc init hardware is over5\n");
}
static void show_clock(uint8_t second_mode)
{
struct tTimestamp ts;
char s[4];


s[2]='\0';
RTC_GetTime(&ts);


}

int main()
{


char work_string[40];

uint8_t oldSecond=0xff, actSecond;

sysInit();

PINSEL0 = 0x00000005;
InitUart0();
Tx_string("WELCOME TO SERIAL PORT DEMO\n");
RTC_InitHardware();
Tx_string("rtc init hardware is over\n");
RTC_SetDOW(2);
RTC_SetDate(29,10,2009);
RTC_SetTime(14,52,30);
Tx_string("rtc init hardware is over1\n");
for(;;)
{
actSecond = (uint8_t)SEC;
Tx_string("rtc init hardware is over2\n");
if(actSecond != oldSecond)
{
oldSecond = actSecond;
work_string[0] = '\0';
Tx_string("rtc init hardware is over3\n");
show_clock(2);

}
}
}

Tx_char and Tx_string are functions to display the messages or character.

what are the steps to follow while use of INTERNAL rtc of lpc2148?
help me.

--- In l..., "raju_nem" wrote:
>
>
> Hi leon Heller,
>
> is sample code working fine?
>
> For interfacing RTC,Memory accelaration module(MAM) is compulsory?
>
> --- In l..., "leon Heller" wrote:
> >
> > Here's a very simple test program of mine:
> >
> > /*
> > ** RTC.c
> > ** Test program for LPC2148 RTC
> > */
> >
> > // Include files
> >
> > #include
> > #include
> >
> >
> > // #defines
> >
> > #define LF 0x0A
> > #define CR 0x0D
> >
> > // Function prototypes
> >
> > int main(void);
> > void Initialise(void);
> >
> >
> >
> > //----------------------- main ----------------------------//
> >
> > int main(void)
> > {
> > Initialise(); // initialisation stuff
> >
> > // LED off
> > IO0SET = IO0SET |= (1 << 8);
> >
> > SEC = MIN = HOUR = 0;
> >
> >
> > T0IR = 0x10;
> > T0IR |= 0x01;
> >
> >
> > asm("nop");
> >
> > while(1)
> > {
> > debug_printf("\n%d %d %d", HOUR, MIN, SEC);
> >
> > asm("nop");
> >
> > }
> >
> > }
> >
> >
> >
> > //-------------------- initialisation stuff --------------------//
> >
> > void Initialise(void)
> > {
> > // initialise PLL
> >
> > PLL0CFG=0x24; // Cclk = 60Mhz
> > PLL0CON=0x01;
> > PLL0FEED=0xAA;
> > PLL0FEED=0x55;
> > while(!(PLL0STAT & 0x0400))
> > ;
> > PLL0CON=0x3;
> > PLL0FEED=0xAA;
> > PLL0FEED=0x55;
> >
> > // initialise MAM and VPB
> >
> > MAMTIM=0x3; // 3 cycles to read from FLASH
> > MAMCR=0x2;
> > APBDIV=0x02; // Pclk = 30MHz
> >
> > // initialise RTC
> >
> > ILR = 3; // Disable 32768 kHz interrupt
> >
> > CCR = 0x11; // enable time counters, 32768 kHz oscillator
> >
> > // initialise GPIOs
> >
> > IO0DIR = IO0DIR | 1 << 8; //P0.8 output
> > }
> >
> > Leon
>

It would be much easier to use the RTC's CIIR register (see LPC2148 user manual).

Then Google for a suitable example eg "LPC2148 CIIR"

Remember "Google" is your best friend!

________________________________

From: l... [mailto:l...] On Behalf Of raju_nem
Sent: 29 October 2009 10:01
To: l...
Subject: [lpc2000] Re: WOrking of RTC in LPC2148


there is problem in this code- it is in finite loop by printing "rtc init hardware is over2" i am using the messages for debugging puprpose.what is wrong in this RTC code? help thanks in advance

#include "LPC2148.h"
#include "UART0.h"
#include "pll.h"

#define PCLK 60000000
#define T0_PCLK_DIV 3
#define NOW 1792

typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned long uint32_t;
typedef signed long int32_t;
typedef unsigned long long uint64_t;
typedef signed long long int64_t;

struct tTimestamp {
uint16_t y;
uint8_t mo;
uint8_t d;
uint8_t h;
uint8_t mi;
uint8_t s;
uint8_t dow;
};

void def_isr(void)
{
Tx_string("Unknown interrupt");
VICVECTADDR = 0x00000000; //Dummy write to signal end of interrupt
}
void intilalize_timer(void)
{

T0TCR = 0x02; // reset & disable timer 0
T0PR = 2; // set the prescale divider
T0MCR = 0; // disable match registers
T0EMR = 0; // disable external match register
T0TCR = 0x01; // enable timer 0
// sysTICs = 0;///////
}

static void sysInit(void)
{
PLL_init(); // intialization of PLL and PCLK IS 60mhz

VICINTENCLEAR = 0xFFFFFFFF; // clear all interrupts
VICINTSELECT = 0x00000000; // clear all FIQ selections
VICDEFVECTADDR = (uint32_t)def_isr; // point unvectored IRQs to reset()

intilalize_timer(); // initialize the system timer
}

void RTC_InitHardware(void)
{
AMR = 0; //alarm mask register to control the alarm registers
CIIR = 0; //count increment register tells the when interrupt will be generated when count increments
PREINT =1830;
PREFRAC =NOW; //prescaler fraction register PREFRAC = PCLK - ((PREINT + 1) 32768)

CCR = 0x02; //Reset value in Clock Tick Counter (CTC)
CCR = 0x01; // disabale CTC-Reset and enable clock with CLKEN
}
void RTC_SetDOW(uint8_t dow)
{
DOW = (uint32_t)dow;
}

void RTC_SetDate(uint8_t d, uint8_t mo, uint16_t y)
{
DOM = (uint32_t)d;
MONTH = (uint32_t)mo;
YEAR = (uint32_t)y;
}

void RTC_SetTime(uint8_t h, uint8_t m, uint8_t s)
{
CCR = 0x20;// Reset value in Clock Tick Counter (CTC) and disable clock
SEC = (uint32_t)s;
MIN = (uint32_t)m;
HOUR= (uint32_t)h;
CCR = 0x01; //re-enable RTC
}
void RTC_GetTime(struct tTimestamp *ts)
{
ts->s = (uint8_t)SEC;
ts->mi = (uint8_t)MIN;
ts->h = (uint8_t)HOUR;
ts->d = (uint8_t)DOM;
ts->mo = (uint8_t)MONTH;
ts->y = (uint16_t)YEAR;
ts->dow= (uint8_t)DOW;
Tx_string("rtc init hardware is over4\n");
Tx_char(ts->s);
Tx_char(ts->mi);
Tx_string("rtc init hardware is over5\n");
}
static void show_clock(uint8_t second_mode)
{
struct tTimestamp ts;
char s[4];
s[2]='\0';
RTC_GetTime(&ts);
}

int main()
{

char work_string[40];

uint8_t oldSecond=0xff, actSecond;

sysInit();

PINSEL0 = 0x00000005;
InitUart0();
Tx_string("WELCOME TO SERIAL PORT DEMO\n");
RTC_InitHardware();
Tx_string("rtc init hardware is over\n");
RTC_SetDOW(2);
RTC_SetDate(29,10,2009);
RTC_SetTime(14,52,30);
Tx_string("rtc init hardware is over1\n");
for(;;)
{
actSecond = (uint8_t)SEC;
Tx_string("rtc init hardware is over2\n");
if(actSecond != oldSecond)
{
oldSecond = actSecond;
work_string[0] = '\0';
Tx_string("rtc init hardware is over3\n");
show_clock(2);

}
}
}

Tx_char and Tx_string are functions to display the messages or character.

what are the steps to follow while use of INTERNAL rtc of lpc2148?
help me.

--- In l... , "raju_nem" wrote:
>
>
> Hi leon Heller,
>
> is sample code working fine?
>
> For interfacing RTC,Memory accelaration module(MAM) is compulsory?
>
> --- In l... , "leon Heller" wrote:
> >
> > Here's a very simple test program of mine:
> >
> > /*
> > ** RTC.c
> > ** Test program for LPC2148 RTC
> > */
> >
> > // Include files
> >
> > #include
> > #include
> >
> >
> > // #defines
> >
> > #define LF 0x0A
> > #define CR 0x0D
> >
> > // Function prototypes
> >
> > int main(void);
> > void Initialise(void);
> >
> >
> >
> > //----------------------- main ----------------------------//
> >
> > int main(void)
> > {
> > Initialise(); // initialisation stuff
> >
> > // LED off
> > IO0SET = IO0SET |= (1 << 8);
> >
> > SEC = MIN = HOUR = 0;
> >
> >
> > T0IR = 0x10;
> > T0IR |= 0x01;
> >
> >
> > asm("nop");
> >
> > while(1)
> > {
> > debug_printf("\n%d %d %d", HOUR, MIN, SEC);
> >
> > asm("nop");
> >
> > }
> >
> > }
> >
> >
> >
> > //-------------------- initialisation stuff --------------------//
> >
> > void Initialise(void)
> > {
> > // initialise PLL
> >
> > PLL0CFG=0x24; // Cclk = 60Mhz
> > PLL0CON=0x01;
> > PLL0FEED=0xAA;
> > PLL0FEED=0x55;
> > while(!(PLL0STAT & 0x0400))
> > ;
> > PLL0CON=0x3;
> > PLL0FEED=0xAA;
> > PLL0FEED=0x55;
> >
> > // initialise MAM and VPB
> >
> > MAMTIM=0x3; // 3 cycles to read from FLASH
> > MAMCR=0x2;
> > APBDIV=0x02; // Pclk = 30MHz
> >
> > // initialise RTC
> >
> > ILR = 3; // Disable 32768 kHz interrupt
> >
> > CCR = 0x11; // enable time counters, 32768 kHz oscillator
> >
> > // initialise GPIOs
> >
> > IO0DIR = IO0DIR | 1 << 8; //P0.8 output
> > }
> >
> > Leon
>



Thank you,i understood little bit more with u r information.I read the lpc2148 RTC manual.I am trying to use the PCLK(peripheral clock) as a clock source for RTC.
What are the values we need to write in to Prescale inter (PREINT) and prescale fractional register(PREFRAC) registers if i use 60MHZ (PLCK) clock.

from manual i understood that,

PREINT = int (PCLK / 32768) #039; 1.

PREFRAC = PCLK #039; ((PREINT + 1) × 32768).
I am using 60MHZ as PCLK then,PREINT =((60000000/32768)-1)=1830 in hexadecimal it is 0x726.
PREFRAC=(60000000) #039; ((1831 + 1) × 32768).

is this correct? if wrong,plz help me thank in advance.
One more doubt is
void Initialize_RTC()
{

CCR=0x2; /* Reset the clock */

ILR=0x3; /* Clear the Interrupt Location Register */

CIIR=0x01;

HOUR=0x0;

SEC=0x0;

MIN=0x0;

PREINT = 0x726;; some doubt on this?

PREFRAC = 0x700; some doubt on this?

VICINTSELECT=0x00000000;

VICVECTADDR0=(unsigned long )readRTC_irq;

VICVECTCNTL0=0x2d;

VICINTENABLE =0x2000;

}

THE last line VICINTENABLE =0x2000; is not excuting.i tried.what may be problem here.Help me thanks in advance.
--- In l..., "Toby Harris" wrote:
>
> It would be much easier to use the RTC's CIIR register (see LPC2148 user manual).
>
> Then Google for a suitable example eg "LPC2148 CIIR"
>
> Remember "Google" is your best friend!
>
> ________________________________
>
> From: l... [mailto:l...] On Behalf Of raju_nem
> Sent: 29 October 2009 10:01
> To: l...
> Subject: [lpc2000] Re: WOrking of RTC in LPC2148
>
>
>
>
> there is problem in this code- it is in finite loop by printing "rtc init hardware is over2" i am using the messages for debugging puprpose.what is wrong in this RTC code? help thanks in advance
>
> #include "LPC2148.h"
> #include "UART0.h"
> #include "pll.h"
>
> #define PCLK 60000000
> #define T0_PCLK_DIV 3
> #define NOW 1792
>
> typedef unsigned char uint8_t;
> typedef signed char int8_t;
> typedef unsigned short uint16_t;
> typedef signed short int16_t;
> typedef unsigned long uint32_t;
> typedef signed long int32_t;
> typedef unsigned long long uint64_t;
> typedef signed long long int64_t;
>
> struct tTimestamp {
> uint16_t y;
> uint8_t mo;
> uint8_t d;
> uint8_t h;
> uint8_t mi;
> uint8_t s;
> uint8_t dow;
> };
>
> void def_isr(void)
> {
> Tx_string("Unknown interrupt");
> VICVECTADDR = 0x00000000; //Dummy write to signal end of interrupt
> }
> void intilalize_timer(void)
> {
>
> T0TCR = 0x02; // reset & disable timer 0
> T0PR = 2; // set the prescale divider
> T0MCR = 0; // disable match registers
> T0EMR = 0; // disable external match register
> T0TCR = 0x01; // enable timer 0
> // sysTICs = 0;///////
> }
>
> static void sysInit(void)
> {
> PLL_init(); // intialization of PLL and PCLK IS 60mhz
>
> VICINTENCLEAR = 0xFFFFFFFF; // clear all interrupts
> VICINTSELECT = 0x00000000; // clear all FIQ selections
> VICDEFVECTADDR = (uint32_t)def_isr; // point unvectored IRQs to reset()
>
> intilalize_timer(); // initialize the system timer
> }
>
> void RTC_InitHardware(void)
> {
> AMR = 0; //alarm mask register to control the alarm registers
> CIIR = 0; //count increment register tells the when interrupt will be generated when count increments
> PREINT =1830;
> PREFRAC =NOW; //prescaler fraction register PREFRAC = PCLK - ((PREINT + 1) �- 32768)
>
> CCR = 0x02; //Reset value in Clock Tick Counter (CTC)
> CCR = 0x01; // disabale CTC-Reset and enable clock with CLKEN
> }
> void RTC_SetDOW(uint8_t dow)
> {
> DOW = (uint32_t)dow;
> }
>
> void RTC_SetDate(uint8_t d, uint8_t mo, uint16_t y)
> {
> DOM = (uint32_t)d;
> MONTH = (uint32_t)mo;
> YEAR = (uint32_t)y;
> }
>
> void RTC_SetTime(uint8_t h, uint8_t m, uint8_t s)
> {
> CCR = 0x20;// Reset value in Clock Tick Counter (CTC) and disable clock
> SEC = (uint32_t)s;
> MIN = (uint32_t)m;
> HOUR= (uint32_t)h;
> CCR = 0x01; //re-enable RTC
> }
> void RTC_GetTime(struct tTimestamp *ts)
> {
> ts->s = (uint8_t)SEC;
> ts->mi = (uint8_t)MIN;
> ts->h = (uint8_t)HOUR;
> ts->d = (uint8_t)DOM;
> ts->mo = (uint8_t)MONTH;
> ts->y = (uint16_t)YEAR;
> ts->dow= (uint8_t)DOW;
> Tx_string("rtc init hardware is over4\n");
> Tx_char(ts->s);
> Tx_char(ts->mi);
> Tx_string("rtc init hardware is over5\n");
> }
> static void show_clock(uint8_t second_mode)
> {
> struct tTimestamp ts;
> char s[4];
>
>
> s[2]='\0';
> RTC_GetTime(&ts);
>
>
> }
>
> int main()
> {
>
> char work_string[40];
>
> uint8_t oldSecond=0xff, actSecond;
>
> sysInit();
>
> PINSEL0 = 0x00000005;
> InitUart0();
> Tx_string("WELCOME TO SERIAL PORT DEMO\n");
> RTC_InitHardware();
> Tx_string("rtc init hardware is over\n");
> RTC_SetDOW(2);
> RTC_SetDate(29,10,2009);
> RTC_SetTime(14,52,30);
> Tx_string("rtc init hardware is over1\n");
> for(;;)
> {
> actSecond = (uint8_t)SEC;
> Tx_string("rtc init hardware is over2\n");
> if(actSecond != oldSecond)
> {
> oldSecond = actSecond;
> work_string[0] = '\0';
> Tx_string("rtc init hardware is over3\n");
> show_clock(2);
>
> }
> }
> }
>
> Tx_char and Tx_string are functions to display the messages or character.
>
> what are the steps to follow while use of INTERNAL rtc of lpc2148?
> help me.
>
> --- In l... , "raju_nem" wrote:
> >
> >
> > Hi leon Heller,
> >
> > is sample code working fine?
> >
> > For interfacing RTC,Memory accelaration module(MAM) is compulsory?
> >
> > --- In l... , "leon Heller" wrote:
> > >
> > > Here's a very simple test program of mine:
> > >
> > > /*
> > > ** RTC.c
> > > ** Test program for LPC2148 RTC
> > > */
> > >
> > > // Include files
> > >
> > > #include
> > > #include
> > >
> > >
> > > // #defines
> > >
> > > #define LF 0x0A
> > > #define CR 0x0D
> > >
> > > // Function prototypes
> > >
> > > int main(void);
> > > void Initialise(void);
> > >
> > >
> > >
> > > //----------------------- main ----------------------------//
> > >
> > > int main(void)
> > > {
> > > Initialise(); // initialisation stuff
> > >
> > > // LED off
> > > IO0SET = IO0SET |= (1 << 8);
> > >
> > > SEC = MIN = HOUR = 0;
> > >
> > >
> > > T0IR = 0x10;
> > > T0IR |= 0x01;
> > >
> > >
> > > asm("nop");
> > >
> > > while(1)
> > > {
> > > debug_printf("\n%d %d %d", HOUR, MIN, SEC);
> > >
> > > asm("nop");
> > >
> > > }
> > >
> > > }
> > >
> > >
> > >
> > > //-------------------- initialisation stuff --------------------//
> > >
> > > void Initialise(void)
> > > {
> > > // initialise PLL
> > >
> > > PLL0CFG=0x24; // Cclk = 60Mhz
> > > PLL0CON=0x01;
> > > PLL0FEED=0xAA;
> > > PLL0FEED=0x55;
> > > while(!(PLL0STAT & 0x0400))
> > > ;
> > > PLL0CON=0x3;
> > > PLL0FEED=0xAA;
> > > PLL0FEED=0x55;
> > >
> > > // initialise MAM and VPB
> > >
> > > MAMTIM=0x3; // 3 cycles to read from FLASH
> > > MAMCR=0x2;
> > > APBDIV=0x02; // Pclk = 30MHz
> > >
> > > // initialise RTC
> > >
> > > ILR = 3; // Disable 32768 kHz interrupt
> > >
> > > CCR = 0x11; // enable time counters, 32768 kHz oscillator
> > >
> > > // initialise GPIOs
> > >
> > > IO0DIR = IO0DIR | 1 << 8; //P0.8 output
> > > }
> > >
> > > Leon
> > >
> >
>
>
>
>
>
>
>
>