Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Understanding Functionality of Cypress PSoC 4 RTC Library or C API Routines

Status
Not open for further replies.

vead

Full Member level 5
Joined
Nov 27, 2011
Messages
285
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
india
Activity points
3,815
hello

I need help to understand below statement
void RTC_Start(void)

Description:performs all the required calculations for the time and date registers and initializes the component along with the date and time selected in the customizer. If ‘Implement RTC update manually’ is disabled in the customizer and if WDT is selected as a source in the clocks configuration window (low frequency clocks tab), attaches the RTC_Update API to the corresponding WDT’s ISR callback.

Parameters:None

Return Value:None
Side Effects:None

void RTC_SetDateAndTime(uint32 time, uint32 date)

Description:Sets the time and date values as current time and date.

Parameters:
time: Time value in "HH:MM:SS" format.
date: Date value in format selected in customizer.

Return Value:None
Side Effects:None

void RTC_GetDateAndTime(RTC_DATE_TIME* dateTime)

Description: Reads the current time and date.
Parameters:
dateTime: Pointer to the RTC_date_time structure in which
Time and Date is returned.

Return Value:None

Side Effects:
None


I don't understand what is meaning of Parameters , and Return Value?
 
Last edited by a moderator:

what is mean of this statement

void RTC_SetAlarmDateAndTime(const RTC_date_time * alarmTime)
Description:
Writes the time and date values as current alarm time and date.

Parameters:
alarmTime: Pointer to the RTC_date_time global structure where new values of alarm time and date are stored.

Return Value:
None
 

Re: need help to understand some statements ?

1. function name is RTC_SetAlarmDateAndTime
2. it takes one parameter(sometimes called an argument) a pointer to a structure of type RTC_date_time
3. the function result is void, i.e. it returns no function result

for an example of use see post #11 of
https://www.cypress.com/forum/psoc-4-architecture/how-set-many-alarms
 
It would certainly facilitate those attempting to assist you by specifying the RTC or other device for which these C API routines are intend.

Also, can you upload or provide a link to the actual documentation from which your are copying and pasting these API descriptions?



Update:

I appreciate the detective work Horace.


BigDog
 

I have psoc kit. I am workong with rtc software component
when I use below code, I am seeing current date and time on LCD
I am attaching rtc datasheet

set time and date
get time and date
print time and date on LCD


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <project.h>
#include <stdio.h>
 
/* Time: 02:59:50 */
#define TIME_HOUR           (0x23u)
#define TIME_MIN            (0x59u)
#define TIME_SEC            (0x55u)
#define TIME_HR_MIN_SEC     ((uint32)(TIME_HOUR << RTC_HOURS_OFFSET) | \
                            (uint32)(TIME_MIN << RTC_MINUTES_OFFSET)    | \
                             TIME_SEC)
 
 
                            
/* Date: 03/22/2016 */
#define DATE_MONTH          (RTC_MARCH)
#define DATE_DAY            (0x22u)
#define DATE_YEAR           (0x2016u)
#define DATE_MONTH_DAY_YEAR ((uint32)(DATE_MONTH << RTC_MONTH_OFFSET)   | \
                            (uint32)(DATE_DAY << RTC_DAY_OFFSET)        | \
                             DATE_YEAR)        
 
#define SYSTICK_EACH_10_HZ  (10u)
#define SYSTICK_RELOAD      (CYDEV_BCLK__SYSCLK__HZ / SYSTICK_EACH_10_HZ)
 
/* Interrupt prototype */
CY_ISR_PROTO(SysTickIsrHandler);
 
 
int main()
{
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    char timeBuffer[16u];
    char dateBuffer[16u];
 
    uint32 time;
    uint32 date;
    uint32 i;
 
    /* Starts SysTick component */
    CySysTickStart();
 
    /* Configure SysTick timer to generate interrupt every 100 ms */
    CySysTickSetReload(SYSTICK_RELOAD);
 
    /* Find unused callback slot. */
    for (i = 0u; i < CY_SYS_SYST_NUM_OF_CALLBACKS; ++i)
    {
        if (CySysTickGetCallback(i) == NULL)
        {
            /* Set callback */
            CySysTickSetCallback(i, SysTickIsrHandler);
            break;
        }
    }
 
    /* Starts RTC component */
    RTC_Start();
    /* Start LCD */
    
    LCD_Start();
    
    /* Set Date and Time */
    RTC_SetDateAndTime(TIME_HR_MIN_SEC,DATE_MONTH_DAY_YEAR);
    
    
    
    
     
    /* Set RTC time update period */
    RTC_SetPeriod(1u, SYSTICK_EACH_10_HZ);
 
    /* Enable global interrupts */
    CyGlobalIntEnable;
 
    
    
    while(1)
    {
        /* Get Date and Time from RTC */
        time = RTC_GetTime();
        date = RTC_GetDate();
 
        /* Print Date and Time to LCD */
        sprintf(timeBuffer, "%02lu:%02lu:%02lu", RTC_GetHours(time), RTC_GetMinutes(time), RTC_GetSecond(time));
        sprintf(dateBuffer, "%02lu/%02lu/%02lu", RTC_GetMonth(date), RTC_GetDay(date), RTC_GetYear(date));
        
        LCD_Position( 0u, 2u);
        LCD_PrintString(timeBuffer);
        LCD_Position( 1u, 2u );
        LCD_PrintString(dateBuffer);
        
 
        CyDelay(200u);
    }
}
 
   
        
    void SysTickIsrHandler(void)
{
    RTC_Update();
}
 
 
/* [] END OF FILE */



now I am trying
1.set current time and date
2.set current alarm time and date
3. get current date and time
4. get alarm date and time
5if current time&date match with alarm time& date turn on LED pin for 30 seconds
6 if current time&date does not match with alarm time& date turn off led LED pin

see kinkhttps://www.cypress.com/forum/psoc-4-architecture/configure-system-clock
I have written code

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <project.h>
#include <stdio.h>
 
/* Time: 02:59:50 */
#define TIME_HOUR           (0x23u)
#define TIME_MIN            (0x59u)
#define TIME_SEC            (0x55u)
#define TIME_HR_MIN_SEC     ((uint32)(TIME_HOUR << RTC_HOURS_OFFSET) | \
                            (uint32)(TIME_MIN << RTC_MINUTES_OFFSET)    | \
                             TIME_SEC)
 
 
                            
/* Date: 03/22/2016 */
#define DATE_MONTH          (RTC_MARCH)
#define DATE_DAY            (0x22u)
#define DATE_YEAR           (0x2016u)
#define DATE_MONTH_DAY_YEAR ((uint32)(DATE_MONTH << RTC_MONTH_OFFSET)   | \
                            (uint32)(DATE_DAY << RTC_DAY_OFFSET)        | \
                             DATE_YEAR)        
 
/* Alarm Time: 15:44:00 */
#define ALARM_HOUR                  (0x04u)
#define ALARM_MIN                   (0x01u)
#define ALARM_SEC                   (0x30u)
#define ALARM_TIME_HR_MIN_SEC       ((uint32)(ALARM_HOUR << HOUR_OFFSET) | \
                                    (uint32)(ALARM_MIN << MIN_OFFSET)    | \
                                     ALARM_SEC)
 
 /* alarm Date: 03/22/2016 */
#define ALARM_MONTH          (RTC_MARCH)
#define ALARM_DAY            (0x22u)
#define ALARM_YEAR           (0x2016u)
#define ALARM_MONTH_DAY_YEAR ((uint32)(DATE_MONTH << RTC_MONTH_OFFSET)   | \
                            (uint32)(DATE_DAY << RTC_DAY_OFFSET)        | \
                             DATE_YEAR)
 
 
#define ALARM_DATE_MONTH_DAY_YEAR   (DATE_MONTH_DAY_YEAR)
#define ALARM_TIME_HR_MIN_SEC      (TIME_HR_MIN_SEC)       
 
#define SYSTICK_EACH_10_HZ  (10u)
#define SYSTICK_RELOAD      (CYDEV_BCLK__SYSCLK__HZ / SYSTICK_EACH_10_HZ)
 
/* Alarm structure declaration */
RTC_DATE_TIME alarmTimeDate;
 
 
 
/* Interrupt prototype */
CY_ISR_PROTO(SysTickIsrHandler);
CY_ISR_PROTO(AlarmIsrHandler);
 
int main()
{
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    char timeBuffer[16u];
    char dateBuffer[16u];
 
    uint32 time;
    uint32 date;
    uint32 i;
     
       /* Alarm structure initialization */
    alarmTimeDate.time = ALARM_TIME_HR_MIN_SEC;
    alarmTimeDate.date = ALARM_DATE_MONTH_DAY_YEAR;
  
    /* Starts SysTick component */
    CySysTickStart();
 
    /* Configure SysTick timer to generate interrupt every 100 ms */
    CySysTickSetReload(SYSTICK_RELOAD);
 
    /* Find unused callback slot. */
    for (i = 0u; i < CY_SYS_SYST_NUM_OF_CALLBACKS; ++i)
    {
        if (CySysTickGetCallback(i) == NULL)
        {
            /* Set callback */
            CySysTickSetCallback(i, SysTickIsrHandler);
            break;
        }
    }
 
    /* Starts RTC component */
    RTC_Start();
    /* Start LCD */
    
    LCD_Start();
    
    /* Set Date and Time */
    RTC_SetDateAndTime(TIME_HR_MIN_SEC,DATE_MONTH_DAY_YEAR);
    
    
    /* Set RTC time update period */
    RTC_SetPeriod(1u, SYSTICK_EACH_10_HZ);
    
     /* Set Alarm Date and Time */
    RTC_SetAlarmDateAndTime(&alarmTimeDate);
   
    /* Enable global interrupts */
    CyGlobalIntEnable;
      while(1)
    {
        /* Get Date and Time from RTC */
        time = RTC_GetTime();
        date = RTC_GetDate();
 
        /* Print Date and Time to LCD */
        sprintf(timeBuffer, "%02lu:%02lu:%02lu", RTC_GetHours(time), RTC_GetMinutes(time), RTC_GetSecond(time));
        sprintf(dateBuffer, "%02lu/%02lu/%02lu", RTC_GetMonth(date), RTC_GetDay(date), RTC_GetYear(date));
        
        LCD_Position( 0u, 2u);
        LCD_PrintString(timeBuffer);
        LCD_Position( 1u, 2u );
        LCD_PrintString(dateBuffer);      
        CyDelay(200u);
       }
}
 
    void SysTickIsrHandler(void)
{
    RTC_Update();
}
 
/* [] END OF FILE *



there is two API
RTC_SetAlarmMask()

RTC_GetAlarmMask()

which one is used to compare current date & time with alarm date& time ?

what I have to do ?
 

Attachments

  • RTC_P4_v1_0.pdf
    203.3 KB · Views: 152
Last edited:
Please look the datasheet
there is API

void RTC_SetAlarmDateAndTime(const RTC_date_time * alarmTime)
alarmTime: Pointer to the RTC_date_time global structure where new values of alarm time and date are stored.

void RTC_GetAlarmDateAndTime(RTC_date_time* alarmTimeDate)
alarmTimeDate: Pointer to the RTC_date_time structure in which alarm date and time are returned.

How to create global structure and what is pointer
 
Last edited by a moderator:

A pointer is a variable which holds the address of another variable. A variable can be updated by dereferencing a pointer to that variable.

Eg:

If you have a variable

Code:
unsigned int x = 5;
and another pointer to an unsigned int like

Code:
unsigned int *ptr2x = 0;

Then you can use ptr2x to update the value of x but before doing that you have to initialize the ptr2x pointer (pointer to x) with the address of x and you do that like this

Code:
ptr2x = &x

Now pointer is initialized.

If you want to increment the value of x you can do like this

Code:
*ptr2x++;

In your Cypress functions posted in post #7 the data type is RTC_date_time. So, you have to create a global variable of this type like

Code:
RTC_date_time myAlarmDateAndTime;

Then when you pass the address of this global variable to the function

Code:
RTC_SetAlarmDateAndTime()

The global variable will get updated with the Alaram date and time.

You pass the address like this

Code:
RTC_SetAtarmDateAndTime(&myAlarmDataAndTime);

Edit

The RTC_DATE_TIME is a structure and it is like this

Code:
typedef struct
{
uint32 time;
uint32 date;
uint32 dayOfWeek;
uint32 status;
}RTC_DATE_TIME;


To explain more you need to post the function definitions that is code inside each function you are using.

You create a variable of the structure type like this

Code:
RTC_DATE_TIME myDataAndTime, myAlarmDateAndTime;

You pass it to the function like this.

Code:
RTC_SetAtarmDateAndTime(&myAlarmDataAndTime);
 
Last edited:

have you seen code that I posted in post #6

actually I am having problem to understand RTC datasheet

can anyone tell me what I have to do,which API is use to trigger Alarm ?
 

Code:
RTC_SetAlarmDateAndTime()
function is used to Set the Alarm date and time. What do you mean by trigger alarm ? Do you mean which function is used to make the alarm occur ?

Code:
RTC_GetAlarmStatus(void)
is the function which returns the status of alarm. If current date and time matches with the alarm set date and time then this function tells you that alarm is active.

You also has to use
Code:
RTC_SetAlarmMask()
to set the masks for the alarm. Without it alarm will not occur.

Remember

Code:
RTC_GetAlarmDateAndTime()
only returns the set alarm date and time.

My advice is use

Code:
uint32 RTC_GetAlarmMask(void)
to get the Alarm mask. See how the mask looks like. You have to then use a mask value with
Code:
RTC_SetAlarmMask()
function to set the mask.
 
Last edited:

hello pic.programmer

thank you for helping me

set current date and time


Code C - [expand]
1
RTC_SetDateAndTime()



set alarm date and time


Code C - [expand]
1
RTC_SetAlarmDateAndTime()



set alarm mask

Code C - [expand]
1
RTC_SetAlarmMask(uint32 mask)


get current time and date from RTC

Code C - [expand]
1
RTC_GetDateAndTime()


get alarm date and time from RTC

Code C - [expand]
1
RTC_GetAlarmDateAndTime()



I tried to use structure and pointer in code

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
int main()
{
typedef struct
{
uint32 time;
uint32 date;
uint32 dayOfWeek;
uint32 status;
}RTC_DATE_TIME;
 
RTC_date_time AlarmDateAndTime;
 
AlarmDateAndTime.Sec = 55u;
AlarmDateAndTime.Min = 59u;
AlarmDateAndTime.Hour = 22u;
AlarmDateAndTime.DayOfMonth = 31u;
AlarmDateAndTime.Month = 12u;
AlarmDateAndTime.Year = 2007u;
RTC_SetAlarmDateAndTime();
 
/* Enable all interrupts */
CyGlobalIntEnable;
 
RTC_SetAtarmDateAndTime(& AlarmDataAndTime);
 
RTC_GetAtarmDateAndTime(& AlarmDataAndTime);

 
Last edited:

I tried to use structure and pointer in code

What happened when you did that ? Did you converted the result to string and displayed on UART or LCD to see what is happening ?

- - - Updated - - -

I installed PSoC Creator 3.2 SP1. It has 3 or 4 RTC examples for PSoC 4 but I am not able to find the example you are using. So, please zip and post the example RTC project your are using and also provide the Cypress link to that RTC example project if you are really using an example project.
 

What happened when you did that ? Did you converted the result to string and displayed on UART or LCD to see what is happening ?

- - - Updated - - -

I installed PSoC Creator 3.2 SP1. It has 3 or 4 RTC examples for PSoC 4 but I am not able to find the example you are using. So, please zip and post the example RTC project your are using and also provide the Cypress link to that RTC example project if you are really using an example project.

there is only four example project. I have psoc 4200 device there are only two example project that support psoc 4200 device. I have done project with RTC that show the current date and time on LCD

I am attaching zip file , I am trying to do something that show alarm is occur
 

Attachments

  • RTC.zip
    2.2 MB · Views: 98

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top