<?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>Using the DPPI on the nRF5340 to enable the ADC and GPIO toggling based on a hardware timer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/90268/using-the-dppi-on-the-nrf5340-to-enable-the-adc-and-gpio-toggling-based-on-a-hardware-timer</link><description>Hi, 
 
 I need to enable the ADC read and GPIO pin toggling to happen simultaneously at high precision, without using the MCU resources, approximately 15 us interval. After searching through this forum, I realized the only way to achieve this precision</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 27 Jul 2022 08:43:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/90268/using-the-dppi-on-the-nrf5340-to-enable-the-adc-and-gpio-toggling-based-on-a-hardware-timer" /><item><title>RE: Using the DPPI on the nRF5340 to enable the ADC and GPIO toggling based on a hardware timer</title><link>https://devzone.nordicsemi.com/thread/378843?ContentTypeID=1</link><pubDate>Wed, 27 Jul 2022 08:43:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bddaefb3-7eca-4992-beef-0ddaff16ddcc</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;I must admit I was not paying attention to whether you were using START or SAMPLE, my main focus was how to setup publish to several subscribers. But you are right, you should use SAMPLE to actually SAMPLE the analog input, while START simply prepare the ADC for the SAMPLE task. In general you may find the hardware description useful:&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/saadc.html"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf5340/saadc.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In terms of which api to use when setting up the publish and subscribe, I was looking at how you can write to the registers directly, but you can also setup this with a more convenient api like you have found also (they do the same, one is just a wrapper around the other).&lt;/p&gt;
&lt;p&gt;Glad to hear you have made it work!&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the DPPI on the nRF5340 to enable the ADC and GPIO toggling based on a hardware timer</title><link>https://devzone.nordicsemi.com/thread/378772?ContentTypeID=1</link><pubDate>Tue, 26 Jul 2022 15:48:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f2fdbd4-20de-4088-af87-a8c7d14354ae</guid><dc:creator>Ted H</dc:creator><description>&lt;p&gt;Kenneth, the SAADC still doesn&amp;#39;t work with your code but I managed to make it work!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The SAADC driver worked with the following code, but this helper layer didn&amp;#39;t work to assign a single event to trigger multiple tasks:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	nrfx_gppi_channel_endpoints_setup(dppi_channel,
		nrfx_timer_event_address_get(&amp;amp;timer1, NRF_TIMER_EVENT_COMPARE0),
		nrf_saadc_task_address_get(NRF_SAADC, NRF_SAADC_TASK_SAMPLE));
	
	err = nrfx_dppi_channel_enable(dppi_channel);
	if (err != NRFX_SUCCESS) {
		LOG_ERR(&amp;quot;Failed to enable (D)PPI channel, error: %08x&amp;quot;, err);
		return;
	}
	
	nrfx_dppi_channel_enable(dppi_channel);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So, instead of setting:&lt;br /&gt;NRF_SAADC-&amp;gt;&lt;span style="text-decoration:underline;"&gt;SUBSCRIBE_START&lt;/span&gt; = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_0;&lt;/p&gt;
&lt;p&gt;I modified it to:&lt;br /&gt;&lt;span&gt;NRF_SAADC&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span style="text-decoration:underline;"&gt;SUBSCRIBE_SAMPLE&lt;/span&gt;&lt;span&gt; = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | &lt;/span&gt;&lt;span&gt;dppi_channel_0&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Then the GPIO pin toggling worked simultaneously with the SAADC read!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Here is the portion of the code that allowed me to do that:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;	uint8_t dppi_channel;
	err = nrfx_dppi_channel_alloc(&amp;amp;dppi_channel);
	if (err != NRFX_SUCCESS) {
		LOG_ERR(&amp;quot;(D)PPI channel allocation error: %08x&amp;quot;, err);
		return;
	}

	NRF_TIMER1-&amp;gt;PUBLISH_COMPARE[0] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel;
	NRF_SAADC-&amp;gt;SUBSCRIBE_SAMPLE = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel;
	NRF_GPIOTE-&amp;gt;SUBSCRIBE_OUT[1] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel;

	nrfx_dppi_channel_enable(dppi_channel);	
	LOG_INF(&amp;quot;DPPI configured&amp;quot;);

	nrfx_gpiote_out_task_enable(PIN);
	LOG_INF(&amp;quot;nrfx_gpiote initialized&amp;quot;);

	nrfx_timer_enable(&amp;amp;timer1);
	printk(&amp;quot;TIMER1 started\n&amp;quot;);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Can you clarify why the original helper layer didn&amp;#39;t work but this publish/subscribe method worked? I was able to find another approach &lt;a href="https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/nrfx_timed_signal/src/main.c"&gt;here&lt;/a&gt;, and it &lt;span style="text-decoration:underline;"&gt;ties&lt;/span&gt;&amp;nbsp;the publish and subscribe sets like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;	/* Tie it all together */
	nrf_gpiote_publish_set(NRF_GPIOTE_EVENTS_IN_0, dppi_ch_1);
	nrf_gpiote_publish_set(NRF_GPIOTE_EVENTS_IN_1, dppi_ch_2);
	nrf_timer_subscribe_set(timer.p_reg, NRF_TIMER_TASK_START, dppi_ch_1);
	nrf_timer_subscribe_set(timer.p_reg, NRF_TIMER_TASK_STOP, dppi_ch_2);
	nrf_timer_subscribe_set(timer.p_reg, NRF_TIMER_TASK_CAPTURE0, dppi_ch_2);
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;I wonder which approach works best with setting up the DPPI module because I intend to use the DPPI more widely now and then. Can you explain why this approach failed to read the ADC channel but only the GPIO pin toggling worked:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	/* Allocate a (D)PPI channel. */
	uint8_t dppi_channel_0, dppi_channel_01;
	err = nrfx_dppi_channel_alloc(&amp;amp;dppi_channel_0);
	if (err != NRFX_SUCCESS) {
		LOG_ERR(&amp;quot;(D)PPI channel 0 allocation error: %08x&amp;quot;, err);
		return;
	}

	/* Configure endpoints of the channel so that the TIMER1 CAPTURE0
	 * event is connected with the SAADC SAMPLE task. This means that each time
	 * TIMER1 reaches it&amp;#39;s set compare value, the SAADC will sample all 
	 * enabled channel once.
	 */
	nrfx_gppi_channel_endpoints_setup(dppi_channel_0,
		nrfx_timer_event_address_get(&amp;amp;timer1, NRF_TIMER_EVENT_COMPARE0),
		nrf_saadc_task_address_get(NRF_SAADC, NRF_SAADC_TASK_SAMPLE));

	/* Enable (D)PPI channel. */
	err = nrfx_dppi_channel_enable(dppi_channel_0);
	if (err != NRFX_SUCCESS) {
		LOG_ERR(&amp;quot;Failed to enable (D)PPI channel 0, error: %08x&amp;quot;, err);
		return;
	}

	nrfx_gppi_channel_endpoints_setup(dppi_channel_1,
		nrfx_timer_event_address_get(&amp;amp;timer1, NRF_TIMER_EVENT_COMPARE0),
		nrfx_gpiote_out_task_addr_get(PIN));

	/* Enable (D)PPI channel. */
	err = nrfx_dppi_channel_enable(dppi_channel_1);
	if (err != NRFX_SUCCESS) {
		LOG_ERR(&amp;quot;Failed to enable (D)PPI channel 1, error: %08x&amp;quot;, err);
		return;
	}

	nrfx_gppi_channels_enable((1 &amp;lt;&amp;lt; dppi_channel_0) | (1 &amp;lt;&amp;lt; dppi_channel_1));
	LOG_INF(&amp;quot;DPPI configured&amp;quot;);

	nrfx_gpiote_out_task_enable(PIN);
	LOG_INF(&amp;quot;nrfx_gpiote initialized&amp;quot;);

	nrfx_timer_enable(&amp;amp;timer1);
	printk(&amp;quot;TIMER1 started\n&amp;quot;);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you for leading to the answer I was looking for!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Ted&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the DPPI on the nRF5340 to enable the ADC and GPIO toggling based on a hardware timer</title><link>https://devzone.nordicsemi.com/thread/378686?ContentTypeID=1</link><pubDate>Tue, 26 Jul 2022 11:04:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4aeb8b8-ada7-4615-9a1f-47ba75e1d06a</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Try something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	/* Allocate a (D)PPI channel. */
	uint8_t dppi_channel_0;
	err = nrfx_dppi_channel_alloc(&amp;amp;dppi_channel_0);
	if (err != NRFX_SUCCESS) {
		LOG_ERR(&amp;quot;(D)PPI channel 0 allocation error: %08x&amp;quot;, err);
		return;
	}

	NRF_TIMER1-&amp;gt;PUBLISH_COMPARE[0] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_0;
	NRF_SAADC-&amp;gt;SUBSCRIBE_START = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_0;
	NRF_GPIOTE-&amp;gt;SUBSCRIBE_OUT[1] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_0;

	static uint32_t dppi_all_channels_mask;

	dppi_all_channels_mask = (1 &amp;lt;&amp;lt; dppi_channel_0);

	nrfx_gppi_channels_enable(dppi_all_channels_mask);	

	LOG_INF(&amp;quot;DPPI configured&amp;quot;);

	nrfx_gpiote_out_task_enable(PIN);

	LOG_INF(&amp;quot;nrfx_gpiote initialized&amp;quot;);

	nrfx_timer_enable(&amp;amp;timer1);
	printk(&amp;quot;TIMER1 started\n&amp;quot;);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the DPPI on the nRF5340 to enable the ADC and GPIO toggling based on a hardware timer</title><link>https://devzone.nordicsemi.com/thread/378589?ContentTypeID=1</link><pubDate>Mon, 25 Jul 2022 21:25:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:481575af-1d74-470d-814f-df56b8165329</guid><dc:creator>Ted H</dc:creator><description>&lt;p&gt;So here is what I did but I still cannot get the ADC read working... The GPIO pin toggling only works. Am I missing something here?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	/* Allocate a (D)PPI channel. */
	uint8_t dppi_channel_0, dppi_channel_1;
	err = nrfx_dppi_channel_alloc(&amp;amp;dppi_channel_0);
	if (err != NRFX_SUCCESS) {
		LOG_ERR(&amp;quot;(D)PPI channel 0 allocation error: %08x&amp;quot;, err);
		return;
	}
	err = nrfx_dppi_channel_alloc(&amp;amp;dppi_channel_1);
	if (err != NRFX_SUCCESS) {
		LOG_ERR(&amp;quot;(D)PPI channel 1 allocation error: %08x&amp;quot;, err);
		return;
	}
	
	NRF_TIMER1-&amp;gt;PUBLISH_COMPARE[0] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_0;
	NRF_SAADC-&amp;gt;SUBSCRIBE_START = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_0;

	NRF_TIMER1-&amp;gt;PUBLISH_COMPARE[0] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_1;
	NRF_GPIOTE-&amp;gt;SUBSCRIBE_OUT[1] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_1;

	static uint32_t dppi_all_channels_mask;

	dppi_all_channels_mask = (1 &amp;lt;&amp;lt; dppi_channel_0) | (1 &amp;lt;&amp;lt; dppi_channel_1);

	nrfx_gppi_channels_enable(dppi_all_channels_mask);	

	LOG_INF(&amp;quot;DPPI configured&amp;quot;);

	nrfx_gpiote_out_task_enable(PIN);

	LOG_INF(&amp;quot;nrfx_gpiote initialized&amp;quot;);

	nrfx_timer_enable(&amp;amp;timer1);
	printk(&amp;quot;TIMER1 started\n&amp;quot;);&lt;/pre&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&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;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the DPPI on the nRF5340 to enable the ADC and GPIO toggling based on a hardware timer</title><link>https://devzone.nordicsemi.com/thread/378507?ContentTypeID=1</link><pubDate>Mon, 25 Jul 2022 10:07:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41510886-84b0-4829-97f8-50ba9971aafa</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;I can find various&amp;nbsp;code that show this to some degree, for instance ppi_init() from esb.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrfx_dppi_channel_alloc(&amp;amp;ppi_ch_radio_ready_timer_start);
nrfx_dppi_channel_alloc(&amp;amp;ppi_ch_radio_address_timer_stop);
nrfx_dppi_channel_alloc(&amp;amp;ppi_ch_timer_compare0_radio_disable);
nrfx_dppi_channel_alloc(&amp;amp;ppi_ch_timer_compare1_radio_txen);

NRF_RADIO-&amp;gt;PUBLISH_READY          = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | ppi_ch_radio_ready_timer_start;
ESB_SYS_TIMER-&amp;gt;SUBSCRIBE_START    = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | ppi_ch_radio_ready_timer_start;
// here you can add several subscribe if you like.
NRF_RADIO-&amp;gt;PUBLISH_ADDRESS        = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | ppi_ch_radio_address_timer_stop;
ESB_SYS_TIMER-&amp;gt;SUBSCRIBE_SHUTDOWN = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | ppi_ch_radio_address_timer_stop;
// here you can add several subscribe if you like.
ESB_SYS_TIMER-&amp;gt;PUBLISH_COMPARE[0] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | ppi_ch_timer_compare0_radio_disable;
NRF_RADIO-&amp;gt;SUBSCRIBE_DISABLE      = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | ppi_ch_timer_compare0_radio_disable;
// here you can add several subscribe if you like.
ESB_SYS_TIMER-&amp;gt;PUBLISH_COMPARE[1] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | ppi_ch_timer_compare1_radio_txen;
NRF_RADIO-&amp;gt;SUBSCRIBE_TXEN         = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | ppi_ch_timer_compare1_radio_txen;
// here you can add several subscribe if you like.

static uint32_t ppi_all_channels_mask;

ppi_all_channels_mask = (1 &amp;lt;&amp;lt; ppi_ch_radio_ready_timer_start) | (1 &amp;lt;&amp;lt; ppi_ch_radio_address_timer_stop) |
						(1 &amp;lt;&amp;lt; ppi_ch_timer_compare0_radio_disable) | (1 &amp;lt;&amp;lt; ppi_ch_timer_compare1_radio_txen);
							
nrfx_gppi_channels_enable(ppi_all_channels_mask);			&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the DPPI on the nRF5340 to enable the ADC and GPIO toggling based on a hardware timer</title><link>https://devzone.nordicsemi.com/thread/378366?ContentTypeID=1</link><pubDate>Fri, 22 Jul 2022 16:51:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb3103fd-5b49-4e7f-861c-ae0d00a2c2aa</guid><dc:creator>Ted H</dc:creator><description>&lt;p&gt;Hello Kenneth,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for the info. Do you have any SDK examples available for subscribing to those DPPI channels? It seems like the nrfx drivers do not offer many examples in the SDK...&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Ted&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using the DPPI on the nRF5340 to enable the ADC and GPIO toggling based on a hardware timer</title><link>https://devzone.nordicsemi.com/thread/378266?ContentTypeID=1</link><pubDate>Fri, 22 Jul 2022 11:09:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a37f9af-4ea3-4d83-93fb-e423c0abb078</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;When you alloc a dppi channel, then you can use this channel to connect severval publishers and subcribers, e.g. in this case you want to set the allocated channel to the TIMER-&amp;gt;PUBLISH_COMPARE[] register:&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/timer.html#register.PUBLISH_COMPARE"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf5340/timer.html#register.PUBLISH_COMPARE&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And then for each peripheral that you want to do something based on this event, then you need to set the subscribe, e.g. in your case set the came dppi channel to SAADC-&amp;gt;SUBSCRIBE_START and GPIOTE-&amp;gt;SUBSCRIBE_OUT[]:&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/saadc.html#register.SUBSCRIBE_START"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf5340/saadc.html#register.SUBSCRIBE_START&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/gpiote.html#register.SUBSCRIBE_OUT"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf5340/gpiote.html#register.SUBSCRIBE_OUT&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>