Configuration of Digital Input/Output pins on nRF52

Hello everybody, I'm new to the Nordic system and the nRF52. I'm trying to become familiar with the board and I want to be able to read different 4 input pins, each one attached to the LEDs. In few words, I'm looking to do something like this.

if(button_1 pressed)
{
 led_1=on;
}


if(button_2 pressed)
{
 led_2=on;
}


if(button_3 pressed)
{
 led_3=on;
}


if(button_4 pressed)
{
 led_4=on;
}

I have tried the example that comes with the SKD pin_change_int_pca10040. I have tried to modify the code with no luck. Any advice will be appreciate it.

Would I be able to use the following function to change the state of the pin from 0 to 1?

nrf_drv_gpiote_out_set

Also, will this one will change the state of the pin from 1 to 0

nrf_drv_gpiote_out_clear

How could I read the state change on the pin?

Thank you for your help

  • I was looking something like this.

    I have done my own code. Sorry if the question was too simple, sometimes libraries fail starting from the most basic example.

    #include <stdbool.h>
    #include "nrf.h"
    #include "nrf_drv_gpiote.h"
    #include "app_error.h"
    #include "boards.h"
    
    
    #define GPIO_PIN_17     17
    #define GPIO_PIN_18     18
    #define GPIO_PIN_19     19
    #define GPIO_PIN_20     20
    
    #define GPIO_PIN_27     27
    #define GPIO_PIN_28     28
    #define GPIO_PIN_29     29
    #define GPIO_PIN_30     30
    
    #define S_ON     1
    #define S_OFF    0
    
    
    
    void gpio_init(void)
    {
    
    			// Pins as outputs
    	    nrf_gpio_range_cfg_input(27,30,NRF_GPIO_PIN_PULLUP);
    	
    			// Pins as inputs
    			nrf_gpio_range_cfg_output(17, 20);
    			
    }
    
    /**
     * @brief Function for application main entry.
     */
    int main(void)
    {
        gpio_init();
    
        while (true)
        {
    			
    			if(nrf_gpio_pin_read(GPIO_PIN_27))
    			{
    				nrf_gpio_pin_write(GPIO_PIN_17, S_OFF);
    			}
    			else
    			{
    				nrf_gpio_pin_write(GPIO_PIN_17, S_ON);
    			}
    			
    			if(nrf_gpio_pin_read(GPIO_PIN_28))
    			{
    				nrf_gpio_pin_write(GPIO_PIN_18, S_OFF);
    			}
    			else
    			{
    				nrf_gpio_pin_write(GPIO_PIN_18, S_ON);
    			}
    			
    			if(nrf_gpio_pin_read(GPIO_PIN_29))
    			{
    				nrf_gpio_pin_write(GPIO_PIN_19, S_OFF);
    			}
    			else
    			{
    				nrf_gpio_pin_write(GPIO_PIN_19, S_ON);
    			}
    			
    			if(nrf_gpio_pin_read(GPIO_PIN_30))
    			{
    				nrf_gpio_pin_write(GPIO_PIN_20, S_OFF);
    			}
    			else
    			{
    				nrf_gpio_pin_write(GPIO_PIN_20, S_ON);
    			}
    	
     
        }
    }
    
Related