13 Replies Latest reply on Jul 8, 2015 9:36 AM by user_242978793

    RTC - How to get current time

    akshay.bha

      Hi there,

         

      Below is the code that I have got from sample example and modified as I require, but I am not able to get current time. Every time I read time after current time and some delay, it still reads the value that I have set to. So, what should I do to read current time and date ?

         

       

         

       int main()

         

      {

         

          int second,minute,hour = 0;

         

          int day,month,year = 0;

         

          RTC_TIME_DATE Start;

         

         

         

      /* Fill struct with date and time */

         

          Start.Sec = 55u;

         

          Start.Min = 55u;

         

          Start.Hour = 13u;

         

          Start.DayOfMonth = 7u;

         

          Start.Month = 7u;

         

          Start.Year = 2015u;

         

          CyGlobalIntEnable;

         

         RTC_WriteTime(&Start);

         

          

         

          RTC_Start(); 

         

            

         

          CyDelay(10000);

         

                 

         

          second = RTC_ReadSecond();

         

          minute = RTC_ReadMinute();

         

          hour = RTC_ReadHour();

         

          day = RTC_ReadDayOfMonth();

         

          month = RTC_ReadMonth();

         

          year = RTC_ReadYear();

         

          

         

          UART_PutString("Time: ");

         

          UART_PutString(itoa(hour,10));

         

          UART_PutString(":");

         

          UART_PutString(itoa(minute,10));

         

          UART_PutString(":");

         

          UART_PutString(itoa(second,10));

         

          

         

          UART_PutString("\nDate: ");

         

          UART_PutString(itoa(day,10));

         

          UART_PutString("-");

         

          UART_PutString(itoa(month,10));

         

          UART_PutString("-");

         

          UART_PutString(itoa(year,10));

         

       

         

      }