<?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>Zephyr + NRF5340: change GPIO function in runtime</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/84368/zephyr-nrf5340-change-gpio-function-in-runtime</link><description>The project uses nRF5340. A signal is connected to P0.27/AIN6, and during &amp;quot;normal&amp;quot; mode the pin is used as an ADC. 
 Before going into sleep mode we would need this pin to become a GPIO Input with enabled interrupt, so as to waking up the MCU (and then</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 06 Feb 2022 19:32:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/84368/zephyr-nrf5340-change-gpio-function-in-runtime" /><item><title>RE: Zephyr + NRF5340: change GPIO function in runtime</title><link>https://devzone.nordicsemi.com/thread/351436?ContentTypeID=1</link><pubDate>Sun, 06 Feb 2022 19:32:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8440e9a-d0e6-447c-8e25-fc20371fe7b1</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I don&amp;#39;t think there should be any conflict in the device tree regarding the pin if you configure both the adc and the interrupt pin in the DT, this is because you don&amp;#39;t set the pin option for the ADC in the DT. As mentioned by Heidi in &lt;a href="https://devzone.nordicsemi.com/support-private/support/257472#permalink=606106"&gt;this reply&lt;/a&gt;:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;quot;Please note that you still need to configure the actual analog inputs (AIN0 to AIN7) in the main file&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So, if you would like to use P0.04, you&amp;nbsp;need to use Analog input associated with that pin,&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/chapters/pin.html?cp=3_0_0_8_0_0#aqfn94"&gt; which is AIN0&lt;/a&gt; (&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/29303/use-gpio-as-adc/116572#116572"&gt;hard wired&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Take a look at the sample &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.7.99-ncs1-rc1/samples/boards/nrf/battery/src/battery.c#L141"&gt;/zephyr/samples/boards/nrf/battery&lt;/a&gt; to see how it&amp;#39;s done.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr + NRF5340: change GPIO function in runtime</title><link>https://devzone.nordicsemi.com/thread/351395?ContentTypeID=1</link><pubDate>Fri, 04 Feb 2022 16:58:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24fa0704-7e36-442d-9621-89492912ffaa</guid><dc:creator>Bruno Saraiva</dc:creator><description>&lt;p&gt;So this is where I get confused - pardon me for the lack of experience with Zephyr:&lt;br /&gt;We know how to configure the pin using DT for EITHER of those functions... but what is the best practice when we need both? Can I simply ignore DT completely for this &amp;quot;dual function&amp;quot; pin? Or should I configure both functions of the pin in DT and disable the via register as mentioned? Note that&amp;nbsp;the project has a ton of other devices configured in DT, so that layer will still be there for the rest of the hardware.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr + NRF5340: change GPIO function in runtime</title><link>https://devzone.nordicsemi.com/thread/351394?ContentTypeID=1</link><pubDate>Fri, 04 Feb 2022 16:51:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d83c650d-5414-40bb-a149-d63d2b5a42c8</guid><dc:creator>Simon</dc:creator><description>[quote user="Bruno Saraiva"]Before I deeply analyze your code, reading from your description, it seems that the solution involves configuring both options in Zephyr&amp;#39;s Device Tree and then &amp;quot;disable&amp;quot; the one not being used directly by register control in run time...[/quote]
&lt;p&gt;Actually, I did not configure the ADC analog input pin and the interrupt pin in the Device Tree (DT). But if you want to do it the &amp;quot;proper&amp;quot; way, you should probably do it through the DT.&lt;/p&gt;
&lt;p&gt;Take a look at this reply to understand how to configure the ADC through the DT:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/support-private/support/257472#permalink=606106"&gt;https://devzone.nordicsemi.com/support-private/support/257472#permalink=606106&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Take a look at this DevZone case to see how to configure the gpio interrupt pin through the DT:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/72618/extra-gpios-in-board-overlay-for-nrf9160dk"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/72618/extra-gpios-in-board-overlay-for-nrf9160dk&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr + NRF5340: change GPIO function in runtime</title><link>https://devzone.nordicsemi.com/thread/351389?ContentTypeID=1</link><pubDate>Fri, 04 Feb 2022 16:28:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31cbf9d8-4b59-4d05-b8ef-34572cf9a229</guid><dc:creator>Bruno Saraiva</dc:creator><description>&lt;p&gt;Hi Simon,&lt;br /&gt;Thank you for the attention! We will implement this on our side to see how it goes.&lt;br /&gt;Before I deeply analyze your code, reading from your description, it seems that the solution involves configuring both options in Zephyr&amp;#39;s Device Tree and then &amp;quot;disable&amp;quot; the one not being used directly by register control in run time...&lt;br /&gt;I hope that this post becomes useful for more people up ahead.&lt;br /&gt;Cheers&lt;br /&gt;Bruno&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr + NRF5340: change GPIO function in runtime</title><link>https://devzone.nordicsemi.com/thread/351385?ContentTypeID=1</link><pubDate>Fri, 04 Feb 2022 16:09:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ac8dbbe0-013f-4fcd-a35d-313bb857d22c</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I did some testing&amp;nbsp;and was able to make this work by disconnecting the positive ADC channel.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First I setup ADC using &lt;code&gt;adc_channel_setup(&lt;/code&gt;) and triggered &lt;code&gt;adc_sample&lt;/code&gt;&lt;span&gt;&lt;code&gt;()&lt;/code&gt; right after&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;I used AIN0 as positive input (P0.04)&lt;/li&gt;
&lt;li&gt;I succesfully got an ADC measurement&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Then I ran &lt;code&gt;NRF_SAADC&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;CH&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;].&lt;/span&gt;&lt;span&gt;PSELP&lt;/span&gt;&lt;span&gt; = &lt;/span&gt;&lt;span&gt;0x00&lt;/span&gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Then I set up a GPIO interrupt, similar to how it&amp;#39;s done in&amp;nbsp;&lt;em&gt;\zephyr\samples\basic\button\src\main.c&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;I attached P0.04 and successfully got an interrupt&lt;/li&gt;
&lt;li&gt;Then I waited 10 seconds and set up ADC as in 1. and got an ADC measurement&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here is the sample (NCS v1.8.0):&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/6013.adc_5F00_gpio_5F00_interrupt_5F00_same_5F00_pin.zip"&gt;devzone.nordicsemi.com/.../6013.adc_5F00_gpio_5F00_interrupt_5F00_same_5F00_pin.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>