Hi,Team,
I'm currently using the nrf54l15-dk. I want to set the rtc of the nrf54l15-dk to obtain the timestamp. How should I configure the rtc? Which examples should I refer to?
My ncs version is v2.8.0.
Thanks.
Hi,Team,
I'm currently using the nrf54l15-dk. I want to set the rtc of the nrf54l15-dk to obtain the timestamp. How should I configure the rtc? Which examples should I refer to?
My ncs version is v2.8.0.
Thanks.
Hello,
The error shows that one variable you have declared or defined (grtc_channel), but you have not actually used it anywhere in your code. This is a common warning or error in C/C++ development, especially when using strict compiler flags.
To resolve this, ensure that you use the variable in your code, for example by passing it to a function. Otherwise, you have to remove this.
Can you please share your application folder?
Kazi Afroza Sultana The unused var won't cause build error.
The main reason is the header not exits.
I don't want talk more. just show your code which is a complete project.
It won't be difficult for your verder, but cost much time for us costumers.
Thanks.
Hi,
Currently, I still haven't been able to implement the function of using grtc as the real-time clock for the nrf54l15-dk. Could you please provide some reference engineering examples?
Thanks.
To set the time, you can save the difference between GRTC and the timestamp (epoch microseconds) in memory. To get the time, you add the same difference to the GRTC. If you save the difference in a retained memory region, it will survive soft reboots.
Hi
I can understand what you mean. But I don't know how to do it. Could you please provide an example of a code engineering project?
Thanks.
This is how to read the GRTC:
In prj.conf:
CONFIG_NRFX_GRTC=y
In your code:
#include <nrfx_grtc.h>
...
uint64_t syscounter;
int ret = nrfx_grtc_syscounter_get(&syscounter);
if (ret != NRFX_SUCCESS) {
...
}
As for retained memory, see zephyr/samples/boards/nordic/system_off for an example.
Hi,
Thank you very much for your reply.
Thank you very much for your reply.
Now I can use the nrfx_grtc_syscounter_get() function to obtain the value. The app will send 8 bytes to my device: 0x10, 0xDB, 0x4D, 0xEE, 0x98, 0x01, 0x00, 0x00. Converting these to 13-digit decimal gives 1756344736528. This represents a Unix millisecond-level timestamp format. Converting it again to UTC format results in 20-09-27 21:32:16.528.
The first time, nrfx_grtc_syscounter_get(&syscounter) was called, and syscounter = . A delay of 1 second was then applied. Subsequently, nrfx_grtc_syscounter_get(&syscounter) was called again, and syscounter = 1127894. Based on the difference you described, I should do this: 1756344736528 + 1127894 - 126117 = 1756335738305. Right? If I'm wrong, please let me know.
This is my simple test code:
unsigned char bytes[] = {0x10, 0xDB, 0x4D, 0xEE, 0x98, 0x01, 0x00, 0x00};
uint64_t timestamp = 0;
// 从小端序字节构建64位整数
for (int i = 0; i < 8; i++) {
timestamp |= (uint64_t)bytes[i] << (i * 8);
}
// 输出时间戳(13位十进制数字)
printf("\n");
printf("Timestamp1: %" PRIu64 "\n", timestamp);
uint64_t syscounter;
ret = nrfx_grtc_syscounter_get(&syscounter);
if (ret != NRFX_SUCCESS) {
LOG_ERR("get grtc err");
}
printf("Timestamp2: %" PRIu64 "\n", syscounter);
k_msleep(1000);
ret = nrfx_grtc_syscounter_get(&syscounter);
if (ret != NRFX_SUCCESS) {
LOG_ERR("get grtc err");
}
printf("Timestamp3: %" PRIu64 "\n", syscounter);
The log printed by the device is as follows:
Timestamp1: 1756344736528 Timestamp2: 126117 Timestamp3: 1127894
Thanks.
Hi,
Thank you very much for your reply.
Thank you very much for your reply.
Now I can use the nrfx_grtc_syscounter_get() function to obtain the value. The app will send 8 bytes to my device: 0x10, 0xDB, 0x4D, 0xEE, 0x98, 0x01, 0x00, 0x00. Converting these to 13-digit decimal gives 1756344736528. This represents a Unix millisecond-level timestamp format. Converting it again to UTC format results in 20-09-27 21:32:16.528.
The first time, nrfx_grtc_syscounter_get(&syscounter) was called, and syscounter = . A delay of 1 second was then applied. Subsequently, nrfx_grtc_syscounter_get(&syscounter) was called again, and syscounter = 1127894. Based on the difference you described, I should do this: 1756344736528 + 1127894 - 126117 = 1756335738305. Right? If I'm wrong, please let me know.
This is my simple test code:
unsigned char bytes[] = {0x10, 0xDB, 0x4D, 0xEE, 0x98, 0x01, 0x00, 0x00};
uint64_t timestamp = 0;
// 从小端序字节构建64位整数
for (int i = 0; i < 8; i++) {
timestamp |= (uint64_t)bytes[i] << (i * 8);
}
// 输出时间戳(13位十进制数字)
printf("\n");
printf("Timestamp1: %" PRIu64 "\n", timestamp);
uint64_t syscounter;
ret = nrfx_grtc_syscounter_get(&syscounter);
if (ret != NRFX_SUCCESS) {
LOG_ERR("get grtc err");
}
printf("Timestamp2: %" PRIu64 "\n", syscounter);
k_msleep(1000);
ret = nrfx_grtc_syscounter_get(&syscounter);
if (ret != NRFX_SUCCESS) {
LOG_ERR("get grtc err");
}
printf("Timestamp3: %" PRIu64 "\n", syscounter);
The log printed by the device is as follows:
Timestamp1: 1756344736528 Timestamp2: 126117 Timestamp3: 1127894
Thanks.
I suggest you do like this:
uint64_t offset = 0;
int set_time(uint64_t timestamp)
{
uint64_t syscounter;
int ret = nrfx_grtc_syscounter_get(&syscounter);
if (ret != NRFX_SUCCESS) {
return ret;
}
offset = timestamp - syscounter;
return 0;
}
int get_time(uint64_t *timestamp)
{
uint64_t syscounter;
int ret = nrfx_grtc_syscounter_get(&syscounter);
if (ret != NRFX_SUCCESS) {
return ret;
}
*timestamp = syscounter + offset;
return 0;
}
If you call set_time() with your initial timestamp, then k_msleep(1000), then get_time() should give the initial timestamp plus one second.
Hi,
Thank you for your reply.
As you said, calling k_msleep(1000) indeed adds 1 second.
But how can I achieve adding 1 second to the timestamp? As I mentioned:
"The app will send 8 bytes to my device: 0x10, 0xDB, 0x4D, 0xEE, 0x98, 0x01, 0x00, 0x00. Converting these to 13-digit decimal gives 1756344736528. This represents a Unix millisecond-level timestamp format. Converting it again to UTC format results in 20-09-27 21:32:16.528." Currently, I can only calculate the 13-digit decimal number: 1756344736528. If I add 1 second to 1756344736528, converting it to UTC results in 2025-09-27 19:02:18.305, and the time is incorrect.
Could you please tell me how to add 1 second to the value of 1756344736528 to achieve the addition of year, month, day, hour, minute, second, and millisecond?
Thanks.
The GRTC measures time in microseconds, not milliseconds. You need to convert between them.