« Close

Datasheets and User Guides

App Notes

Software & Driver

 

19.0 RTC (T7 Only) [T-Series Datasheet]

Overview - T7-Pro Only

The T7-Pro has a battery-backed RTC (real-time clock) which is useful for assigning timestamps to data that is stored on the microSD card during scripting operations—particularly in situations where the device could experience power failure or other reboots, and does not have a communication connection that can be used to determine real-time after reboot. The system time is stored in seconds since 1970, also known as the Epoch and Unix timestamp.

Reading Time

Read the system time in seconds with address 61500:

Name Start Address Type Access
RTC_TIME_S 61500 UINT32 R
RTC_TIME_S
- Address: 61500
Read the current time in seconds since Jan, 1970, aka Epoch or Unix time. This value is calculated from the 80 MHz crystal, not the RTC 32 kHz crystal. Non-pro devices do not have a real time clock, so the reported time is either seconds since device startup or the time reported by the network time protocol over Ethernet. Pro devices have a real time clock that will be used to initialize this register at startup, the time can then be updated by NTP.
  • Data type: UINT32  (type index = 1)
  • Read-only
  • T7:
  • T4:

Get a simple calendar time representation by reading six consecutive addresses, starting with address 61510:

Name Start Address Type Access
RTC_TIME_CALENDAR 61510 UINT16 R
RTC_TIME_CALENDAR
- Address: 61510
Read six consecutive addresses of type UINT16, starting with this address. The result will be in year, month, day, hour, minute, second calendar format. i.e. [2014, 10, 21, 18, 55, 35]
  • Data type: UINT16  (type index = 0)
  • Read-only
  • T7:
  • T4:

To time events faster than 1 second apart, it is possible to read the CORE_TIMER (address 61520) and see how it changes from second to second. To access the core timer value in Lua scripts, use the LJ.Tick() function.

Setting Time

Set the system time by writing a new timestamp (in seconds) to address 61504:

Name Start Address Type Access
RTC_SET_TIME_S 61504 UINT32 W
RTC_SET_TIME_S
- Address: 61504
Write a new timestamp to the RTC in seconds since Jan, 1970, aka Epoch or Unix timestamp.
  • Data type: UINT32  (type index = 1)
  • Write-only
  • T7:
  • T4:

To set the T7-Pro's time from a SNTP server, use RTC_SET_TIME_SNTP and SNTP_UPDATE_INTERVAL:

Name Start Address Type Access
RTC_SET_TIME_SNTP 61506 UINT32 W
SNTP_UPDATE_INTERVAL 49702 UINT32 R/W
RTC_SET_TIME_SNTP
- Address: 61506
Write any value to instruct the T7 to update its clock from a SNTP server. Requires that SNTP_UPDATE_INTERVAL is non-zero.
  • Data type: UINT32  (type index = 1)
  • Write-only
  • T7:
  • T4:
SNTP_UPDATE_INTERVAL
- Address: 49702
Sets the SNTP retry time in seconds. A value of zero will disable SNTP(0=default). Values must be 10 or greater.
  • Data type: UINT32  (type index = 1)
  • Readable and writable
  • T7:
  • T4:

Examples

[Lua] Read the value of the RTC in a Lua script

table = {}
table[1] = 0    --year
table[2] = 0    --month
table[3] = 0    --day
table[4] = 0    --hour
table[5] = 0    --minute
table[6] = 0    --second

table, error = MB.RA(61510, 0, 6)
print(string.format("%04d/%02d/%02d %02d:%02d.%02d", table[1], table[2], table[3], table[4], table[5], table[6]))

>> 2014/10/15 18:55.22

[C/C++] Read the value of the RTC in C/C++

int LJMError;
double newValue;
LJMError = LJM_eReadAddress(handle, 61500, 1, &newValue);
printf(newValue);
//returned value of 1413398998 would correspond with Wed, 15 Oct 2014 18:49:58 GMT