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

nRF9160 DK : activating GPIO

Hello,

 I have been working to manipulate GPIO.

I succeeded to turn on and off P0.02 ~ P0.05 (LED 1~4). However, I cannot get P0.00 and P0.01 to get work.

GPIO IN seems to work because I looped back the 5V and I get 1 as a result but GPIO OUT doesn't work at all.

I measured with a multimeter but it mesaures no voltage.

I referenced to following examples and Q&A:

https://devzone.nordicsemi.com/f/nordic-q-a/43774/simple-gpio-example---nrf9160-dk

https://devzone.nordicsemi.com/f/nordic-q-a/44940/simple-gpio-example---nrf9160-dk-2

I added my project to the git, please take a look at it if you need more reference to help me.

https://github.com/CerfVert94/nRF9160-GPIO

I added the following lines to KConfig.deconfig :

config GPIO
    bool
    default y
    depends on SPI && SOC_FAMILY_NRF

I commented out uart1 that uses pin P0.00 and P0.01 in nrf9160_pca10090_common.dts; just in case.

/*
&uart1 {
    status = "ok";
    current-speed = <115200>;
    tx-pin = <1>;
    rx-pin = <0>;
    rts-pin = <14>;
    cts-pin = <15>;
};
*/

I use the non-secure boot, so added nrf9160_pca10090ns.overlay file, which contains the following lines :

&spi3 {
    status = "ok";
    sck-pin = <10>;
    mosi-pin = <11>;
    miso-pin = <12>;
    ss-pin = <13>;
    spi-max-frequency = <4000000>;
};

All these config / overlay files are in path/ncs/nrf/applications/MY_PROJECT/ , where CMakeLists.txt is located.

The following is my code :

static void gpio_init(void)
{
  const char* const gpioName = "GPIO_0";
  gpio_dev = device_get_binding(gpioName);
 
  if (gpio_dev == NULL) {
    printk("Could not get %s device\n", gpioName);
    return;
  }
  printk("Successfully initialised %s device\n", gpioName);
 
  if(gpio_pin_configure(gpio_dev, PIN1, GPIO_DIR_OUT) < 0)
    printk("Could not configure pin P0.%02d\n", PIN1);
  if(gpio_pin_configure(gpio_dev, PIN2, GPIO_DIR_OUT ) < 0)
    printk("Could not configure pin P0.%02d\n", PIN2);
}
static void spi_init(void)
{
  const char* const spiName = "SPI_3";
  spi_dev = device_get_binding(spiName);  

  if (spi_dev == NULL) {
    printk("Could not get %s device\n", spiName);
    return;
  }
  printk("Successfully initialised %s device\n", spiName);
}
void main(void)
{
  printk("Application started\n");
  gpio_init();


  spi_init();
      if (!gpio_pin_write(gpio_dev, PIN1, 1))
        printf("1. P0.%02d : write 1\n", PIN1);
      if (!gpio_pin_write(gpio_dev, PIN2, 1))
        printf("2. P0.%02d : write 1\n", PIN2);
  while(1);
}

I want to manipulate Chip Select signal during SPI communication but I can't manipulate GPIO ... could you help me, please?

Parents
  • I tested your example, and it worked as expected. (I modified your project slightly by removing target_sources(app PRIVATE src/SD.c) from CMakeListst.txt).

    I measured 1.79 volt across both P0.00 and P0.01 with a multimeter. I also connected an external LED in series with a resistor and was able to light it up.

    Are you sure you have configured the multimeter correctly? Could you try to attach an LED+resistor and check the results. If it you still have problems, please tell me, and I will look into it.

    Best regards,

    Simon

Reply
  • I tested your example, and it worked as expected. (I modified your project slightly by removing target_sources(app PRIVATE src/SD.c) from CMakeListst.txt).

    I measured 1.79 volt across both P0.00 and P0.01 with a multimeter. I also connected an external LED in series with a resistor and was able to light it up.

    Are you sure you have configured the multimeter correctly? Could you try to attach an LED+resistor and check the results. If it you still have problems, please tell me, and I will look into it.

    Best regards,

    Simon

Children
  • Hello,

    I resolved the issue this morning as well.

    I rebuilt the solution and it measured about 1.8V.

    The time that I mesaured the voltage with multimeter, I think I have misconfigured the project.

    And then I assumed that the DK would give 3.3V across the GPIO pins and 1.8V is not enough to light it up.

    I used a transistor and resistors to flash the LED.

    So, long story short, it was bad on my part.

    Thank you

Related