<?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>GPIOTE polling</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/36284/gpiote-polling</link><description>Hi, 
 I&amp;#39;ve modified light switch client to read input from GPIO pins . I used int_pin_change as a reference for initializing inputs. The Int_change_pin example uses interrupts for detecting input but I need event polling in my application. When I set</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 11 Jul 2018 09:10:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/36284/gpiote-polling" /><item><title>RE: GPIOTE polling</title><link>https://devzone.nordicsemi.com/thread/139689?ContentTypeID=1</link><pubDate>Wed, 11 Jul 2018 09:10:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd609e74-f684-45d3-b3c2-6fb13e129491</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;The attached code shows how to use GPIOTE to detect toggle on the input pin and then toggle the output pin.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA
 * 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 * 
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 * 
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 * 
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 * 
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 */
/** @file
*
* @defgroup gpiote_example_main main.c
* @{
* @ingroup nrf_gpiote_example
* @brief GPIOTE Example Application main file.
*
* This file contains the source code for a sample application using GPIOTE.
*/

#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_gpiote.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;nrf_drv_ppi.h&amp;quot;
#include &amp;quot;nrf_drv_timer.h&amp;quot;
#include &amp;quot;nrf_drv_gpiote.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;

#ifdef BSP_LED_0
    #define GPIO_OUTPUT_PIN_NUMBER BSP_LED_0  /**&amp;lt; Pin number for output. */
#endif
#ifndef GPIO_OUTPUT_PIN_NUMBER
    #error &amp;quot;Please indicate output pin&amp;quot;
#endif

#define GPIO_INPUT_PIN_NUMBER   BSP_BUTTON_0

static void button_push_test(void)
{
	uint32_t gpiote_event_addr;
	uint32_t gpiote_task_addr;
	ret_code_t err_code;

	
	nrf_ppi_channel_t ppi_channel;
	
	// Configure input
	nrf_gpio_cfg_input(GPIO_INPUT_PIN_NUMBER, NRF_GPIO_PIN_NOPULL);
	
	nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
	in_config.pull = NRF_GPIO_PIN_PULLUP;
	
	err_code = nrf_drv_gpiote_in_init(GPIO_INPUT_PIN_NUMBER,&amp;amp;in_config, NULL); 
	APP_ERROR_CHECK(err_code);
	
	gpiote_event_addr = nrf_drv_gpiote_in_event_addr_get(GPIO_INPUT_PIN_NUMBER);
	
	
	// Configure output
	
	nrf_gpio_cfg_output(GPIO_OUTPUT_PIN_NUMBER);
	
	nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_TASK_TOGGLE(false);
	
	err_code = nrf_drv_gpiote_out_init(GPIO_OUTPUT_PIN_NUMBER, &amp;amp;out_config);
  APP_ERROR_CHECK(err_code);
	
	gpiote_task_addr = nrf_drv_gpiote_out_task_addr_get(GPIO_OUTPUT_PIN_NUMBER);

	
	// Set up PPI channel
	err_code = nrf_drv_ppi_channel_alloc(&amp;amp;ppi_channel);
  APP_ERROR_CHECK(err_code);
	
	
	err_code = nrf_drv_ppi_channel_assign(ppi_channel, gpiote_event_addr, gpiote_task_addr);
  APP_ERROR_CHECK(err_code);
	
  err_code = nrf_drv_ppi_channel_enable(ppi_channel);
  APP_ERROR_CHECK(err_code);
	
	// Enable GPIOTE
	nrf_drv_gpiote_in_event_enable(GPIO_INPUT_PIN_NUMBER,false);
  nrf_drv_gpiote_out_task_enable(GPIO_OUTPUT_PIN_NUMBER);
	
	
}

/**
 * @brief Function for application main entry.
 */
int main(void)
{
    ret_code_t err_code;

    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);
	
		button_push_test();

    while (true)
    {
        // Do Nothing - GPIO can be toggled without software intervention.
    }
}


/** @} */
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>