RTC (Real-Time Clock)
Last updated
Last updated
This feature is supported in BSP v0.9.9 and above. For older versions, there is no Arduino API for the RTC function (but you can still access this feature by using native LinkIt SDK APIs).
LinkIt 7697 has an internal RTC module and by using a separate power source it can store the time information when the main power is cut off for saving power. To achieve this goal, a little rework is needed for enabling the RTC module. By default, the RTC module shares the same 3V3 power source with the main MT7697 chip. So if you turn off the power of a LinkIt 7697 board, both MT7697 and the RTC module would lose their power supply. By separating the power sources of MT7697 and the RTC module, you need to remove the 0R resistor (marked as R2 in the schematic):
And its position on LinkIt 7697 is:
After the rework is done, you can provide the power sources to the MT7697 and the RTC module separately and let the RTC keep alive when the MT7697 is turned down. The valid input voltage of the RTC module is ranging from 1.6V to 3.63V, so you can even power on the RTC module by 2xAA batteries.
Here is a demo video to show how the time information is kept even when the main power is cut:
Description
This demo uses a LCD to show the time in the RTC of LinkIt 7697 and puts a regular clock behind as a reference. In the beginning, the power is cut and you can see the power indicator on the LinkIt 7697 and the LCD are off. However, the power for the RTC module is still connected. After seconds, the power for the board is turned on again and the system goes back (the power indicator and the LCD are on). You can notice that the time displayed on the LCD is still synchronized with the current time.
To use the RTC class, include the header file LRTC.h in the beginning of the sketch file.
Before calling RTC related APIs to access the time, you need to initialize the module first. It's suggested to call the begin() API in the setup() phase.
To get the time information stored in the RTC, call the get() API. After the function returns, you can access the year, month, day, hour, minute and second information by calling:
Here is an example:
For setting the time to the RTC (e.g. you might get the time from NTP), the set() API is used.
The valid ranges of input parameters are identical to the table listed above for get().
Two examples are provided in the File / Examples / LRTC sub-menu. For ease of understanding, the time information used in the examples is hard-coded and set by pressing the user button. If you don't set any time information to the RTC module, the time gotten from the RTC module would start from 2000/1/1 00:00:00. The CheckTime example outputs the result to the Serial Monitor and the CheckTimeLCD example display the time on a 1602 LCD (as the video shown above). You need to install the driver for 1602 LCD before running the LCD example. If you're not familiar with that LCD, refer to the 1602 LCD tutorial for detailed information.
APIs | Valid Ranges |
---|---|
LRTC.year()
[2000, 2099]
LRTC.month()
[1, 12]
LRTC.day()
[1, 31]
LRTC.hour()
[0, 23]
LRTC.minute()
[0, 59]
LRTC.second()
[0, 59]