Issue with Configuring GPIO P1.XX on nRF52

Problem Description:

I am trying to configure and control an LED connected to pin P1.07 on my nRF52 device, but I am experiencing issues. When I configure pin P1.07 as an output, I am unable to turn the LED on and off. However, if I use a pin on port P0 (e.g., P0.07), everything works correctly.

I noticed that the ports I had connected to P1 on my hardware were not functioning properly. I had conducted tests with the nRF52840 demo board using pins on P0, but due to layout issues, I had to use the external pins connected to P1 when I built the hardware. Now, I have the circuit and software ready, but the P1 ports are not working.

To isolate the problem, I stripped down all my code and tried to simply turn on an LED connected to pin P1.07.

Current Configuration:

  • SDK: Zephyr 2.6.1
  • Board: Custom board for my hardware
  • Example Project: Nordic BLE HIDS Keyboard
  • GPIO Configuration: I have enabled CONFIG_GPIO_NRF_P1=y in the prj.conf file.

Code Used:

#include <hal/nrf_gpio.h> // Include if using nRF specific features
#define LED_1 NRF_GPIO_PIN_MAP(1, 7)

void main(void)
{
    const struct device *dev = device_get_binding("GPIO_1");
    gpio_pin_configure(dev, LED_1, GPIO_OUTPUT);

    while (1)
    {
        gpio_pin_set(dev, LED_1, 1);
        k_sleep(K_MSEC(500));
        gpio_pin_set(dev, LED_1, 0);
        k_sleep(K_MSEC(500));
    }
}

Checks Performed:

  • I verified that CONFIG_GPIO_NRF_P1=y is enabled in the prj.conf file.
  • I checked the Device Tree to ensure that gpio1 is enabled:

&gpio1 {
    status = "okay";
};


Symptoms:

  • The LED does not turn on when using pin P1.07.
  • The code works correctly when using a pin on port P0 (e.g., P0.07).

Questions:

  1. Are there additional configurations necessary to use the pins on port P1 on nRF52 devices?
  2. Do I need to modify other settings in the Device Tree or elsewhere to properly enable port P1?

Thank you in advance for any help or suggestions!

Parents
  • Hi,
    You configuration seems correct. Could you confirm the following too?


    1. Please make sure that the P1.07 is not being used by any other peripherals etc.

    2. Is your LED properly connected to the P1.07? Maybe try changing to another pin on the same port to rule out any hardware issues with P1.07?

    3. You mention that when connecting to P0.07 the LED lights u. Do you use the same LED? Just to rule out that it might be an LED issue.

    Regards,

    Priyanka

  • Hi Priyanka,

    1. Please make sure that the P1.07 is not being used by any other peripherals etc.
    • Not used, the board is custom so there should be no problem.
    1. Is your LED properly connected to the P1.07? Maybe try changing to another pin on the same port to rule out any hardware issues with P1.07?
    • The LED is connected with the ground to GND and the positive to the pin.
    1. You mention that when connecting to P0.07 the LED lights up. Do you use the same LED? Just to rule out that it might be an LED issue.
    • The LED is the same, yes, I just changed the port from zero to one.

    I have tried other solutions and this seems to work, the problem is that it seems to work for the LEDs but not for the GPIOs. Do I need to use other settings or should these be the correct ones?

    I read somewhere that the pins of the GPIO1 port are not configurable in the same way as those of GPIO0. I wanted to understand if this is true. In my project, I was using the dk_buttons_and_leds file to manage LEDs and buttons. I don't think it works properly, or is it enough to make some modifications to the file?

    #include <hal/nrf_gpio.h> // Include if using nRF specific features
    // #define LED_BATTERY_75_100 NRF_GPIO_PIN_MAP(0, 17)
    #define LED_BATTERY_75_100 NRF_GPIO_PIN_MAP(1, 17)
    
    /* -------------------------------------------------------------------------- */
    /*                                     LED                                    */
    /* -------------------------------------------------------------------------- */
    
    void TurnLEDOn(uint32_t led_pin)
    {
        // nrf_gpio_cfg_output(led_pin);
        nrf_gpio_pin_clear(led_pin);
    }
    
    void TurnLEDOff(uint32_t led_pin)
    {
        // nrf_gpio_cfg_output(led_pin);
        nrf_gpio_pin_set(led_pin);
    }
    
    void WriteLEDState(uint32_t led_pin, uint32_t state)
    {
        nrf_gpio_pin_write(led_pin, state);
    }
    
    void ToggleLED(uint32_t led_pin)
    {
        nrf_gpio_cfg_output(led_pin);
        uint32_t state = nrf_gpio_pin_out_read(led_pin);
        if (state == 0)
        {
            nrf_gpio_pin_set(led_pin);
        }
        else
        {
            nrf_gpio_pin_clear(led_pin);
        }
    }
    
    /* -------------------------------------------------------------------------- */
    /*                                    MAIN                                    */
    /* -------------------------------------------------------------------------- */
    
    void configure_gpio(void)
    {
        // Configure GPIOs used by the application
    }
    
    void main(void)
    {
        configure_gpio(); // Configure the GPIOs used by the application
        nrf_gpio_cfg_output(LED_BATTERY_75_100);
    
        while (1)
        {
            TurnLEDOff(LED_BATTERY_75_100);
            k_sleep(K_MSEC(500));
            TurnLEDOn(LED_BATTERY_75_100);
            k_sleep(K_MSEC(500)); // Wait for 500 ms
        }
    }
    

    Thanks for your response.

Reply
  • Hi Priyanka,

    1. Please make sure that the P1.07 is not being used by any other peripherals etc.
    • Not used, the board is custom so there should be no problem.
    1. Is your LED properly connected to the P1.07? Maybe try changing to another pin on the same port to rule out any hardware issues with P1.07?
    • The LED is connected with the ground to GND and the positive to the pin.
    1. You mention that when connecting to P0.07 the LED lights up. Do you use the same LED? Just to rule out that it might be an LED issue.
    • The LED is the same, yes, I just changed the port from zero to one.

    I have tried other solutions and this seems to work, the problem is that it seems to work for the LEDs but not for the GPIOs. Do I need to use other settings or should these be the correct ones?

    I read somewhere that the pins of the GPIO1 port are not configurable in the same way as those of GPIO0. I wanted to understand if this is true. In my project, I was using the dk_buttons_and_leds file to manage LEDs and buttons. I don't think it works properly, or is it enough to make some modifications to the file?

    #include <hal/nrf_gpio.h> // Include if using nRF specific features
    // #define LED_BATTERY_75_100 NRF_GPIO_PIN_MAP(0, 17)
    #define LED_BATTERY_75_100 NRF_GPIO_PIN_MAP(1, 17)
    
    /* -------------------------------------------------------------------------- */
    /*                                     LED                                    */
    /* -------------------------------------------------------------------------- */
    
    void TurnLEDOn(uint32_t led_pin)
    {
        // nrf_gpio_cfg_output(led_pin);
        nrf_gpio_pin_clear(led_pin);
    }
    
    void TurnLEDOff(uint32_t led_pin)
    {
        // nrf_gpio_cfg_output(led_pin);
        nrf_gpio_pin_set(led_pin);
    }
    
    void WriteLEDState(uint32_t led_pin, uint32_t state)
    {
        nrf_gpio_pin_write(led_pin, state);
    }
    
    void ToggleLED(uint32_t led_pin)
    {
        nrf_gpio_cfg_output(led_pin);
        uint32_t state = nrf_gpio_pin_out_read(led_pin);
        if (state == 0)
        {
            nrf_gpio_pin_set(led_pin);
        }
        else
        {
            nrf_gpio_pin_clear(led_pin);
        }
    }
    
    /* -------------------------------------------------------------------------- */
    /*                                    MAIN                                    */
    /* -------------------------------------------------------------------------- */
    
    void configure_gpio(void)
    {
        // Configure GPIOs used by the application
    }
    
    void main(void)
    {
        configure_gpio(); // Configure the GPIOs used by the application
        nrf_gpio_cfg_output(LED_BATTERY_75_100);
    
        while (1)
        {
            TurnLEDOff(LED_BATTERY_75_100);
            k_sleep(K_MSEC(500));
            TurnLEDOn(LED_BATTERY_75_100);
            k_sleep(K_MSEC(500)); // Wait for 500 ms
        }
    }
    

    Thanks for your response.

Children
Related