<?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>How Do I Re-Initialise a Timer?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/71499/how-do-i-re-initialise-a-timer</link><description>Hi, nRF newbie here, forgive me if I&amp;#39;m being dim. I&amp;#39;ve searched the devzone, can&amp;#39;t see obvious answers. nRF52840, SDK 17.0.2, Nordic SES 5.30a, using nrfx_* drivers I&amp;#39;m using one of the timers for bitbashing a bespoke serial bus, and want to re-initialise</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 11 Feb 2021 14:40:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/71499/how-do-i-re-initialise-a-timer" /><item><title>RE: How Do I Re-Initialise a Timer?</title><link>https://devzone.nordicsemi.com/thread/294011?ContentTypeID=1</link><pubDate>Thu, 11 Feb 2021 14:40:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:939a7659-a233-4d94-99fc-b577a64b0c0a</guid><dc:creator>benmack</dc:creator><description>&lt;p&gt;Thanks for confirming that&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How Do I Re-Initialise a Timer?</title><link>https://devzone.nordicsemi.com/thread/293934?ContentTypeID=1</link><pubDate>Thu, 11 Feb 2021 10:35:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbf43188-ccf9-47d3-a97f-66efed0aa0a3</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;yes, the basic concept is that.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;-Amanda H.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How Do I Re-Initialise a Timer?</title><link>https://devzone.nordicsemi.com/thread/293896?ContentTypeID=1</link><pubDate>Thu, 11 Feb 2021 07:58:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:23082dfe-d2b0-4f75-aeaf-9ed2a69114fe</guid><dc:creator>benmack</dc:creator><description>&lt;p&gt;Thanks for the reply&lt;/p&gt;
&lt;p&gt;Are you suggesting I do this:-&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void init_sbus_timer(void)
{
   uint32_t err_code = NRF_SUCCESS;
   nrfx_timer_config_t timer_cfg = NRFX_TIMER_DEFAULT_CONFIG;
   err_code = nrfx_timer_init(&amp;amp;TIMER_SBUS, &amp;amp;timer_cfg, timsbus_interrupt);
   if (err_code == NRFX_ERROR_INVALID_STATE)
   {
      err_code = nrfx_timer_uninit(&amp;amp;TIMER_SBUS);
      APP_ERROR_CHECK(err_code);
      err_code = nrfx_timer_init(&amp;amp;TIMER_SBUS, &amp;amp;timer_cfg, timsbus_interrupt);
   }
   APP_ERROR_CHECK(err_code);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;To be honest that seems a little clunky, I might just write my own init routine&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How Do I Re-Initialise a Timer?</title><link>https://devzone.nordicsemi.com/thread/293892?ContentTypeID=1</link><pubDate>Thu, 11 Feb 2021 07:29:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:933f7653-39cc-4027-83ca-c58e241b472d</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Because&amp;nbsp;&lt;span&gt;NRFX_ERROR_INVALID_STATE returned by&amp;nbsp;&lt;/span&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/group__nrfx__timer.html#ga4ff72f2933ca09b483ebabb9bbd8cdbc"&gt;nrfx_timer_init&lt;/a&gt;&lt;span&gt;() means t&lt;/span&gt;&lt;span&gt;he instance is already initialized,&amp;nbsp;&lt;/span&gt;I think you can initiate the time&amp;nbsp;&lt;span&gt;nrfx_timer_init() in the sub-function,&amp;nbsp;&lt;/span&gt;and &lt;span&gt;uninitialise&amp;nbsp;&lt;/span&gt;&lt;span&gt;and initialise&amp;nbsp;again&amp;nbsp;&lt;/span&gt;if it gets the&amp;nbsp;&lt;span&gt;NRFX_ERROR_INVALID_STATE.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-Amanda H.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How Do I Re-Initialise a Timer?</title><link>https://devzone.nordicsemi.com/thread/293852?ContentTypeID=1</link><pubDate>Wed, 10 Feb 2021 17:15:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4a39710-1fe4-45e1-b6f0-a4727b279d3c</guid><dc:creator>benmack</dc:creator><description>&lt;p&gt;Hi Amanda&lt;/p&gt;
&lt;p&gt;Thanks for the reply&lt;/p&gt;
&lt;p&gt;OK, so I have to uninitialise the timer before I reinitialise it...&lt;/p&gt;
&lt;p&gt;But my second question still stands - how do I do that, if I don&amp;#39;t know whether it is initialised?&lt;/p&gt;
&lt;p&gt;As I said, I tried &amp;quot;&lt;span style="font-family:courier new, courier;"&gt;if (nrfx_timer_is_enabled()) nrfx_timer_uninit();&lt;/span&gt;&amp;quot; but that gives an assert if it is not initialised.&lt;/p&gt;
&lt;p&gt;As you said, I can&amp;#39;t just call &lt;span style="font-family:courier new, courier;"&gt;nrfx_timer_uninit()&lt;/span&gt; as that gives an assert if it is not initialised.&lt;/p&gt;
&lt;p&gt;I need a &lt;span style="font-family:courier new, courier;"&gt;if(nrfx_timer_is_init())&lt;/span&gt; but that doesn&amp;#39;t exist&lt;/p&gt;
&lt;p&gt;Surely I&amp;#39;m not alone in wanting to do this? I normally re-init timers all the time on other platforms (e.g. STM32s). Maybe I should just write my own timer_init()...&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How Do I Re-Initialise a Timer?</title><link>https://devzone.nordicsemi.com/thread/293767?ContentTypeID=1</link><pubDate>Wed, 10 Feb 2021 12:59:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88b3ead9-af51-4b87-9999-9823379dd306</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]Which of course it won&amp;#39;t be, it is already initialised. Why won&amp;#39;t nrfx_timer_init() let me re-initialise it?[/quote]
&lt;p&gt;&lt;span&gt;NRFX_ERROR_INVALID_STATE returned by&amp;nbsp;&lt;/span&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/group__nrfx__timer.html#ga4ff72f2933ca09b483ebabb9bbd8cdbc"&gt;nrfx_timer_init&lt;/a&gt;() means t&lt;span&gt;he instance is already initialized.&lt;/span&gt;&lt;span&gt;&amp;nbsp;It only allows initializing&lt;/span&gt;&lt;span&gt;&amp;nbsp;if the instance&amp;nbsp;must not have already been initialized. That can avoid initializing the using timer by accident.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    if (p_cb-&amp;gt;state != NRFX_DRV_STATE_UNINITIALIZED)
    {
        err_code = NRFX_ERROR_INVALID_STATE;
        NRFX_LOG_WARNING(&amp;quot;Function: %s, error code: %s.&amp;quot;,
                         __func__,
                         NRFX_LOG_ERROR_STRING_GET(err_code));
        return err_code;
    }
&lt;/pre&gt;&lt;/p&gt;
[quote user=""]I tried adding &amp;quot;if (nrfx_timer_is_enabled()) nrfx_timer_uninit();&amp;quot; before nrfx_timer_init(), but both those funcs have&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;NRFX_ASSERT(m_cb[p_instance-&amp;gt;instance_id].state != NRFX_DRV_STATE_UNINITIALIZED);&lt;/span&gt;&lt;br /&gt;Why are these asserts here?[/quote]
&lt;p&gt;&lt;span&gt;&lt;/span&gt;nrfx_timer_uninit()&amp;nbsp;doesn&amp;#39;t check&amp;nbsp;the value of&amp;nbsp;state&amp;nbsp;itself, but it does call&amp;nbsp;nrfx_timer_disable(). nrfx_timer_disable() and &lt;span&gt;nrfx_timer_is_enabled()&amp;nbsp;&lt;/span&gt;do an&amp;nbsp;NRFX_ASSERT(m_cb[p_instance-&amp;gt;instance_id].state != NRFX_DRV_STATE_UNINITIALIZED).&amp;nbsp;If you call&amp;nbsp;nrfx_timer_uninit() and &lt;span&gt;nrfx_timer_is_enabled()&amp;nbsp;&lt;/span&gt;on&amp;nbsp;an uninitialized driver instance, you will get assert.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;-Amanda H.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>