0

Set RTC in nRF52832

Declan gravatar image

asked 2017-10-12 15:02:56 +0100

updated 2017-10-12 16:24:52 +0100

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 flag offensive close delete report spam

1 answer

Sort by » oldest newest most voted
0
sigurdon gravatar image

answered 2017-10-12 19:39:59 +0100

updated 2017-10-12 19:40:05 +0100

Hi,

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

edit flag offensive delete publish link more

Comments

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.

Declan ( 2017-10-12 20:18:55 +0100 )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.

John DeWitt ( 2017-10-12 23:13:00 +0100 )editconvert to answer

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

Declan ( 2017-10-13 07:10:14 +0100 )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);
}

}

Declan ( 2017-10-13 07:24:34 +0100 )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);

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

Question Tools

1 follower

Stats

Asked: 2017-10-12 15:02:56 +0100

Seen: 112 times

Last updated: okt. 12