LPC17xx RTC - incrementing all values in the clock and date values

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

LPC17xx RTC - incrementing all values in the clock and date values

748 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by teslabox on Wed Jun 27 02:59:58 MST 2012
Hi!

I run the RTC in my LPC1769 with the initial values (only zeros) of the clock and date values. I set the general interrupts from the RTC and I configured them to generate an interrupts each of the increment of the seconds value. In this interrupt function clock and date values are sent thru the UART0 to the RS232 terminal in my computer. But I notice that all of the values of the clock and of the date are incremented simultaneously as below:
 
Screen form the RS232 terminal:

Quote:
01 01 01 01 01 01  ......
02 02 02 02 02 02  ......
03 03 03 03 03 03  ......
04 04 04 04 04 04  ......
05 05 05 05 05 05  ......
06 06 06 06 06 06  ......
07 07 07 07 07 07  ......
08 08 08 08 08 08  ......
09 09 09 09 09 09  ......
0a 0a 0a 0a 0a 0a  ......
0b 0b 0b 0b 0b 0b  ......
0c 0c 0c 0c 0c 0c  ......
0d 0d 0d 0d 01 0d  ......
0e 0e 0e 0e 02 0e  ......
0f 0f 0f 0f 03 0f  ......
10 10 10 10 04 10  ......



I attached a simple ANSI C code which I use:
// Defines values for the RTC
#define HRS ((LPC_RTC->CTIME0) >> 16) & 0x1F    // Hour
#define MNS ((LPC_RTC->CTIME0) >>  8) & 0x3F    // Minute
#define SCS ((LPC_RTC->CTIME0) >>  0) & 0x3F    // Second
#define DAY ((LPC_RTC->CTIME1) >>  0) & 0x1F    // Day
#define MNT ((LPC_RTC->CTIME1) >>  8) & 0x0F    // Month
#define YRS ((LPC_RTC->CTIME1) >> 16) & 0xFFF    // Year
NVIC_EnableIRQ (RTC_IRQn);        // Set the RTC Interrupts
 
    LPC_GPIO1->FIODIR |= (1<<28);    // GPIO1.28 as a output pin with a LED
 
    LPC_SC->PCONP |= (1<<9);    // Set the power and the clock signal to the Real Time Clock
    LPC_RTC->CCR  |= (1<<0);    // Disable the RTC
    LPC_RTC->ILR  |= (1<<0);    // The Counter Increment Interrupt block generated an interrupt
    LPC_RTC->CIIR |= (1<<0);    // An increment of the Second value generates an interrupt
 
    LPC_RTC->HOUR  = 0;        // Set the hour
    LPC_RTC->MIN   = 0;        // Set the minutes
    LPC_RTC->SEC   = 0;        // Set the seconds
    LPC_RTC->DOM   = 0;        // Set the day of month
    LPC_RTC->MONTH = 0;        // Set the month
    LPC_RTC->YEAR  = 0;        // Set the year
 
    LPC_RTC->CCR  |= (1<<0);    // Enable the RTC
// Interrupt function for RTC
void RTC_IRQHandler (void)
{
    LPC_GPIO1->FIOPIN ^= (1<<28);    // Toggle LED
 
    UART0_SendByte (HRS);    // Send HOUR
    UART0_SendByte (MNS);    // Send MIN
    UART0_SendByte (SCS);    // Send SEC
    UART0_SendByte (DAY);    // Send DAY
    UART0_SendByte (MNT);    // Send MONTH
    UART0_SendByte (YRS);    // Send YEAR
 
    LPC_RTC->ILR |= (1<<0);    // Reset the interrupt
}
I can't find any misstake to fix it to work correct :|.
0 Kudos
Reply
3 Replies

486 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Jun 28 06:41:23 MST 2012

Quote: teslabox
What shall I do now?



Read #4 of http://knowledgebase.nxp.com/showthread.php?t=1928
0 Kudos
Reply

486 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by teslabox on Thu Jun 28 02:06:42 MST 2012
Thanks for help. It was just a stupid misstake. Below working C code:

    NVIC_EnableIRQ (RTC_IRQn);    // Set the RTC Interrupts

    LPC_GPIO1->FIODIR |= (1<<28);        // GPIO1.28 as a output pin with a LED
    LPC_GPIO2->FIODIR |= (1<<5)|(1<<6);   // GPIO1.28 as a output pin with a LED
    LPC_GPIO2->FIOSET |= (1<<5);
    LPC_GPIO2->FIOCLR |= (1<<6);

    LPC_SC->PCONP |= (1<<9);    // Set the power and the clock signal to the Real Time Clock

    LPC_RTC->CCR = 0;
    LPC_RTC->AMR = 0;
    LPC_RTC->CIIR = 0;
    LPC_RTC->CIIR |= (1<<0);    // An increment of the Second value generates an interrupt

    LPC_RTC->HOUR  =  9;        // Set the hour
    LPC_RTC->MIN   = 49;        // Set the minutes
    LPC_RTC->SEC   =  0;        // Set the seconds
    LPC_RTC->DOM   = 28;        // Set the day
    LPC_RTC->MONTH =  6;        // Set the month
    LPC_RTC->YEAR  = 12;        // Set the year

    LPC_RTC->CCR  |= (1<<0);    // Enable the RTC
But I run my RTC for an hour and I compared the RTC time to the Windows clock time and there is 4 min 9 sec diference per an hour [I](start at 09:48:00; end at 10:49:00 in Windows, 10:52:09 in RTC)[/I].
Why does it happen when the RTC is clocked by external 32 768 kHz clock crystal :/. What shall I do now?
0 Kudos
Reply

486 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Jun 27 04:25:59 MST 2012
Try:

http://knowledgebase.nxp.com/showthread.php?p=5479
0 Kudos
Reply