void RTC_Start(void)
Descriptionerforms 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
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
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 */
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 *
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.
unsigned int x = 5;
unsigned int *ptr2x = 0;
ptr2x = &x
*ptr2x++;
RTC_date_time myAlarmDateAndTime;
RTC_SetAlarmDateAndTime()
RTC_SetAtarmDateAndTime(&myAlarmDataAndTime);
typedef struct
{
uint32 time;
uint32 date;
uint32 dayOfWeek;
uint32 status;
}RTC_DATE_TIME;
RTC_DATE_TIME myDataAndTime, myAlarmDateAndTime;
RTC_SetAtarmDateAndTime(&myAlarmDataAndTime);
RTC_SetAlarmDateAndTime()
RTC_GetAlarmStatus(void)
RTC_SetAlarmMask()
RTC_GetAlarmDateAndTime()
uint32 RTC_GetAlarmMask(void)
RTC_SetAlarmMask()
Code C - [expand] 1 RTC_SetDateAndTime()
Code C - [expand] 1 RTC_SetAlarmDateAndTime()
Code C - [expand] 1 RTC_SetAlarmMask(uint32 mask)
Code C - [expand] 1 RTC_GetDateAndTime()
Code C - [expand] 1 RTC_GetAlarmDateAndTime()
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);
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.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?