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

Setting GPIO pin as output pin

I am using nrf51822 DK. How to set GPIO pins as output pins and access the pins to set or reset the output.For example if I want to use pin 20 as output, how to configure that.I need the code syntax to do that. Can you please point out to any examples or code snippets if any? Can you also please tell me how to configure LEDs output on the board. There are four LEDs on the board. For example if I want to toggle 4th LED how to do that?

  • You are probably looking for LED blinky example in SDK v12.3.0 (the newest which supports nRF51 chips).

    (As this is pretty basic example mentioned in every beginners' tutorial one would wonder how long have you tried to solve your question yourself before posting to the forum;)

  • Hi Nikhil!

    As endnode said in his answer, the blinky example is a good place to start.

    In my opinion the easiest way to control the LED is to use the nrf_gpio interface directly.

    • Configuring a pin as output: nrf_gpio_cfg_pin_output(pin_number);

    • Turn on/off the led: nrf_gpio_pin_set(pin_number); / nrf_gpio_pin_clear(pin_number);

    • Toggle the LED: nrf_gpio_pin_toggle(pin_number);

    Which pin that is connected to the different LEDs, you can find in the product specification, or on the backside of your nRF51 DK.

  • Thank you Joakim.

  • Hi Joakim, where did you get these instruction from? If there a manual/documentation for these? A link to that will be great man. Thank you very much!

  • I found some of these Instruction in nrf_gpio.h file sorry. 

1 2