This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Basic GPIO on NRF52840 Development Kit

Hi, 

I'm trying to wrap my head around doing some basic GPIO reading, writing etc. and hopefully some interrupts. Apologies if these are basic questions - I've only really had experience within the Arduino framework before this.

I've got a NRF52840 Development Kit and I'm using NRF Connect for VSCode with NRF Connect v1.9.1

I've gone through the blinky and button examples, and I can get them working, and change them to address different leds/buttons. However, I'm not sure how to generalise this to other pins.

I've read a whole load of forum posts and I'm confused as to the difference between all the seemingly different GPIO libraries: what's the distinction between the libraries "drivers/gpio.h", "nrf_gpio.h", purely "gpio.h", GPIO HAL, GPIOTE, GPIO, "device.h"? Would I need to adjust the CMakeLists.txt to use these?

Are there multiple libraries for controlling GPIO things?

I've found various GPIO headers under both NRFX  (https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfx/drivers/gpio/hal.html#c.NRF_GPIO_PIN_MAP) and Zephyr (https://docs.zephyrproject.org/latest/reference/peripherals/gpio.html?highlight=gpio_pin_configure#c.gpio_pin_configure) etc.

I've also seen that a bunch of the forum posts are a) from about 5 years ago and b) referencing NRF SDK as opposed to NRF Connect SDK. Has there been an update to the GPIO libaries since then and is there a stark difference between the libraries available in the different SDKs?

Lastly, I've got a bit confused about the Devicetree in general. As I understand it, it's a set of files that contains a description of the hardware for each board so the program can find e.g. which pin is connected to an LED. If I wanted to say use pin P0.09 to control an LED that I'd wired in externally to the board, would I need to add in a new thing in the nrf52840dk_nrf52840.dts file?

  • Hi Benjamin, 

    nRF Connect SDK is our new platform and it's the platform that we will continue develop in the future. The nRF5 SDK is our legacy SDK and we stopped development on this SDK (We still support it and still provide bug fixes). 
    nRF Connect SDK has a quite steep learning curve that could be a challenge for many, including me who works at Nordic. 

    For your need I would suggest to have a look at the device tree documentation here. And we have a guide here that could be very useful for you.

    If you simply want to add an LED to your nRF5DK you can simply add an overlay file to the board to add new LED. If you are going to make your own board, you may better create a new device tree file for your board (dts). 

    I attached here a modified version of the blinky example that I added a new 2 LEDs into the board on pin P0.11 and P0.12 . Please take a look at the .overlay file inside boards folder. 

    1258.blinky_custom.zip

  • Thanks, I've read through those documentation pages you linked and they were very helpful.

    With regards to the blinky_custom example you linked, I'm getting some errors when trying to run it.

    This error happens when first building the file: 

      

    Trying to build the file similarly gives some errors:

    Looking through the code, my guess of some possible errors are:

    • in line 52 of the main.c, it should be 'dev2' not 'dev' inside gpio_pin_configure()
    • in line 8 of the .overlay file, it should be 'myled1 : led_1' instead of 'myled0led1 : led_1'
    • in line 17 of the .overlay file, it should be 'myled1 = &myled1' instead of 'myled1 = &myled0'

    - though it is entirely possible I'm misunderstanding the code layout.

    I also noticed the .overlay was labelled as 'nrf52dk_nrf52832.overlay' which I assume should be changed to 'nrf52840dk_nrf52840.overlay' for my specific board? I think that was at least part of the problem as the .overlay is now showing up in the device tree interface

  • Hi Benjamin, 

    You are right. I was just focusing on creating one extra LED and not the 2nd one (led1). 
    Could you try to compile it for nRF52832dk to see if you get any error ? 
    I believe you just need to change the name of the .overlay file to nrf52840dk_nrf52840.overlay and it should work. 

  • Hi,

    I've managed to get it compiling now - I believe the error was that I had underscores in my alias names, which seems to stop the compiler from being able to find any header files? Not sure why that is, but seemed consistent.

    I've attached the program I ended up with:

    blinky_ext_led.zip

    There are still warnings when it compiles, but I'm guessing these are all fine?:

  • Hi Benjamin, 

    Did it work ? Do you see any voltage on the pin ? 

    I don't think it's an issue with the warnings from VS Code. What's important is if the log in the compiler terminal show any error or warning. 

Related