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?

Parents
  • 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.

Reply
  • 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.

Children
Related