This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

GPIOTE polling

Hi,

I'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 the value of GPIOTE_CONFIG_IN_SENSE_TOGGLE to false and download the code to nrf52DK all the LEDs are turned on. My application works with the interrupt mode, so I'm assuming the issue is not related to application. How do I configure GPIOTE_CONFIG_IN_SENSE_TOGGLE to detect input in event mode?

Thanks,

Sunil

  • FormerMember
    +1 FormerMember

    The attached code shows how to use GPIOTE to detect toggle on the input pin and then toggle the output pin.

     

    /**
     * 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 "AS IS" 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 <stdbool.h>
    #include <stdint.h>
    #include "nrf.h"
    #include "nrf_gpiote.h"
    #include "nrf_gpio.h"
    #include "boards.h"
    #include "nrf_drv_ppi.h"
    #include "nrf_drv_timer.h"
    #include "nrf_drv_gpiote.h"
    #include "app_error.h"
    
    #ifdef BSP_LED_0
        #define GPIO_OUTPUT_PIN_NUMBER BSP_LED_0  /**< Pin number for output. */
    #endif
    #ifndef GPIO_OUTPUT_PIN_NUMBER
        #error "Please indicate output pin"
    #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,&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, &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(&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.
        }
    }
    
    
    /** @} */
    

Related