Hi guys, I'm facing some trouble to put my rtc working properly. I made a code based on the rtc example but it's not incrementing the time the right way.
Bellow follows my code, it's just to send the time through the uart each second.
I'm using the nRF51-DK (nRF51422, 32.768 kHz crystal) no softdevice, SDK10
static void lfclk_config(void)
{
ret_code_t err_code = nrf_drv_clock_init(NULL);
APP_ERROR_CHECK(err_code);
nrf_drv_clock_lfclk_request();
}
static void rtc_config(void)
{
uint32_t err_code;
//Initialize RTC instance
err_code = nrf_drv_rtc_init(&rtc, NULL, rtc_handler);
APP_ERROR_CHECK(err_code);
//Enable tick event & interrupt
nrf_drv_rtc_tick_enable(&rtc,true);
//Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds
// err_code = nrf_drv_rtc_cc_set(&rtc,0,COMPARE_COUNTERTIME*RTC0_CONFIG_FREQUENCY,true);
// APP_ERROR_CHECK(err_code);
//Power on RTC instance
nrf_drv_rtc_enable(&rtc);
}
int main(void)
{
leds_config();
lfclk_config();
rtc_config();
uart_config();
printf("\n\rExample1234567890\r\n");
printf("\n\rRTC0_CONFIG_FREQUENCY=%d",RTC0_CONFIG_FREQUENCY);
struct tm *timeinfo;
time_t date_hour_seconds;
while(1)
{
date_hour_seconds=nrf_drv_rtc_counter_get(&rtc);
timeinfo = localtime(&date_hour_seconds);
printf("\n\rCurrent date and hour: %s", asctime(timeinfo));
nrf_delay_ms(1000);
}
}
I've tried two configurations of RTC0_CONFIG_FREQUENCY on my nrf_drv_rtc.h file one using the value 8 which was on rtc example and other with the value 32768 which was on RTC1_CONFIG_FREQUENCY.
Example1234567890
RTC0_CONFIG_FREQUENCY=8
Current date and hour: Thu Jan 1 00:00:00 1970
Current date and hour: Thu Jan 1 00:00:08 1970
Current date and hour: Thu Jan 1 00:00:16 1970
Current date and hour: Thu Jan 1 00:00:24 1970
Current date and hour: Thu Jan 1 00:00:32 1970
Current date and hour: Thu Jan 1 00:00:40 1970
Current date and hour: Thu Jan 1 00:00:48 1970
Current date and hour: Thu Jan 1 00:00:56 1970
Current date and hour: Thu Jan 1 00:01:04 1970
--------------------------------------------------------
Example1234567890
RTC0_CONFIG_FREQUENCY=32768
Current date and hour: Thu Jan 1 00:00:27 1970
Current date and hour: Thu Jan 1 13:51:32 1970
Current date and hour: Fri Jan 2 03:36:03 1970
Current date and hour: Fri Jan 2 17:20:34 1970
Current date and hour: Sat Jan 3 07:05:05 1970
Current date and hour: Sat Jan 3 20:49:36 1970
Current date and hour: Sun Jan 4 10:34:08 1970
Current date and hour: Mon Jan 5 00:18:39 1970
Current date and hour: Mon Jan 5 14:03:10 1970