<?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>nrf9160-dk getting value from switches</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/72629/nrf9160-dk-getting-value-from-switches</link><description>This compiles with warnings and the value always comes back as 0 
 #define SW1_NODE DT_ALIAS(sw1) #if DT_NODE_HAS_STATUS(SW1_NODE, okay) #define SW1 DT_GPIO_LABEL(SW1_NODE, gpios) #define SW1_PIN DT_GPIO_PIN(SW1_NODE, gpios) #define SW1_FLAGS DT_GPIO_FLAGS</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 11 Mar 2021 13:52:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/72629/nrf9160-dk-getting-value-from-switches" /><item><title>RE: nrf9160-dk getting value from switches</title><link>https://devzone.nordicsemi.com/thread/299301?ContentTypeID=1</link><pubDate>Thu, 11 Mar 2021 13:52:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a39cc80-5b48-4a2b-ab8c-7097415d867e</guid><dc:creator>paul_tanner</dc:creator><description>&lt;p&gt;Sorry, I had not changed the configure line and that explains the error message.&lt;/p&gt;
&lt;p&gt;That fixed, I have a clean build but the program was not seeing switch 1.&lt;/p&gt;
&lt;p&gt;I tracked this down to&amp;nbsp;&lt;span&gt; &lt;/span&gt;sw1 = &amp;amp;button3; in the &amp;lt;BOARD&amp;gt;_common.dts&lt;/p&gt;
&lt;p&gt;This translates to pin 7 which is wired to push button 2 on the DK board.&lt;/p&gt;
&lt;p&gt;So I changed the program to&amp;nbsp;#define SW1_NODE&lt;span&gt; &lt;/span&gt;DT_ALIAS(sw2)&lt;/p&gt;
&lt;p&gt;Which now picks up Switch 1.&amp;nbsp; I did not change the .dts file for the board in case it broke other stuff.&lt;/p&gt;
&lt;p&gt;So we can close this now.&amp;nbsp; Thx.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160-dk getting value from switches</title><link>https://devzone.nordicsemi.com/thread/299289?ContentTypeID=1</link><pubDate>Thu, 11 Mar 2021 13:33:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:045ad8ab-6aa5-4415-86ac-fc3a47c04269</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Also, have a&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.4.2/zephyr/samples/basic/button/README.html"&gt; look at the Button sample in Zephyr.&lt;/a&gt; This should do what you are looking for.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160-dk getting value from switches</title><link>https://devzone.nordicsemi.com/thread/299260?ContentTypeID=1</link><pubDate>Thu, 11 Mar 2021 12:55:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:62c6b724-e9c1-4206-9d67-da9aff0d0318</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;...&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;You have Zephyr OS v2.4, assuming you are using NCS v1.4.x.&lt;br /&gt;&lt;br /&gt;Have you configured correct PIN as per my last comment? From gpio.h&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * @brief Get logical level of an input pin.
 *
 * Get logical level of an input pin taking into account GPIO_ACTIVE_LOW flag.
 * If pin is configured as Active High, a low physical level will be interpreted
 * as logical value 0. If pin is configured as Active Low, a low physical level
 * will be interpreted as logical value 1.
 *
 * Note: If pin is configured as Active High, the default, gpio_pin_get()
 *       function is equivalent to gpio_pin_get_raw().
 *
 * @param port Pointer to the device structure for the driver instance.
 * @param pin Pin number.
 *
 * @retval 1 If pin logical value is 1 / active.
 * @retval 0 If pin logical value is 0 / inactive.
 * @retval -EIO I/O error when accessing an external GPIO chip.
 * @retval -EWOULDBLOCK if operation would block.
 */
static inline int gpio_pin_get(const struct device *port, gpio_pin_t pin)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160-dk getting value from switches</title><link>https://devzone.nordicsemi.com/thread/299192?ContentTypeID=1</link><pubDate>Thu, 11 Mar 2021 09:35:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d86705f-8b20-4356-b5c7-1afa51336392</guid><dc:creator>paul_tanner</dc:creator><description>&lt;p&gt;Hi @&amp;Oslash;yvind&lt;/p&gt;
&lt;p&gt;On the 9160dk the default for Switch 1 is pin 8 with alias sw1.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using ncs 2.4.&amp;nbsp; It seems it doesn&amp;#39;t include an&amp;nbsp;&lt;span&gt;http_update sample.&amp;nbsp; (I could not find any example of polling a switch.)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I just want to be able to poll the switch to get its value.&lt;/p&gt;
&lt;p&gt;The build output is:&lt;/p&gt;
&lt;p&gt;Including boilerplate (Zephyr base): /Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/cmake/app/boilerplate.cmake -- Application: /Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp -- Zephyr version: 2.4.0 (/Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr) -- Found Python3: /usr/local/bin/python3.7 (found suitable exact version &amp;quot;3.7.7&amp;quot;) found components: Interpreter -- Found west (found suitable version &amp;quot;0.7.2&amp;quot;, minimum required is &amp;quot;0.7.1&amp;quot;) -- Board: nrf9160dk_nrf9160ns -- Cache files will be written to: /Users/paul_tanner/Library/Caches/zephyr -- Found dtc: /usr/local/bin/dtc (found suitable version &amp;quot;1.6.0&amp;quot;, minimum required is &amp;quot;1.4.6&amp;quot;) -- Found toolchain: gnuarmemb (/Applications/ARM) -- Found BOARD.dts: /Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160ns.dts -- Found devicetree overlay: /Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/boards/nrf9160dk_nrf9160ns.overlay nrf9160dk_nrf9160ns.dts.pre.tmp:357.32-361.5: Warning (simple_bus_reg): /soc/cryptocell-sw: missing or empty reg/ranges property nrf9160dk_nrf9160ns.dts.pre.tmp:601.12-606.4: Warning (spi_bus_reg): /soc/peripheral@40000000/spi@b000/bme280@13: SPI bus unit address format error, expected &amp;quot;0&amp;quot; nrf9160dk_nrf9160ns.dts.pre.tmp:56.42-68.3: Warning (unique_unit_address_if_enabled): /soc/peripheral@40000000/flash-controller@39000: duplicate unit-address (also used in node /soc/peripheral@40000000/kmu@39000) nrf9160dk_nrf9160ns.dts.pre.tmp:305.19-311.3: Warning (unique_unit_address_if_enabled): /soc/peripheral@40000000/clock@5000: duplicate unit-address (also used in node /soc/peripheral@40000000/power@5000) warning: unit address and first address in &amp;#39;reg&amp;#39; (0x0) don&amp;#39;t match for /soc/peripheral@40000000/spi@b000/bme280@13 -- Generated zephyr.dts: /Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/build/zephyr/zephyr.dts -- Generated devicetree_unfixed.h: /Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/build/zephyr/include/generated/devicetree_unfixed.h Parsing /Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/Kconfig Loaded configuration &amp;#39;/Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160ns_defconfig&amp;#39; Merged configuration &amp;#39;/Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/prj.conf&amp;#39; Configuration saved to &amp;#39;/Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/build/zephyr/.config&amp;#39; Kconfig header saved to &amp;#39;/Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/build/zephyr/include/generated/autoconf.h&amp;#39; -- The C compiler identification is GNU 9.3.1 -- The CXX compiler identification is GNU 9.3.1 -- The ASM compiler identification is GNU -- Found assembler: /Applications/ARM/bin/arm-none-eabi-gcc Changed board to secure nrf9160dk_nrf9160 (NOT NS) === child image spm - begin === Including boilerplate (Zephyr base): /Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/cmake/app/boilerplate.cmake -- Application: /Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/spm -- Zephyr version: 2.4.0 (/Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr) -- Found Python3: /usr/local/bin/python3.7 (found suitable exact version &amp;quot;3.7.7&amp;quot;) found components: Interpreter -- Found west (found suitable version &amp;quot;0.7.2&amp;quot;, minimum required is &amp;quot;0.7.1&amp;quot;) -- Board: nrf9160dk_nrf9160 -- Cache files will be written to: /Users/paul_tanner/Library/Caches/zephyr -- Found dtc: /usr/local/bin/dtc (found suitable version &amp;quot;1.6.0&amp;quot;, minimum required is &amp;quot;1.4.6&amp;quot;) -- Found toolchain: gnuarmemb (/Applications/ARM) -- Found BOARD.dts: /Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160.dts -- Found devicetree overlay: /Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/spm/nrf9160dk_nrf9160.overlay nrf9160dk_nrf9160.dts.pre.tmp:56.42-68.3: Warning (unique_unit_address_if_enabled): /soc/peripheral@50000000/flash-controller@39000: duplicate unit-address (also used in node /soc/peripheral@50000000/kmu@39000) nrf9160dk_nrf9160.dts.pre.tmp:305.19-311.3: Warning (unique_unit_address_if_enabled): /soc/peripheral@50000000/clock@5000: duplicate unit-address (also used in node /soc/peripheral@50000000/power@5000) -- Generated zephyr.dts: /Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/build/spm/zephyr/zephyr.dts -- Generated devicetree_unfixed.h: /Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/build/spm/zephyr/include/generated/devicetree_unfixed.h Parsing /Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/Kconfig Loaded configuration &amp;#39;/Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_defconfig&amp;#39; Merged configuration &amp;#39;/Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/spm.conf&amp;#39; Merged configuration &amp;#39;/Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/build/spm/zephyr/misc/generated/extra_kconfig_options.conf&amp;#39; Configuration saved to &amp;#39;/Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/build/spm/zephyr/.config&amp;#39; Kconfig header saved to &amp;#39;/Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/build/spm/zephyr/include/generated/autoconf.h&amp;#39; -- The C compiler identification is GNU 9.3.1 -- The CXX compiler identification is GNU 9.3.1 -- The ASM compiler identification is GNU -- Found assembler: /Applications/ARM/bin/arm-none-eabi-gcc -- Configuring done -- Generating done -- Build files have been written to: /Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/build/spm === child image spm - end === CMake Warning at /Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/CMakeLists.txt:1331 (message): __ASSERT() statements are globally ENABLED -- Configuring done -- Generating done -- Build files have been written to: /Users/paul_tanner/Nordic/nrfsrc/ncs/nrf/samples/nrf9160/gps_udp/build -- west build: building application [1/266] Preparing syscall dependency handling [8/266] Performing build step for &amp;#39;spm_subimage&amp;#39; [1/197] Preparing syscall dependency handling [192/197] Linking C executable zephyr/zephyr_prebuilt.elf Memory region Used Size Region Size %age Used FLASH: 32 KB 48 KB 66.67% SRAM: 5600 B 64 KB 8.54% IDT_LIST: 56 B 2 KB 2.73% [197/197] Linking C executable zephyr/zephyr.elf [260/266] Linking C executable zephyr/zephyr_prebuilt.elf Memory region Used Size Region Size %age Used FLASH: 149600 B 976 KB 14.97% SRAM: 37752 B 128 KB 28.80% IDT_LIST: 168 B 2 KB 8.20% [266/266] Generating zephyr/merged.hex&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160-dk getting value from switches</title><link>https://devzone.nordicsemi.com/thread/299118?ContentTypeID=1</link><pubDate>Wed, 10 Mar 2021 19:26:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a575d07-a324-437d-90c8-0004c8af606e</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Can you please elaborate on what you are trying to achieve? What version of NCS are you working on?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What pin number are you trying to configure?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//This is you function call
gpio_pin_configure(sw1, GPIO_INPUT, GPIO_PULL_DOWN);

//From what I can see, you should change it to the following:
gpio_pin_configure(sw1, SW1_PIN, GPIO_PULL_DOWN);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Looking at how &lt;em&gt;gpio_pin_configure()&amp;nbsp;&lt;/em&gt;is configured in e.g. http_update sample:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define SW1_PIN (DT_GPIO_PIN(DT_ALIAS(sw1), gpios))
#define SW1_FLAGS (DT_GPIO_FLAGS(DT_ALIAS(sw1), gpios))

static int button_init(void)
{
	int err;

	gpiob = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(sw1), gpios));
	if (gpiob == 0) {
		printk(&amp;quot;Nordic nRF GPIO driver was not found!\n&amp;quot;);
		return 1;
	}
	err = gpio_pin_configure(gpiob, SW1_PIN, GPIO_INPUT | SW1_FLAGS);
	if (err == 0) {
		gpio_init_callback(&amp;amp;gpio_cb, fmfu_button_pressed, BIT(SW1_PIN));
		err = gpio_add_callback(gpiob, &amp;amp;gpio_cb);
	}
	if (err == 0) {
		fmfu_button_irq_enable();
	}
	if (err != 0) {
		printk(&amp;quot;Unable to configure SW1 GPIO pin!\n&amp;quot;);
		return 1;
	}
	return 0;
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;From &lt;em&gt;zephyr\include\drivers\gpio.h&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * @brief Configure a single pin.
 *
 * @param port Pointer to device structure for the driver instance.
 * @param pin Pin number to configure.
 * @param flags Flags for pin configuration: &amp;#39;GPIO input/output configuration
 *        flags&amp;#39;, &amp;#39;GPIO drive strength flags&amp;#39;, &amp;#39;GPIO pin drive flags&amp;#39;, &amp;#39;GPIO pin
 *        bias flags&amp;#39;, GPIO_INT_DEBOUNCE.
 *
 * @retval 0 If successful.
 * @retval -ENOTSUP if any of the configuration options is not supported
 *                  (unless otherwise directed by flag documentation).
 * @retval -EINVAL Invalid argument.
 * @retval -EIO I/O error when accessing an external GPIO chip.
 * @retval -EWOULDBLOCK if operation would block.
 */
static inline int gpio_pin_configure(const struct device *port,
				     gpio_pin_t pin,
				     gpio_flags_t flags)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Please provide full build output.&lt;br /&gt;&lt;br /&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>