Adding timestamp to data saved using littleFS

Hello, 

For context, I am using an EVK-ANNA-B112 development board which has an nRF52832 inside. The development board has an external 32.768KHz HW clock connected to the XL_1 and XL_2 pins. I use this external clock for timing UART and enable this using the following code in my prj.conf:

CONFIG_UART_0_NRF_HW_ASYNC=y
CONFIG_UART_0_NRF_HW_ASYNC_TIMER=2

I am using littleFS to save data to a file within the flash memory of the ANNA-B112. With each entry to the file, I want to include the timestamp. I followed the example from  RE: NRF52840 date time example . In that forum, someone suggests setting time with date_time_set() and retrieving time using date_time_now() as follows:

CONFIG_DATE_TIME=y
CONFIG_DATE_TIME_MODEM=n
CONFIG_DATE_TIME_NTP=n

/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr.h>
#include <date_time.h>
#include <sys/printk.h>

void main(void)
{
	// Set time to 8th of June, 2022, 16:00
	// unix timestamp: 1654704000000
	struct tm time = 
	{
  		.tm_sec = 00,
  		.tm_min = 00,
  		.tm_hour = 16,
  		.tm_mday = 8,
  		.tm_mon = 6-1,
  		.tm_year = 2022-1900,
  		.tm_wday = 3,
	};
	int err = date_time_set(&time);
	/* your err handling here */
	
	printk("Hello World! %s\n", CONFIG_BOARD);
	int64_t unix_timestamp = 0;

	// Wait 10 seconds to see that the timestamp increments 10 seconds
	k_sleep(K_SECONDS(10));

	err = date_time_now(&unix_timestamp);
	/* your err handling here */
	
	// Use https://www.epochconverter.com/ to convert to human readable
	printk("unix timestamp: %lld", unix_timestamp);
}

So in this code the time is set to 8th of June, 2022, 16:00 using date_time_set() and they check to see if this has incremented by 10 seconds after waiting. When I do the same thing, I am receiving back unexpected unix value of 1141601040 from date_time_now() which seems to be converting to Sunday, March 5, 2006 11:24:00 PM. 

My question is whether I am reading back the unix time data wrong, or if the date_time_now() function is inaccurate because I haven't setup a clock or timer? I also want to know that if I setup the external 32.768KHz HW clock to be used for keeping track of time, will this interfere with how I am using it for UART?

Thank you!

Crisvin K. 

Parents Reply Children
No Data
Related