About GPIO pin problem.

Hello Developers,

I am working with the nRF52833 microcontroller using segger embedded studio with the latest SDK. My issue is that I can configure and use all GPIOs except P0.18. I'm unsure why this is happening.

In my case, I am using a basic LED blink code with a green LED, but when I try to toggle it using P0.18, it does not work. However, all other pins function correctly.

Can anyone help me to resolve this issue?

#include <stdio.h>
#include <nrf_gpio.h>


//LED1
#define G_LED1         NRF_GPIO_PIN_MAP(0,18)

#define LDO_TRANS_PIN2       NRF_GPIO_PIN_MAP(1, 1)


void configure_pins(void) 
{  
    nrf_gpio_cfg(G_LED1, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_CONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE); 
      
    nrf_gpio_cfg(LDO_TRANS_PIN1, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNEC_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE);
   
    nrf_gpio_pin_set(LDO_TRANS_PIN1);
  
}

void delay_ms(uint32_t ms) 
{
    for (uint32_t i = 0; i < (ms * 850); i++); 
}

void delay_s(uint32_t s) 
{
    delay_ms(s * 2000);
}



int main(void) 
{
    configure_pins();   
    
    while (1) 
    {
     nrf_gpio_pin_toggle(G_LED1);
     printf("G_LED1 status: %d\n", nrf_gpio_pin_read(G_LED1));
     delay_s(1);
    }
}

Parents
  • #include <stdio.h>
    #include <stdint.h>
    #include "nrf_gpio.h"
    #include "nrf_nvmc.h"
    #include "nrf.h"
    
    // Define GPIO Pins
    #define G_LED1         NRF_GPIO_PIN_MAP(0,18)  
    #define LDO_TRANS_PIN2 NRF_GPIO_PIN_MAP(1, 1)
    
    // Function to check and erase UICR if P0.18 is set as nRESET
    void disable_reset_pin(void) 
    {
        if (NRF_UICR->PSELRESET[0] != 0xFFFFFFFF || NRF_UICR->PSELRESET[1] != 0xFFFFFFFF) 
        {
            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een; // Enable erase mode
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy);
            
            NRF_NVMC->ERASEUICR = 1; // Erase UICR
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy);
            
            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; // Disable erase mode
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy);
            
            NVIC_SystemReset(); // Reset MCU to apply changes
        }
    }
    
    
    void configure_pins(void) 
    {  
        nrf_gpio_cfg(G_LED1, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_CONNECT, 
                     NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE); 
          
        nrf_gpio_cfg(LDO_TRANS_PIN2, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
                     NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE);
       
        nrf_gpio_pin_set(LDO_TRANS_PIN2); // Set P1.1 HIGH
    }
    
    
    void delay_ms(uint32_t ms) 
    {
        for (uint32_t i = 0; i < (ms * 850); i++); 
    }
    
    void delay_s(uint32_t s) 
    {
        delay_ms(s * 2000);
    }
    
    // Main function
    int main(void) 
    {
        disable_reset_pin();
        configure_pins();  
        
        while (1) 
        {
            nrf_gpio_pin_toggle(G_LED1);
            printf("G_LED1 status: %d\n", nrf_gpio_pin_read(G_LED1));
            delay_s(1);
        }
    }
    
    I am erasing the UICR but still the pin is not working as GPIO

  • This code is run following every NVIC_SystemReset(), which will stop the pin working as a GPIO:

        /* Configure GPIO pads as pPin Reset pin if Pin Reset capabilities desired. If CONFIG_GPIO_AS_PINRESET is not
          defined, pin reset will not be available. One GPIO (see Product Specification to see which one) will then be
          reserved for PinReset and not available as normal GPIO. */
        #if defined (CONFIG_GPIO_AS_PINRESET)
            if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) ||
                ((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))){
                NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; // Write Enable
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                NRF_UICR->PSELRESET[0] = 21;
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                NRF_UICR->PSELRESET[1] = 21;
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos; // Read-only Enable
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                // UICR changes require a reset to be effective
                NVIC_SystemReset();
            }
        #endif
    

    CONFIG_GPIO_AS_PINRESET is used in the project file Pre-Processor options list and must be either removed or altered say to "notCONFIG_GPIO_AS_PINRESET"

Reply
  • This code is run following every NVIC_SystemReset(), which will stop the pin working as a GPIO:

        /* Configure GPIO pads as pPin Reset pin if Pin Reset capabilities desired. If CONFIG_GPIO_AS_PINRESET is not
          defined, pin reset will not be available. One GPIO (see Product Specification to see which one) will then be
          reserved for PinReset and not available as normal GPIO. */
        #if defined (CONFIG_GPIO_AS_PINRESET)
            if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) ||
                ((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))){
                NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; // Write Enable
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                NRF_UICR->PSELRESET[0] = 21;
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                NRF_UICR->PSELRESET[1] = 21;
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos; // Read-only Enable
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                // UICR changes require a reset to be effective
                NVIC_SystemReset();
            }
        #endif
    

    CONFIG_GPIO_AS_PINRESET is used in the project file Pre-Processor options list and must be either removed or altered say to "notCONFIG_GPIO_AS_PINRESET"

Children
No Data
Related