<?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>Timer working only once</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/108641/timer-working-only-once</link><description>Hello, I want my timer to run all the time it is enabled. That&amp;#39;s my basic code for PPI SAADC and Timer usage. And it is printing only once, ive seen some samples from nrf too, but those were once usage only too. I had some experience with STM32 and if</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 27 Feb 2024 17:20:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/108641/timer-working-only-once" /><item><title>RE: Timer working only once</title><link>https://devzone.nordicsemi.com/thread/471113?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2024 17:20:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd2be14e-838c-4d76-905c-ca0094cc49dc</guid><dc:creator>Dzolo2k1</dc:creator><description>&lt;p&gt;Ok I got it, i had do initialise every channel separately so my channel_count macro works, and ofc im an idiot who didnt understand properly my code. I had to change a bit my buff req loop so it looks for samples count not channel count.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer working only once</title><link>https://devzone.nordicsemi.com/thread/471033?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2024 13:36:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8df756d4-d50f-457b-a56a-f92ac7490674</guid><dc:creator>Dzolo2k1</dc:creator><description>&lt;p&gt;Sadly, it doesnt work. I was trying to add this line of config before. &lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1709040906155v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;And still it does block itself from working again on evt_finished. I can do try to do it differently, but right now im just super curious what have i done wrong.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer working only once</title><link>https://devzone.nordicsemi.com/thread/470985?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2024 11:29:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:680be049-19ad-4126-94ee-ca2bf97cd1e5</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Can you add this line&amp;nbsp;before&amp;nbsp;nrfx_saadc_advanced_mode_set()?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;adv_config.start_on_end = true;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You then need to use&amp;nbsp;NRF_SAADC_TASK_SAMPLE as the endpoint.&lt;/p&gt;
&lt;p&gt;Alternatively you need to use two separate PPI channels, one between TIMER-&amp;gt;COMPARE0 and SAADC-&amp;gt;SAMPLE and one between SAADC-&amp;gt;END and SAADC-&amp;gt;START.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer working only once</title><link>https://devzone.nordicsemi.com/thread/470892?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2024 23:41:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7b43032-a098-4c8f-9baa-e5c80eab757e</guid><dc:creator>Dzolo2k1</dc:creator><description>&lt;p&gt;Oh yeah and ive change in endpoints setup NRF_SAADC_TASK_SAMPLE to NRF_SAADC_TASK_START&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer working only once</title><link>https://devzone.nordicsemi.com/thread/470891?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2024 23:40:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f74030b6-2482-49f9-9e95-47eec5eed7f1</guid><dc:creator>Dzolo2k1</dc:creator><description>&lt;p&gt;I&amp;#39;ve done some debugging and it is not entering nrfx_saadc_evt_done &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer working only once</title><link>https://devzone.nordicsemi.com/thread/470885?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2024 22:37:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ecca027-ff4c-4095-9487-83aa5a3b172b</guid><dc:creator>Dzolo2k1</dc:creator><description>&lt;p&gt;Hello, I still have a problem. Sadly it is not working in loop or actually it is, cuz if i trigger Timer callback i can see its workin in loop, but somehow my SAADC starts only once. Im completely stuck. &lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;quot;nrfx_saadc.h&amp;quot;
#include &amp;lt;nrfx_timer.h&amp;gt;
#include &amp;lt;nrfx_gpiote.h&amp;gt;
#include &amp;lt;nrfx_log.h&amp;gt;
#include &amp;lt;helpers/nrfx_gppi.h&amp;gt;
#include &amp;lt;nrfx_ppi.h&amp;gt;
#define ANALOG_INPUT_TO_SAADC_AIN(x) ((x) + 1)


#define TIMER_INST_IDX 0
#define TIME_TO_WAIT_MS 3300UL

#define CH0_AIN ANALOG_INPUT_TO_SAADC_AIN(1)
#define CH1_AIN ANALOG_INPUT_TO_SAADC_AIN(2)
#define CH2_AIN ANALOG_INPUT_TO_SAADC_AIN(3)

#define CHANNEL_COUNT NRFX_ARRAY_SIZE(m_multiple_channels)


#define BUFFER_SIZE 3UL
#define BUFFER_COUNT 3UL

static const nrfx_saadc_channel_t m_multiple_channels[] =
{
    NRFX_SAADC_DEFAULT_CHANNEL_SE(CH0_AIN, 0),
    NRFX_SAADC_DEFAULT_CHANNEL_SE(CH1_AIN, 1),
    NRFX_SAADC_DEFAULT_CHANNEL_SE(CH2_AIN, 2)
};

static uint8_t m_gppi_channels[3];
static nrf_saadc_value_t value_buffer[CHANNEL_COUNT];

static void timer_handler(nrf_timer_event_t event_type, void * p_context){
      
}

nrfx_timer_t timer_inst = NRFX_TIMER_INSTANCE(TIMER_INST_IDX);


static void saadc_handler(nrfx_saadc_evt_t const * p_event){
    nrfx_err_t status;
    (void)status;

    static uint16_t buffer_index = 1;
    static uint16_t buf_req_evt_counter;
    uint16_t samples_number;
switch(p_event-&amp;gt;type)
    {
        case NRFX_SAADC_EVT_CALIBRATEDONE:

            status = nrfx_saadc_mode_trigger();
            NRFX_ASSERT(status == NRFX_SUCCESS);
            break;

        case NRFX_SAADC_EVT_READY:

            break;

        case NRFX_SAADC_EVT_BUF_REQ:
            NRFX_LOG_INFO(&amp;quot;SAADC event: BUF_REQ&amp;quot;);

            if (++buf_req_evt_counter &amp;lt; 3)
            {
                status = nrfx_saadc_buffer_set(value_buffer[buffer_index++], BUFFER_SIZE);
                buffer_index = buffer_index % BUFFER_COUNT;
                if(status != NRFX_SUCCESS)
			    {
				LOG_ERR(&amp;quot;Error! Could not set buffer: %d\n&amp;quot;, status);
			    }
            }
            
            break;
        case NRFX_SAADC_EVT_DONE:

            samples_number = p_event-&amp;gt;data.done.size;
            for (uint16_t i = 0; i &amp;lt; samples_number; i++)
            {
                printf(&amp;quot;[Sample %u] value == %d\n&amp;quot;, i, p_event-&amp;gt;data.done.p_buffer[i]);
            }
            break;

        

        default:
            break;
    }
}

static void Timer_init(void){

    nrfx_err_t err; 

    (void)err;


    uint32_t base_frequency = NRF_TIMER_BASE_FREQUENCY_GET(timer_inst.p_reg);

    nrfx_timer_config_t config = NRFX_TIMER_DEFAULT_CONFIG(base_frequency);

    config.bit_width = NRF_TIMER_BIT_WIDTH_32;

    err = nrfx_timer_init(&amp;amp;timer_inst, &amp;amp;config, timer_handler);

    nrfx_timer_clear(&amp;amp;timer_inst);

    uint32_t desired_ticks = nrfx_timer_ms_to_ticks(&amp;amp;timer_inst, TIME_TO_WAIT_MS);


    nrfx_timer_extended_compare(&amp;amp;timer_inst, NRF_TIMER_CC_CHANNEL0, desired_ticks,
                                NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);                           

     
    
    
}
void saadc_init(void){

    nrfx_err_t err; 

    (void)err;

    err = nrfx_saadc_init(NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY);

    err = nrfx_saadc_channels_config(m_multiple_channels, CHANNEL_COUNT);

    uint32_t channel_mask = nrfx_saadc_channels_configured_get();

    nrfx_saadc_adv_config_t adv_config = NRFX_SAADC_DEFAULT_ADV_CONFIG;

    err = nrfx_saadc_advanced_mode_set(channel_mask,
                                          NRF_SAADC_RESOLUTION_8BIT,
                                          &amp;amp;adv_config,
                                          saadc_handler);
  
    err = nrfx_saadc_buffer_set(&amp;amp;value_buffer, CHANNEL_COUNT);

    err = nrfx_saadc_offset_calibrate(saadc_handler);

    }

int main(void)
{
    nrfx_err_t err; 

    saadc_init(); 

    Timer_init();

    uint8_t channel;
	err = nrfx_gppi_channel_alloc(&amp;amp;channel);
    
    nrfx_gppi_channel_endpoints_setup(
        channel,
		nrfx_timer_event_address_get(&amp;amp;timer_inst, NRF_TIMER_EVENT_COMPARE0),
		nrf_saadc_task_address_get(NRF_SAADC, NRF_SAADC_TASK_SAMPLE));

    nrfx_gppi_channels_enable(BIT(channel));                         

    #if defined(__ZEPHYR__)
    IRQ_DIRECT_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_SAADC), IRQ_PRIO_LOWEST, nrfx_saadc_irq_handler, 0);
    #endif
    #if defined(__ZEPHYR__)
    IRQ_DIRECT_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_TIMER_INST_GET(TIMER_INST_IDX)), IRQ_PRIO_LOWEST,
                       NRFX_TIMER_INST_HANDLER_GET(TIMER_INST_IDX), 0);
    IRQ_DIRECT_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_GPIOTE), IRQ_PRIO_LOWEST, nrfx_gpiote_irq_handler,
                       0);
    #endif      
    nrfx_timer_enable(&amp;amp;timer_inst);

        while(1){}

        return 0;
}


&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer working only once</title><link>https://devzone.nordicsemi.com/thread/470715?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2024 12:17:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:391bc6cf-d062-4b6d-86d2-98b80b352a50</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Some of the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/hardware_drivers_desc.html"&gt;drivers are described in nRF5 documentation&lt;/a&gt;, but the APIs does not match 100% to the nrfx driver APIs, see &lt;a title="Migration guide for nrfx drivers" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/nrfx_migration_user_guide.html?cp=9_1_2_7"&gt;Migration guide for nrfx drivers&lt;/a&gt;. The HAL APIs are only documented in the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.2/nrfx/api_reference.html"&gt;nrfx API documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For nRF Connect SDK, it is recommended to use the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.2/zephyr/hardware/peripherals/index.html"&gt;Zephyr driver APIs&lt;/a&gt; whenever possible.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer working only once</title><link>https://devzone.nordicsemi.com/thread/470709?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2024 12:09:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c194c944-e198-4fe0-be73-0c5d8f9a3453</guid><dc:creator>Dzolo2k1</dc:creator><description>&lt;p&gt;Oh god, thank you. But im wondering is there any doc. explains the functions in HAL/drivers? I know there are samples and some basic&amp;nbsp;explanations about functions in .h file, but im asking about some more knowledge. Cuz right now im just reading HW documents from nrf52840 and trying to figure out what to use from .h files&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer working only once</title><link>https://devzone.nordicsemi.com/thread/470696?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2024 11:48:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c95318db-4bd3-4447-ae1d-7e7ed0dbce79</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;If you want a recurring timer, you need to change the parameter passed to nrfx_timer_extended_compare() from&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__nrf__timer__hal.html#gga1dee3ab20f9dfa38bacf2502a8d1688cae953a4526a33bba2c89e2f240f7957d3"&gt;NRF_TIMER_SHORT_COMPARE0_&lt;strong&gt;STOP&lt;/strong&gt;_MASK&lt;/a&gt; to&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__nrf__timer__hal.html#gga1dee3ab20f9dfa38bacf2502a8d1688ca98029953aa61f28bc923ff4ff9ab3a1d"&gt;NRF_TIMER_SHORT_COMPARE0_&lt;strong&gt;CLEAR&lt;/strong&gt;_MASK&lt;/a&gt;. The STOP mask will stop the timer once the COMPARE0 is generated, while the CLEAR mask will clear the counter in the timer, practically restarting it.&lt;/p&gt;
&lt;p&gt;Note that you have set the&amp;nbsp;&lt;em&gt;enable_int&lt;/em&gt;&lt;span&gt;&amp;nbsp;parameter to false, which means that there will be no interrupt generated from the event, and the timer handler will not be run. This is useful if you are using the event for triggering SAADC sampling using PPI.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>