nRF52840 Nordic Semiconductor (Part 002) - GPIO Inputs

Based off the Bog standard "Blinky "Example contained in the NRF SDK :- C:\nRF5_SDK_17.0.2_d674dde\examples\peripheral\blinky\pca10059\mbr\ses\blinky_pca10059_mbr.emProject

Load in the project using Segger Studio ,

Select the main.c file , delete its contents and paste the contents below.

Build and send the .hex file to the nRF52840.

/// GPIO inputs

#include <stdbool.h>
#include <stdint.h>
#include "boards.h"
#include "nrf_gpio.h"

#define led1 13
#define led2 15
#define led3 17
#define led4 20
#define Button1 22
#define Button2 24
#define Button3 31
#define Button4 42

int main(void)

nrf_gpio_cfg_input(Button1, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_input(Button2, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_input(Button3, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_input(Button4, NRF_GPIO_PIN_PULLUP);


 while (true)
if(nrf_gpio_pin_read(Button1) == 0) {nrf_gpio_pin_set(led1);}
 else {nrf_gpio_pin_clear(led1);}
if(nrf_gpio_pin_read(Button2) == 0) {nrf_gpio_pin_set(led2);}
 else {nrf_gpio_pin_clear(led2);}
if(nrf_gpio_pin_read(Button3) == 0) {nrf_gpio_pin_set(led3);}
 else {nrf_gpio_pin_clear(led3);}
if(nrf_gpio_pin_read(Button4) == 0) {nrf_gpio_pin_set(led4);}
 else {nrf_gpio_pin_clear(led4);}



Should you wish to use the onboard buttons they are active low, which means that the input will be connected to ground when the button is activated.

The SW1 button has no external pull-up resistor, but the reset button (SW2) has a 10 k pull-up resistor.

To use SW1, P1.06 must be configured as an input with an internal pull-up resistor.

The LEDs are active low, which means that writing a logical zero '0' to the output pin will illuminate the LED.

Part Description GPIO
SW1 Button P1.06
SW2 Reset P0.18
LD1 Green P0.06
LD2 Red P0.08
LD2 Green P1.09
LD2 Blue P0.12