RTC - How to get current time

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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));

   

 

   

}

0 Likes
13 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

    uint32 time;
    uint32 date;
    char timeBuffer[16u];
    char dateBuffer[16u];

   

 

   

You are missing these commands  time = RTC_GetTime(); and date = RTC_GetDate();

   

sprintf(timeBuffer,"%02u:%02u:%02u",RTC_GetHours(time),RTC_GetMinutes(time),RTC_GetSecond(time));

   

sprintf(dateBuffer,"%02u:%02u:%02u",RTC_GetMonth(date),RTC_GetDay(date),RTC_GetYear(date));

   

        UART_UartPutString(timeBuffer);
        UART_UartPutString("     |     ");
        UART_UartPutString(dateBuffer);
        UART_UartPutString("\r");
        CyDelay(200);

   

bobgoar

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

I'll Send you a complete program however it is for PSOC 4 not PSOC 5 but you can convert it.

0 Likes
Anonymous
Not applicable

When I add  time = RTC_GetTime() and date = RTC_GetDate(); , it says implicit declaration of function  'RTC_GetTime() ' is invalid in c99. 

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Bob Goars project using both functions compiles. What is your RTC component

   

named ?

   

 

   

RTC_ or RTC_1_, respectivley that would be RTC_GetTime( ) or RTC_1_GetTime().

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 I got RTC, not RTC_1, so I am doing it right.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

I tried the sample program you took your program from and it didn't update it had the same issue you experienced with your code.  I Am using a CY8CKit-059 Psoc 5 LP prototyping kit and after looking at the RTC for Psoc 4 and RTC for Psoc 5 and 3 they are different and use different code.  The PSOC 5 component needs a 32Khz crystal to function.  It is not loaded on the Cy8CKit -059 PSOC 5LP.  So the display reads out the orginal data that was loaded at the start of the program. I had this issue with the program I sent you as I left out the SyTickISRhandler and it was not updating .  So I must ask do you have a Crystal attached to your board?  By the way I added the Uart to the orginal code and it is displaying the date and time but no upate.

   

 

   

Also the code I sent will only work on a PSOC 4 and not the PSOC 5 I assumed that the RTC component was the same for both devices but it is not.

   

I have not tried it on an LCD display.

   

 

   

Bobgoar

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Ak B: your cann't use my code with the PSOC 5 Component as it program functions are completely different that is why you got the error of C99 function not found on the Get_time and date line.

   

 

   

Bobgoar

0 Likes
Anonymous
Not applicable

 I have found out that, my board hasn't crystal attached to chip, I am using below board.

   

http://www.powerfulboard.com/

   

Is there any way that I can configure crystal and get working ?

   

Thanks 

0 Likes
Anonymous
Not applicable

 Is there any board with crystal for Psoc5LP , that you know ? 

   

So, have you got your time updating with Cy8CKit -059 PSOC 5LP or it is still not working ?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

There are currently two (completely different) RTC components: One for PSoC4 (a new one) and one for PSoC5.

   

APIs are slightly different and in the PSoC5 version special a function concerning DST is missing. The 5s APIs are quite too many, so it is easy to make mistakes, but it is working correctly. Keep in mind that a watch crystal is needed, because the accuracy of the internal IMO is 1% which would mean you can be half a week off in a year, not only some minutes.

   

The actual CY8CKIT-050 has got a 32.768kHz xtal on board, so with that kit you will be fine off.

   

On the CY8CKIT-059 is room for an xtal at location Y1 where you may solder one.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I don't think the xtal is on board, from the CY8CKIT-059 user

   

manual -

   

 

   

 

   

   

 

   

Odd though, its shown in BOM ?

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Ahgrrr! Typo above - corrected. The CY8CKIT-050 has got an xtal.

   

 

   

Bob

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

The Crystal that is called out in the data sheet for the Cy8Ckit-059 5lp Prototyping kit is no longer available for purchase can you use a 12pf load cyrstal in its place?

0 Likes