lpcware

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

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
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 :|.

Outcomes