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

Simple GPIO Example - nRF9160 DK

Hello,

I'm having difficulty getting the GPIO set up in a way that behaves predictably on the nRF9160 DK. As far as I understand it, the nRF52840 is what controls the GPIO on the board, and the nRF9160 has to send its requests through it to interact. However, some pins on the 9160 are routed directly to things like the LEDs or switches.

My goal is very simple - I need to control pins 2, 4, 6, and 7 during execution. But when I define the pins, the results are not as expected:

struct device *gpio_dev;
gpio_dev = device_get_binding(DT_GPIO_P0_DEV_NAME);
gpio_pin_configure(gpio_dev, 2, GPIO_DIR_OUT);
gpio_pin_write(gpio_dev, 2, 1);

Unfortunately, this does not pull P0.02 high, and instead illuminates one of the LEDs. Any advice would be appreciated!

As an aside, I find that the documentation rarely provides the final answer to my problems. I'm a beginner, but I'm also someone who digs for answers for hours at a time until he solves his problems. I would love to learn about each aspect of programming this board, but I don't know where to begin. A lot of the time I depend on grepping through entire directory trees to find symbols that my IDE could not. I have no idea where to find a guide to using prj.conf, .overlay files, and so on. It doesn't seem that there is a good tutorial that can bring someone up to speed from the beginning. And yes, I have used the getting started tutorials, looked at every example, and read tons of forum posts. It's still necessary for me to make posts here, unfortunately. There should be very simple example given for every feature listed on the product page, even if they're redundant.

Parents Reply Children
  • Hi,

    That should be correct. I've included a hex that toggles some LEDs and P0.17. Could you flash the hex to the board and see if it run?

    If it doesn't, then you are maybe missing secureboot?

    Jared 

    #include <zephyr.h>
    #include <device.h>
    #include <gpio.h>
    
    /* 1000 msec = 1 sec */
    #define SLEEP_TIME 	1000
    
    void main(void)
    {
    	int cnt = 0;
    	struct device *dev;
    
    	dev = device_get_binding("GPIO_0");
    	/* Set LED pin as output */
    	gpio_pin_configure(dev, 3, GPIO_DIR_OUT); //p0.03 == LED2
    	gpio_pin_configure(dev, 4, GPIO_DIR_OUT); //p0.04 == LED3
    	gpio_pin_configure(dev, 17, GPIO_DIR_OUT); //p0.17
    
    	while (1) {
    		/* Set pin to HIGH/LOW every 1 second */
    		gpio_pin_write(dev, 3, cnt % 2);	//p0.03 == LED2
    		gpio_pin_write(dev, 4, cnt % 2);	//p0.04 == LED3
    		gpio_pin_write(dev, 17, cnt % 2);	//p0.17 Toggling pin 17
    		cnt++;
    		k_sleep(SLEEP_TIME);
    	}
    }
    

    Togglepin.hex

  • Sorry Jared, I should have been more specific. The included hex file does run, and I'm able to see the output on the board.

    However, the pins that I need to use are the physical pins on the board. While the LEDs do light up when I set 3 and 4 to high, the actual pin itself sees no change in voltage.

    I need to use pins [P0.0]2, 4, 6, and 7 in order to interact with an Arduino shield. The documentation says that there is an Arduino interface, but nothing about how to activate it. Is that an nRF52840 only feature, or is it available for the nRF9160?

    Thanks,
    Justin

  • Hi,

    You didn't see any activity on P0.17 after programming the hex file? The pins that are available from the nRF91 are pins P0.10 - P0.20 and P0.0 and P0.01.

    Best regards

    Jared 

  • P0.17 was functional. But I need to use pins 2-7.

    "The pins that are available from the nRF91 are pins P0.10 - P0.20 and P0.0 and P0.01."

    Well, shoot. Where is this made known? Is there a way that I can use the 9160 to communicate with the 52840 to access these pins? They are pretty important for the task I purchased the board for.

    Thanks,
    Justin

  • I would suggest those pins are indeed available, but they have to be properly directed by the nRF52 to be i/o ports disconnected to buttons and LEDs by setting the appropriate nRF52 pin high to select the required i/o function.

    For example, P0.7 (nRF9160) can be connected to D7 by driving nRF52_P0.26 high (see U12 FSA2466UMX DPDT FET switch)
    D7 is available on P13 and P12, two headers which are marked not assembled but pads are available, and are not otherwise connected as far as I can see. These pins may be listed in the user Manual (I haven't checked), but are traceable on the schematic.

Related