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

GPIO PIN issue

Hello, 

  I am using NRF52840 development board with SDK 15.2. I am using the template peripheral project since i want to get comfortable with the peripherals on the board.  I have been trying to set some of the pins as outputs and then set them low or high with NRF_P0->OUT however i have not been able to change the output voltage on the pins. I am doing the following: 

nrf_gpio_cfg(NRF_P0->PIN_CNF[14], NRF_GPIO_PIN_DIR_OUTPUT, GPIO_PIN_CNF_INPUT_Disconnect, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0H1, NRF_GPIO_PIN_NOSENSE);
nrf_gpio_cfg(NRF_P0->PIN_CNF[15], NRF_GPIO_PIN_DIR_OUTPUT, GPIO_PIN_CNF_INPUT_Disconnect, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0H1, NRF_GPIO_PIN_NOSENSE);
nrf_gpio_cfg(NRF_P0->PIN_CNF[16], NRF_GPIO_PIN_DIR_OUTPUT, GPIO_PIN_CNF_INPUT_Disconnect, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0H1, NRF_GPIO_PIN_NOSENSE);

then i either set the output low with this NRF_P0->OUT &= 0x00000000; or high with this NRF_P0->OUT |= 0xffffffff;. 

When i connect an oscilloscope to the output pins, it does not matter whether i set them high or low  with NRF_P0->OUT |= 0xffffffff; or  NRF_P0->OUT &= 0x00000000; the voltage on the pin stays the same. 

Can anyone help me with this, i am not sure what i'm doing wrong. I've also tried using nrf_gpio_cfg_output(NRF_P0->PIN_CNF[6]); and nrf_gpio_pin_clear(NRF_P0->PIN_CNF[6]); on the pins without any results. I've looked at some of the examples in the SDK hoever i dont want to use the bsp package since ill be developing on a custom board. 

Parents
  • Unlike many simpler 8-bit devices most (all) ARM cores implement the io pin with separate out and in registers; reading the OUT register returns the last value written to the OUT register, not the value currently on the io pin. To read the pin, instead use the IN register. To further illustrate, look at the definition of nrf_gpio_pin_toggle() function.

    You can do a quick check by replacing "&=" with "=" and "|=" with "=" in your example, although of course you are driving all 32 pins on P0.

  • Im not trying to read the value on the pin, i'm trying to drive the pin high and measure it using an oscilloscope. Are you saying that NRF->P0->OUT = 0xFFFFFFFF will not drive the pins high? I am using  NRF->P0->OUT = 0xFFFFFFFF to try and drive all the pins high and see if i can measure a difference on the pins on the development board however that is not working. is this not what  NRF->P0->OUT is meant for? my guess is that im somehow not initializing the pins on the port correctly however i havent been able to verify that.

Reply
  • Im not trying to read the value on the pin, i'm trying to drive the pin high and measure it using an oscilloscope. Are you saying that NRF->P0->OUT = 0xFFFFFFFF will not drive the pins high? I am using  NRF->P0->OUT = 0xFFFFFFFF to try and drive all the pins high and see if i can measure a difference on the pins on the development board however that is not working. is this not what  NRF->P0->OUT is meant for? my guess is that im somehow not initializing the pins on the port correctly however i havent been able to verify that.

Children
  • The code you listed above in the first question shows "&=" (a read-modify-write operation) and not "=" (a write operation). Yes just "=" 0xFFFFFFFF should indeed set them all high, which is what I was trying to say.. sorry if I was just confusing. It may be that nrf_gpio_cfg_output() just expects a pin number, eg 6, and not the value you are passing.  See this example:

    //      Software Label  Id // Pin Name  Dir Function  Description
    //      =============== == // === ===== === ========= ===========
    #define LED_GREEN_PIN   30 //  29 P0.30 Out GPIO/AIN6 LED_GREEN
    
        //                 Pin Id                Pin Port Schematic
        //                 ===============       === ==== =========
        nrf_gpio_pin_set  (LED_GREEN_PIN   ); // 29 P0.30 LED_GREEN
        nrf_gpio_cfg(LED_GREEN_PIN,           // 29 P0.30 LED_GREEN
                     NRF_GPIO_PIN_DIR_OUTPUT,
                     NRF_GPIO_PIN_INPUT_DISCONNECT,
                     NRF_GPIO_PIN_NOPULL,
                     NRF_GPIO_PIN_H0S1,       // Require High Drive low level
                     NRF_GPIO_PIN_NOSENSE);
    

Related