<?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>nRF52840 SDK16 - RTC Driver general questions - instance, initialization, and channels</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/82425/nrf52840-sdk16---rtc-driver-general-questions---instance-initialization-and-channels</link><description>Hi everyone, 
 I want to use the RTC module in my code, and I have some questions. 
 1. What I have understood so far is that the nRF52840 has three RTCs (RTC0, RTC1, RTC2). RTC0 is used by the SD and RTC1 from the application timer software. So it&amp;#39;s</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 13 Dec 2021 11:52:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/82425/nrf52840-sdk16---rtc-driver-general-questions---instance-initialization-and-channels" /><item><title>RE: nRF52840 SDK16 - RTC Driver general questions - instance, initialization, and channels</title><link>https://devzone.nordicsemi.com/thread/343136?ContentTypeID=1</link><pubDate>Mon, 13 Dec 2021 11:52:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2b635f9-6292-4892-b726-f9f71161a517</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;You can use the nrfx interface if you want, but in general it is easier to enable the nrf_drv layer in the nRF5 SDK since this is the default driver interface&amp;nbsp;in the SDK.&lt;/p&gt;
&lt;p&gt;Also, the functionality of the nrf_drv drivers and the nrfx drivers is more or less identical, for most functions the only difference is the name.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SDK16 - RTC Driver general questions - instance, initialization, and channels</title><link>https://devzone.nordicsemi.com/thread/342873?ContentTypeID=1</link><pubDate>Fri, 10 Dec 2021 10:10:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3dd78c6e-5fc0-4b16-a110-4c93c53fee39</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Thank you ovrebekk,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yes I know about the legacy layer (I forgot to mention it in the stack scketch).&lt;/p&gt;
[quote userid="2116" url="~/f/nordic-q-a/82425/nrf52840-sdk16---rtc-driver-general-questions---instance-initialization-and-channels/342851#342851"]So in fact when you develop applications in the nRF5 SDK you will use the nrf_drv API in your application, which is then redirected to the nrfx implementation, which will again use the HAL files underneath.[/quote]
&lt;p&gt;I was thinking the opposite :) The new implementation (nrfx) has &lt;a href="https://www.taterli.com/nrf5/nrf5/nrfx_migration_user_guide.html#:~:text=If%20you%20want%20to%20start%20using%20a%20new%20nrfx%20driver%20with%20the%20SDK%20to%20take%20advantage%20of%20its%20new%20functionality"&gt;additional functionalities&lt;/a&gt; and I should use the nrfx API when I develop applcations.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SDK16 - RTC Driver general questions - instance, initialization, and channels</title><link>https://devzone.nordicsemi.com/thread/342851?ContentTypeID=1</link><pubDate>Fri, 10 Dec 2021 08:49:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1483634c-03e7-431c-b8f2-321029acd22b</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Nick&lt;/p&gt;
&lt;p&gt;Sorry, the information I gave you earlier was a bit imprecise.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the nRF5 SDK there is actually one more layer that is usually involved, for historical reasons.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the older SDK&amp;#39;s we had the nrf_drv set of drivers, which included drivers for all the different peripherals in the part.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then at a later stage it was decided to pull the low level drivers out of the SDK into a separate module, called nrfx, which could be shared also with other software packages (such as the newer nRF Connect SDK, which is the replacement for the nRF5 SDK going forward).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But in order not to break compatibility with all the existing SDK examples using the nrf_drv API&amp;#39;s we included a legacy integration layer in the SDK, which redirects all the nrf_drv calls to nrfx calls.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So in fact when you develop applications in the nRF5 SDK you will use the nrf_drv API in your application, which is then redirected to the nrfx implementation, which will again use the HAL files underneath.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hopefully this all made sense ;)&lt;/p&gt;
[quote user="Nikosant03"]Are there any cases where I should use the HAL? For example, if I want to change the prescaler setting, the HAL has the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.0.0/group__nrf__rtc__hal.html?cp=8_5_4_6_9_0_16_2_1#gaf04720d3617c04d21541e5816139b5fc"&gt;RTC_FREQ_TO_PRESCALER &lt;/a&gt;macro that is convenient for this task.&amp;nbsp;[/quote]
&lt;p&gt;If the HAL has some functionality that you can&amp;#39;t find in the higher layers it is OK to use it, as long as you avoid using any functions or macros that already exist in nrf_drv or nrfx.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SDK16 - RTC Driver general questions - instance, initialization, and channels</title><link>https://devzone.nordicsemi.com/thread/342693?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 11:52:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5d14bd44-ff39-4f72-a789-a0c700b3249c</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Thank you Ovrebekk,&lt;/p&gt;
[quote userid="2116" url="~/f/nordic-q-a/82425/nrf52840-sdk16---rtc-driver-general-questions---instance-initialization-and-channels/342517#342517"]HAL is short for &amp;#39;Hardware Abstraction Layer&amp;#39;, and is a small wrapper around the hardware peripheral registers to make them easier to access. The NRFX layer sits on top of the HAL layer, and from an application perspective it should be sufficient to access the NRFX interface, and let NRFX interface to the HAL layer underneath.&amp;nbsp;[/quote]
&lt;p&gt;So the stack is like this?&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1639049995482v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;With that being said accessing just the NRFX API is enough. Are there any cases where I should use the HAL? For example, if I want to change the prescaler setting, the HAL has the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.0.0/group__nrf__rtc__hal.html?cp=8_5_4_6_9_0_16_2_1#gaf04720d3617c04d21541e5816139b5fc"&gt;RTC_FREQ_TO_PRESCALER &lt;/a&gt;macro that is convenient for this task.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SDK16 - RTC Driver general questions - instance, initialization, and channels</title><link>https://devzone.nordicsemi.com/thread/342517?ContentTypeID=1</link><pubDate>Wed, 08 Dec 2021 10:52:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d00d211-2818-4d41-aba4-6956ecd73e28</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Nick&lt;/p&gt;
&lt;p&gt;If you need very accurate timing for the SAADC sampling I agree that using PPI and a dedicated RTC or timer is a better approach, yes. You can use the app_timer also, but then there will be some hundreds of microseconds of timing jitter since you will be affected by high priority interrupts in the system.&amp;nbsp;&lt;/p&gt;
[quote user="Nikosant03"]What is the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__nrf__rtc__hal.html?cp=8_5_1_6_9_0_29_2"&gt;RTC HAL&lt;/a&gt;? I&amp;#39;ve noticed there are functions and macros not included in nrfx driver. Should I use&amp;nbsp;the&amp;nbsp;Hardware access layer in combination with nrfx?[/quote]
&lt;p&gt;HAL is short for &amp;#39;Hardware Abstraction Layer&amp;#39;, and is a small wrapper around the hardware peripheral registers to make them easier to access. The NRFX layer sits on top of the HAL layer, and from an application perspective it should be sufficient to access the NRFX interface, and let NRFX interface to the HAL layer underneath.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SDK16 - RTC Driver general questions - instance, initialization, and channels</title><link>https://devzone.nordicsemi.com/thread/342293?ContentTypeID=1</link><pubDate>Tue, 07 Dec 2021 10:55:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4d70332-6420-440f-af4c-a4394fb6ecd8</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Thank you &lt;a href="https://devzone.nordicsemi.com/members/ovrebekk"&gt;ovrebekk&lt;/a&gt;!!&lt;/p&gt;
[quote userid="2116" url="~/f/nordic-q-a/82425/nrf52840-sdk16---rtc-driver-general-questions---instance-initialization-and-channels/342241#342241"]Are you sure that you could not just use app_timer callbacks for your event generation?[/quote]
&lt;p&gt;My plan is to&amp;nbsp;connect RTC events with SAADC tasks through PPI. I&amp;#39;ve &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/46302/using-ppi-with-app-timer#:~:text=app_timer%20is%20a,or%20TIMER%20instance."&gt;read&lt;/a&gt; that is suggested to use RTC rather than application timer for this task (and more specifically RTC2 since RTC0 is reserved by the Soft Device and RTC1 by the application timer)&lt;/p&gt;
&lt;p&gt;What is the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__nrf__rtc__hal.html?cp=8_5_1_6_9_0_29_2"&gt;RTC HAL&lt;/a&gt;? I&amp;#39;ve noticed there are functions and macros not included in nrfx driver. Should I use&amp;nbsp;the&amp;nbsp;Hardware access layer in combination with nrfx?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SDK16 - RTC Driver general questions - instance, initialization, and channels</title><link>https://devzone.nordicsemi.com/thread/342241?ContentTypeID=1</link><pubDate>Tue, 07 Dec 2021 07:50:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aaf66fc5-95ad-4652-8954-a149f94a99e6</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Nick&lt;/p&gt;
[quote user=""]1. What I have understood so far is that the nRF52840 has&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/rtc.html?cp=4_0_0_5_21_9#topic"&gt;three RTCs&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;(RTC0, RTC1, RTC2). RTC0 is used by the SD and RTC1 from the application timer software. So it&amp;#39;s safer using RTC2 for events generation, right?[/quote]
&lt;p&gt;This is correct. The SoftDevice uses RTC0, and the app_timer uses RTC1, so if you use both then only RTC2 will be available to the application.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you sure that you could not just use app_timer callbacks for your event generation?&lt;/p&gt;
[quote user=""]2. What is the &lt;strong&gt;id&lt;/strong&gt; parameter when calling the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__nrfx__rtc.html?cp=8_5_1_6_9_0_29_1_4#gae1ce32a651d4e4a964b870707f4d3e54"&gt;NRFX_RTC_INSTANCE&lt;/a&gt;&amp;nbsp;macro for creating an RTC instance? For example, if I use RTC2 the &lt;strong&gt;id&lt;/strong&gt; value must be 2, while if I &lt;span&gt;use RTC2 the&amp;nbsp;&lt;/span&gt;&lt;strong&gt;id&lt;/strong&gt;&lt;span&gt;&amp;nbsp;value must be 1&lt;/span&gt;?[/quote]
&lt;p&gt;Yes. The ID parameter simply refers to the peripheral instance ID, so id 0 means RTC0, id 1 means RTC1 and so on.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you pick an ID that is already in use you should get an error message when compiling.&amp;nbsp;&lt;/p&gt;
[quote user=""]3.&amp;nbsp;&lt;span&gt;The PRESCALER register is a 12-bit register, meaning that the maximum value is 4095, giving a tick every 125 ms.&amp;nbsp;&lt;/span&gt;So,&amp;nbsp;with&amp;nbsp;the TICK event, the maximum event period is&amp;nbsp;limited to 125ms?[/quote]
&lt;p&gt;That is correct. If you want a longer event period you need to use a compare register and enable one of the compare events.&amp;nbsp;&lt;/p&gt;
[quote user=""]4. Each RTC has &lt;strong&gt;four&lt;/strong&gt; compare channels, right? The function to set a compare channel&amp;nbsp;is&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__nrfx__rtc.html?cp=8_5_1_6_9_0_29_1_9#ga527c0dc9807c1801eed001d47cbb1709"&gt;nrfx_rtc_cc_set&lt;/a&gt;.&amp;nbsp;According to the function&amp;#39;s description, the second parameter is the channel of the instance. So the value of this parameter could be 1,2,3, or 4? For example, can I use all of the four compare channels of RTC2 like this?[/quote]
&lt;p&gt;This is detailed &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/rtc.html?cp=4_0_0_5_21_9#topic"&gt;here&lt;/a&gt;. RTC0 has 3 CC registers, while RTC1 and RTC2 has 4 CC registers.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Your code looks correct to me. This should enable all four CC registers with different values, and interrupts enabled.&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>