Setting GPIO pin as output pin

Nikhil497 gravatar image

asked 2017-08-13 17:29:45 +0200

updated 2017-08-13 17:35:28 +0200

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?

edit retag flag offensive close delete report spam

2 answers

Sort by » oldest newest most voted
Joakim-Jakobsen gravatar image

answered 2017-08-14 11:31:01 +0200

updated 2017-08-14 11:32:44 +0200

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.

edit flag offensive delete publish link more


Thank you Joakim.

Nikhil ( 2017-08-14 14:03:06 +0200 )editconvert to answer
endnode gravatar image

answered 2017-08-13 22:19:22 +0200

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;)

edit flag offensive delete publish link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

User menu

    or sign up

Question Tools

1 follower


Asked: 2017-08-13 17:29:45 +0200

Seen: 145 times

Last updated: aug. 14