This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTC SEC, MIN, HOUR etc don't increment (LPC2129)

Hello,

I've developed a simple program that sends current time/date to the serial port COM1. But on the gyper terminal I see that time is not being changed.
Could you give me a hand with it?
What is wrong in this code?

// ------------------------------------
#include <stdio.h>
#include <LPC21xx.H>
// Delay in ms
void delay_ms(long int ms)
{ long int i,j; for(i=0;i<ms;i++) for(j=0;j<6666;j++); //6653
}

// Start point
int main (void)
{ int year, month, day; int hour, min, sec;

/* initialize the serial interface */ PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */ U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */ U1LCR = 0x03; /* DLAB = 0 */

/* the 'printf' function call */ printf ("Hello World\n"); CCR = 0x0003; // CLKEN, CTCRST

/* When 1, the RTC is enabled. When 0, the RTC is disabled to conserve power. */
PCONP |= 0x20; //1 << 9;

while (1) { year = YEAR; month = MONTH; day = DOM; sec = SEC; min = MIN; hour = HOUR; printf("%d/%d/%d: %d:%d:%d - %d\n", day, month, year, hour, min, sec, ticks); delay_ms(100); }

Parents Reply Children
  • Ok. I've corrected my source code.

    // ------------------------------------
    #include <stdio.h>
    #include <LPC21xx.H>
    // Delay in ms
    void delay_ms(long int ms)
    {
      long int i,j;
      for(i=0;i<ms;i++)
       for(j=0;j<6666;j++); //6653
    }
    
    // Start point
    int main (void)
    {
      int year, month, day;
      int hour, min, sec;
    
    /* initialize the serial interface */
      PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
      U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
      U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
      U1LCR = 0x03; /* DLAB = 0 */
    
      /* the 'printf' function call */
      printf ("Hello World\n");
      CCR = 0x0003; // CLKEN, CTCRST
    
      /* When 1, the RTC is enabled. When 0, the RTC is disabled to conserve power. */
      PCONP |= 0x20; //1 << 9;
    
      while (1)
      {
       year = YEAR;
       month = MONTH;
       day = DOM;
       sec = SEC;
       min = MIN;
       hour = HOUR;
       printf("%d/%d/%d: %d:%d:%d - %d\n", day, month, year, hour, min, sec, ticks); delay_ms(100); }
    
    

  • Ok. I've corrected my source code.

    Thank you.

    /* When 1, the RTC is enabled. When 0, the RTC is disabled to conserve power. */
      PCONP |= 0x20; //1 << 9;
    

    The comment is correct, but the code does something else.

  •   PCONP |= 0x20; //1 << 9;
    

    If you want to enable the clock, don't you need to set the PCRCT bit?

    The quick look I've made suggests it's bit 9 of the PCONP register (as your comment suggests). So should the code be:

      PCONP |= (1 << 9);
    

    or

      PCONP |= 0x200;
    

  • Thank you for your response.
    Frankly, I tried it before:
    // ---
    PCONP |= 1 << 9;
    // ---

    But it still doesn't work.

  • PCRTC bit in PCONP doesn't help.
    I even tried to assign an ISR RTC, but there was no any success.
    Is it really enough to set CCR and and PCONP to read incremented values fro SEC, HOUR, MIN etc?

  • Hello Sergey Kryachko,

    In the usermanual for LPC2129 you find the description for RTC Clock Control Register. It says for bit CTCRST:

    CTC Reset. When one, the elements in the Clock Tick Counter are reset. The elements remain reset until CCR[1] is changed to zero. .

    You have to change your code to

      CCR = 0x0003;  // CLKEN, CTCRST
      CCR = 0x0001;  // CLKEN
    

    Best Regards,
    Martin Guenther

  • I appreciate your help.
    But the problem was in PREINT (Prescaler Integer Register) register value.
    In debug I descovered that PREINT is '0', but it must be greater than or equal to 1.

    Now it seems to work.

    Thank you.

  • Your remark about CCR = 0x01; is also important. If CCR has 0x03 (not 0x01) at the start of while cycle, it doesn't work.
    So your note helped me as well :)
    Thank you again.

  • Hello

    Can you help me to load the values in PREINT & PREFRAC registers of LPC2129 sothat the one sec in PC is equal to one sec in SEC register of RTC .

    I am using XTAL clock of 12Mhz,enabled PLL,VPBDIV.My current values of PREINT & PREFRAC are 0x0392 and 0x4380 respectively.Does anything else have to be done?

    regards
    xyz