Hello,I have a custom board using a Nordic nrf52823 microcontroller on it. I am using VSCode with the nrf connect SDK and the Zpehry RTOS- I want to make use Zephyr RTC to get time stamp in date time format.
At the beggining i initialized a RTC device in DT suggesting answer in ticket: nRF52840 with Zephyr RTOS: How to use RTC with struct rtc_time?
my_rtc: &rtc0{ compatible = "nordic,nrf-rtc"; reg = < 0x4000b000 0x1000 >; cc-num = < 0x3 >; interrupts = < 0xb 0x1 >; status = "okay"; clock-frequency = < 0x8000 >; prescaler = < 0x1 >; };
and getting by node
#define TIMER_RTC DT_NODELABEL(my_rtc)
I tried to code something like that, the first step initialize rtc_time structure contains date time for initializing by function rtc_set_time()
int main(void) { const struct device *rtc_dev = DEVICE_DT_GET(TIMER_RTC); int ret; if (!rtc_dev) { printk("cannot find rtc device!\n"); return 0; } struct rtc_time datetime = { .tm_sec = 0, .tm_min = 0, .tm_hour = 23, .tm_mday = 6, .tm_mon = 10, .tm_year = 2023, .tm_nsec = 0, }; ret = rtc_set_time(rtc_dev, &datetime); if (ret) { printk("cannot set time"); } struct rtc_time current_datetime; }in the loop i tried display current date but probably i understand in the wrong way the RTC and the whole library
while (1) { printk("date: %04d-%02d-%02d %02d:%02d:%02d\n", datetime.tm_year, datetime.tm_mon, datetime.tm_mday, datetime.tm_hour, datetime.tm_min, datetime.tm_sec); ret = rtc_get_time(rtc_dev, ¤t_datetime); if (ret) { printk("cannot get time"); } printk("date: %04d-%02d-%02d %02d:%02d:%02d\n", current_datetime.tm_year, current_datetime.tm_mon, current_datetime.tm_mday, current_datetime.tm_hour, current_datetime.tm_min, current_datetime.tm_sec); while (1) ; }
the current data:
Someone can explain me where i make a mistake? I am beginner so please be understanding