#2 - next one in my pipeline is Realtime Clock (RTC) initialize and get it working.
What is RTC?
1. Wikipedia
A real-time clock (RTC) is a computer clock (most often in the form of an integrated circuit) that keeps track of the current time. Although the term often refers to the devices in personal computers,servers and embedded systems, RTCs are present in almost any electronic device which needs to keep accurate time.
RTC in K20D Freescale Board
The Real Time Clock (RTC) module on the K20 has two modes of operation, system power‐up and system power‐
down. In system power‐up mode, the RTC may be powered by either the MCU regulator or the backup power
supply, VBAT. During system power‐down, the RTC is only powered from the backup power supply, VBAT
I have used RTC with a FRDM-K20D50 Board to schedule an alarm at regular intervals.
The CPU Settings should enable the RTC Oscillator. Otherwise RTC will not work.
RTC Component added.
Setting Properties for the RTC Component
Now lets add the code to set the RTC time and get it back, the main.c
int i;
for(i=1;i<=3000000;i++)
{
}
I have used RTC with a FRDM-K20D50 Board to schedule an alarm at regular intervals.
The CPU Settings should enable the RTC Oscillator. Otherwise RTC will not work.
RTC Component added.
Now lets add the code to set the RTC time and get it back, the main.c
Code to set and get time
printf("--Test init--\n");
LDD_RTC_TTime ttime;
ttime.Day = 11;
ttime.Month = 06;
ttime.Year = 2015;
ttime.Hour = 17;
ttime.Minute = 45;
ttime.Second = 15;
RTC1_SetTime(NULL, &ttime);
int i;
for(i=1;i<=3000000;i++)
{
}
LDD_RTC_TTime ttime1;
RTC1_GetTime(NULL, &ttime1);
printf("%d-%d-%d %d:%d:%d\n", ttime1.Day, ttime1.Month, ttime1.Year, ttime1.Hour, ttime1.Minute, ttime1.Second);
Output
--Test init--
11-6-2015 17:45:16
- Printed the RTC time that is set
Lets try setting RTC alarm and triggering it
Enable the methods setAlarm and enable onAlarm Event and generate code
main.c
ttime1.Second += 30;
RTC1_SetAlarm(NULL, &ttime);
Event.c
void RTC1_OnAlarm(LDD_TUserData *UserDataPtr)
{
printf("---Alarm Triggered--\n");
LDD_RTC_TTime ttime1;
RTC1_GetTime(NULL, &ttime1);
printf("%d-%d-%d %d:%d:%d\n", ttime1.Day, ttime1.Month, ttime1.Year,
ttime1.Hour, ttime1.Minute, ttime1.Second);
}
Output after alarm
---Alarm Triggered--
11-6-2015 17:45:26