Hi
i bound rtc in nrf52833 and set/get the time.
but the time is not incrementing ,iam reading the same time which i set.
i added the config below,
but no change in rtc time.
Hi
i bound rtc in nrf52833 and set/get the time.
but the time is not incrementing ,iam reading the same time which i set.
i added the config below,
but no change in rtc time.
Happy New Year!
Not sure if this awnser the question completely but here is an example on how to use the RTC in the nRF Connect SDK (NCS), you can use the RTC API provided by Zephyr.
Have the RTC driver enabled in your project configuration. You can do this by adding `CONFIG_RTC=y` to your `prj.conf` file, like you have done already.
Use the RTC API functions to set and get the time. Here's a basic example of how to increment time:
#include <zephyr/drivers/rtc.h>
const struct device *rtc_dev = DEVICE_DT_GET(DT_NODELABEL(rtc0));
struct rtc_time time;
// Get the current time
rtc_get_time(rtc_dev, &time);
// Increment the time (e.g., add one second)
time.tm_sec++;
// Handle overflow
if (time.tm_sec >= 60) {
time.tm_sec = 0;
time.tm_min++;
// Handle further overflow as needed
}
// Set the new time
rtc_set_time(rtc_dev, &time);
This code snippet demonstrates how to get the current time, increment it, and set the new time using the RTC API.
Also, be aware that in some cases, certain RTC instances might be used by the system or other protocols. For example, as stated in another [Nordic DevZone discussion](devzone.nordicsemi.com/.../rtc-prescaler-has-no-effect-in-zephyr), RTC0 might be used by Bluetooth Low Energy, and RTC1 is used by Zephyr itself. This leaves RTC2 available for application use in many cases.
Remember to handle time overflow correctly and consider any specific requirements of your application when implementing time incrementation.
Regards,
Jonathan
Hi jonathan,
Thank you for the response,
I will try the same,but is this the only way to update the rtc?
here i can see the sample,that it automatically updates with this code.
also can i use the call back function or interrupt to update the rtc.
typedef void(* | rtc_update_callback) (const struct device *dev, void *user_data) |
RTC update event callback. |
I only provide a basic sample, you can use other ways, like the examples used on zephyr docs.
i need to get only the unix epoch time to generate totp,
so i need a counter type peripheral that should increment the value in seconds.
the above approach u suggested might not generate accurate timestamp when considering totp.
can you suggest me someother way to get epoch time without manual incrementation?
lara said:the above approach u suggested might not generate accurate timestamp when considering totp.
I am not sure what would be the best approach here as I am not familiar with what conditions would apply when using TOTP, but I assume that you would need something that gives you a decent time accuracy for a given duration. I would think that if we are using seconds and for a couple of minutes it might be accurate enough.
You can also try the the Zephyr forum here for recommendations if someone has done something similar before.
https://www.zephyrproject.org/community/
Regards,
Jonathan