<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>RTC Calendar update issue in NCS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/125336/rtc-calendar-update-issue-in-ncs</link><description>Hello Team, 
 I am using the nRF52833 with the nRF Connect SDK (v2.9.1) in VS Code , and I am experiencing an issue with the RTC calendar update. 
 I initially set the RTC calendar to 30th October 2025, 09:00:00 AM . The RTC was set successfully and worked</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 13 Nov 2025 06:11:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/125336/rtc-calendar-update-issue-in-ncs" /><item><title>RE: RTC Calendar update issue in NCS</title><link>https://devzone.nordicsemi.com/thread/554205?ContentTypeID=1</link><pubDate>Thu, 13 Nov 2025 06:11:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4dd7dda4-dff5-4ab8-850a-8467c8937929</guid><dc:creator>Embel_Tech</dc:creator><description>&lt;p&gt;&amp;nbsp; &amp;nbsp;Thanks, for your support!&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Issue Resolved, Now RTC Calendar updated successfully, when set RTC calendar directly from epoch without updating structure.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC Calendar update issue in NCS</title><link>https://devzone.nordicsemi.com/thread/553719?ContentTypeID=1</link><pubDate>Fri, 07 Nov 2025 17:08:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39b9c87e-8f2a-4ca8-9171-be5dc176472a</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I see that you convert manually there, between the &lt;code&gt;tm&lt;/code&gt; and &lt;code&gt;rtc_time&lt;/code&gt; data structures. Please note the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Both of those structures use the same underlying representation. That is: Both hold in &lt;code&gt;.tm_year&lt;/code&gt; a value equal to the current year - 1900, and both store in &lt;code&gt;.tm_mon&lt;/code&gt; a value of the month, where January is 0, February is 1, and so on, up to December which is 11. Since both structures use the same representation, there is no need to do arithmetic on the numbers when converting between the two. Adding or subtracting 1 will convert to the next or previous month respectively, and in the case of December or January most likely fail in some undefined way.&lt;/li&gt;
&lt;li&gt;Both structures have additional fields, which needs to be updated correctly when other fields update. Therefore, you shouldn&amp;#39;t really do manual changes such as the ones that you do, or you risk that the structure holds an internally inconsistent state.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There is for instance the function&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/apidoc/latest/group__rtc__interface.html#gac2bb774a4b512f76c35a0a6723a7c807"&gt;rtc_time_to_tm()&lt;/a&gt;, for converting from an &lt;code&gt;rtc_time&lt;/code&gt; structure to a &lt;code&gt;tm&lt;/code&gt; structure. I highly recommend using that one, instead of filling the values manually yourself. I did not find a corresponding function for the reverse conversion, but by looking at the implementation of &lt;code&gt;rtc_time_to_tm()&lt;/code&gt;, you should be able to easily implement the reverse cast.&lt;/p&gt;
&lt;p&gt;Since you add and subtract 1 to the month when you convert between the two structures, what you experienced is most likely that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;With the erroneous manual conversion, the 30th of October is converted into the 30th of a neighboring month, which is a month with only 30 days.&lt;/li&gt;
&lt;li&gt;Adding seconds to the corresponding timestamp, it now represents the 1st of the following month, not the 31st of the same month.&lt;/li&gt;
&lt;li&gt;With the erroneous manual conversion back the other way, the date is now the 1st of the month following October: November 1st.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To summarize, the error is not in additional seconds gets added to the timestamp, but rather that the date structure conversions are wrong.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC Calendar update issue in NCS</title><link>https://devzone.nordicsemi.com/thread/553075?ContentTypeID=1</link><pubDate>Sat, 01 Nov 2025 05:01:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a610a244-fc76-4c3c-b705-cfca26a68bb4</guid><dc:creator>Embel_Tech</dc:creator><description>&lt;p&gt;I am using rtc.h for setting RTC calendar as follows:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class="ui-code" data-mode="text"&gt;void init_rtc_calender(void) {
&amp;#160; &amp;#160; &amp;#160;if (!device_is_ready(rtc_dev)) {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;LOG_ERR(&amp;quot;RTC device not ready&amp;quot;);
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;return;
&amp;#160; &amp;#160; &amp;#160;}
&amp;#160;
&amp;#160; &amp;#160; &amp;#160;time_t epoch =&amp;#160;1761917512;
&amp;#160; &amp;#160; &amp;#160;struct tm *tm = gmtime(&amp;amp;epoch);
&amp;#160; &amp;#160; &amp;#160;struct rtc_time set_time = {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;.tm_year = tm-&amp;gt;tm_year + 1900,
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;.tm_mon = tm-&amp;gt;tm_mon + 1,
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;.tm_mday = tm-&amp;gt;tm_mday,
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;.tm_hour = tm-&amp;gt;tm_hour,
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;.tm_min = tm-&amp;gt;tm_min,
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;.tm_sec = tm-&amp;gt;tm_sec
&amp;#160; &amp;#160; &amp;#160;};
&amp;#160; &amp;#160; &amp;#160;&amp;#160; &amp;#160; &amp;#160;
&amp;#160; &amp;#160; &amp;#160;if (rtc_set_time(rtc_dev, &amp;amp;set_time) != 0) {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;LOG_ERR(&amp;quot;Failed to set RTC time&amp;quot;);
&amp;#160; &amp;#160; &amp;#160;}
&amp;#160;}&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;AND&lt;br /&gt;Readback&amp;nbsp; RTC calendar as :&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;// Get RTC time
&amp;#160; &amp;#160; &amp;#160;struct rtc_time current_time;
&amp;#160; &amp;#160; &amp;#160;if (rtc_get_time(rtc_dev, &amp;amp;current_time) != 0) {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;epoch_send_in_progress = false;
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;return;
&amp;#160; &amp;#160; &amp;#160;}
&amp;#160;
&amp;#160; &amp;#160; &amp;#160;// Convert to Unix epoch
&amp;#160; &amp;#160; &amp;#160;struct tm tm_time = {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;.tm_year = current_time.tm_year - 1900, &amp;#160;// Years since 1900
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;.tm_mon &amp;#160;= current_time.tm_mon - 1, &amp;#160; &amp;#160; // 0-11
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;.tm_mday = current_time.tm_mday,
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;.tm_hour = current_time.tm_hour,
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;.tm_min &amp;#160;= current_time.tm_min,
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;.tm_sec &amp;#160;= current_time.tm_sec
&amp;#160; &amp;#160; &amp;#160;};
&amp;#160; &amp;#160; &amp;#160;time_t epoch_time = mktime(&amp;amp;tm_time);
&amp;#160; &amp;#160; &amp;#160;//uint32_t epoch_32bit = (uint32_t)epoch_time;
&amp;#160; &amp;#160; &amp;#160;flash_state.rtc_calender_epoch = (uint32_t)epoch_time;
&amp;#160; &amp;#160; &amp;#160;LOG_INF(&amp;quot; -------------- CURRENT RTC CAL in Scanner : %d &amp;#160;-------------------&amp;quot;,flash_state.rtc_calender_epoch);
&lt;/pre&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC Calendar update issue in NCS</title><link>https://devzone.nordicsemi.com/thread/553022?ContentTypeID=1</link><pubDate>Fri, 31 Oct 2025 13:22:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ff67f5b-3948-4c45-bbcf-04662f9f7b4b</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The RTC of the nRF52833 is a Real Time Counter (not a Real Time Clock). Therefore, in order to implement calendar functionality (time and date) on the nRF52833, one must either use an external Real Time Clock, or build time and date functionality on top of the RTC of the nRF52833. For both there are several alternatives, but it sounds like you use a software solution, either from existing solutions already present in nRF Connect SDK, or from external libraries (either from us or from third parties.) What exact sample, application and/or library are you using for your project?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>