# Set RTC in nRF52832

My application is built using the nRF52832 device. The system must only be "active" between certain times (5am through to 9pm).

I am a newbie and have no idea how to set the RTC of the nRF52832. I could either set the time in a text string OR set the time of the PC in the nRF52832 when the program is uploaded.

I use the following code snipped to check if the time is within 5am and 9pm:

case BATTERY_CHECK:

        date_time_get_current_time(&current_time);
if(current_time.hours > 4 && current_time.hours <10)
{


I need to be able to set the following: date_time_set_timestamp() RTC2_date_time_clock_init_N_start()

edit retag close delete

Sort by » oldest newest most voted

Hi,

For keeping track of time on the nRF52, I would recommend taking a look at the nrf-calendar-example we have on Github.

more

0 Declan gravatar image Declan 1 ●1 ●3 answered 18 mins ago Thanks, but sorry - "nrf-calendar-example" makes no sense to me. I am very new to the whole Nordic / Keil environment. I desperately need assistance in being able to set the time and read(get) the time as per above. Any help would be greatly appreciated.

( 2017-10-12 20:18:55 +0200 )editconvert to answer

Well, I think what Sigurd was trying to say in not so many words is that the RTC peripheral you see on the nRF52 is a real time counter, not a real time clock/calendar. You can use it to keep track of ticks at almost any interval you want, but you have to build the logic on top of it if you want to use it as a clock/calendar. The example he is pointing you to is a way to do that.

( 2017-10-12 23:13:00 +0200 )editconvert to answer

Thanks, it's building the logic that I do not understand. I must keep track of the hours in a day.

( 2017-10-13 07:10:14 +0200 )editconvert to answer

How can I set the current PC time into: void date_time_set_timestamp(uint32_t timestamp) { uint32_t RTC2_counter;

RTC2_counter = NRF_RTC2->COUNTER;
if(timestamp < (RTC2_counter / 8))
{
date_time_clock_timestamp = 0;
}
else
{
date_time_clock_timestamp = timestamp - (RTC2_counter / 8);
}


}

( 2017-10-13 07:24:34 +0200 )editconvert to answer

Where did you find the function date_time_set_timestamp() ?

Did you test the nrf-calendar example? In the nrf-calender example the current time is set with the function nrf_cal_set_time(), nrf_cal_set_time(year, month, day, hour, minute, second);

( 2017-10-16 14:08:33 +0200 )editconvert to answer

[hide preview]

## Recent blog posts

• ### GPIO pin errors

Posted 2017-10-20 02:37:56 by micallef25
• ### How to build continuous integration and delivery process for embedded SW development

Posted 2017-10-03 11:01:29 by Yaniv Nis
• ### Multiple channels in RTT

Posted 2017-09-29 11:51:52 by Krzysztof Zaraska
• ### 6 Things to Know about Bluetooth Beacons

Posted 2017-09-22 08:27:00 by Rose Martin
• ### Creating a Keil project for a Bluetooth Mesh example (Updated for 0.10.0)

Posted 2017-09-19 12:08:11 by Kristian Skordal

## Recent questions

• ### nRF51822 receiving range problem. Transmit range is good however. Using micro ESB proprietary library.

Posted 2017-10-20 01:26:12 by Mahonroy
• ### Mesh SDK Beacon example not working?

Posted 2017-10-19 17:12:16 by SørenHN
• ### Weird definition of access_opcode_t?

Posted 2017-10-19 16:54:00 by SørenHN
• ### Errorcode: CouldNotFindJprogDLL (0x2)

Posted 2017-10-19 16:52:57 by alidaf