nRF52840 Nordic Semiconductor (Part 001) - GPIO Outputs

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.

Yes the code is linear, its done this way to break down the port assignments to make it easier to see what is going on.

The GPIO's are in two banks of 32 bits (as they are basically registers ported out to the pins. Seamingly random distribution though.

// GPIO Outputs

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

#define led1  13
#define led2  15
#define led3  17
#define led4  20
#define led5  22
#define led6  24
#define led7  31  // This is GPIO "0.31" ... i.e. First register bank
#define led8  32  // This is GPIO "1.00"... i.e. Second  register bank
//#define led9 41 // LED2 Green ( of the onboard RGB LED !!!, puzzeled by this @momo)
#define led9   42  // This is GPIO "1.10" ... 32+10 = 42
#define led10 47 //               GPIO "1.15" ... 32+15 = 47

/**
 * @brief Function for application main entry.
 */
int main(void)
{
nrf_gpio_cfg_output(led1);   // Assign the GPIO pin as OUTPUT
nrf_gpio_cfg_output(led2);
nrf_gpio_cfg_output(led3);
nrf_gpio_cfg_output(led4);
nrf_gpio_cfg_output(led5);
nrf_gpio_cfg_output(led6);
nrf_gpio_cfg_output(led7);
nrf_gpio_cfg_output(led8);
nrf_gpio_cfg_output(led9);
nrf_gpio_cfg_output(led10);
  while(1)
  {
  nrf_gpio_pin_set(led1);nrf_gpio_pin_clear(led10);  // Set and Clear for Logic 1 or 0
  nrf_delay_ms(100);
  nrf_gpio_pin_set(led2);nrf_gpio_pin_clear(led1);
  nrf_delay_ms(100);
  nrf_gpio_pin_set(led3);nrf_gpio_pin_clear(led2);
  nrf_delay_ms(100);
  nrf_gpio_pin_set(led4);nrf_gpio_pin_clear(led3);
  nrf_delay_ms(100);
  nrf_gpio_pin_set(led5);nrf_gpio_pin_clear(led4);
  nrf_delay_ms(100);
  nrf_gpio_pin_set(led6);nrf_gpio_pin_clear(led5);
  nrf_delay_ms(100);
  nrf_gpio_pin_set(led7);nrf_gpio_pin_clear(led6);
  nrf_delay_ms(100);
  nrf_gpio_pin_set(led8);nrf_gpio_pin_clear(led7);
  nrf_delay_ms(100);
  nrf_gpio_pin_set(led9);nrf_gpio_pin_clear(led8);
  nrf_delay_ms(100);
  nrf_gpio_pin_set(led10);nrf_gpio_pin_clear(led9);
  nrf_delay_ms(100);
  }
}