Skip to content

nRF52 Programming Tutorials – Part 1 Getting Started

The nRF52 DK is the easiest way to get started with project development using the nRF5 series controller. Every BLE Chipset from Nordic comes with its own development kit – nRF51 DK, nRF52 DK and the nRF52840 DK. The code is compatible and the basic procedure for programming all these controllers is the same. These Development Kits simplify firmware and product development using the nRF ICs and are perfect for both beginners and experienced users. This series of tutorials, help you get started with the nRF52 DK.

Tutorials are aimed at people with basic programming and embedded system’s experience and are new to development with the NRF. At the end of this tutorial, readers will be able to understand the basic concepts that they can use to implement in their projects.

What is Bluetooth Low Energy(BLE)?

            Bluetooth Low Energy is a form of wireless communication designed especially for short-range communication. It is designed for applications that require low power consumption and low data transfers. All mobile phones support BLE and this has made it a hugely popular communication medium.

Applications:

  • BLE Beacon/Device can be used for Indoor Positioning, Navigation and Tracking
  • Blood Pressure Monitors and Heart Rate Sensors
  • Industrial Monitoring Sensors
  • Geography-based, targeted promotions (iBeacon and Eddy stone)
  • Theft Protection
beacon using an nrf IC
Image Source: Developex (BLE Beacons for Tracking)

What is nRF52 DK?

The nRF52 DK is a versatile single board development kit developed by Nordic Semiconductor.

Why nRF52 DK?

Like the Arduino, the nrf52 board is well documented. It shares the same form factor as an Arduino Uno and is great for rapid testing and prototyping. All NRF pins are clearly labeled allowing users to make quick connections without confusion.

The NRF52 DK also has an onboard JLINK programmer and debugger, which makes it a single solution for NRF project development. No other additional third-party programmer either hardware or software is required to program the NRF5 IC.

nrf52 Board
Image source: https://www.tme.eu

NRF5 SDK (Software Development Kit)

Nordic SDK is very extensive and provides everything you need to use their NRF ICs. Nordics SDK includes – APIs for BLE Tasks, APIs for using MCU Peripherals (UART, TWI, GPIO, etc.), Development Tools (compilers, libraries, etc.), Example programs, etc. Nordic SDK has example programs for these applications:

Central is the Master/Device (ex: Smartphone): – The BLE device which initiates an outgoing connection request to a broadcasting peripheral device. This section in the SDK explains how to program the NRF as a central device.

Peripheral is the Slave/Device (ex: nrf52 Board): – The BLE device which accepts an incoming connection request after broadcasting. This section in the SDK explains how to program the NRF as a peripheral device.

The SDK has numerous example programs that users can use to get started. You can directly use them in your application or keep them as a reference.

Soft Device:

            Soft Device is the low-level code required by every Nordic NRF IC for Bluetooth Communication. It includes code for all the low-level BLE Tasks like – BLE scanning, maintaining connections, data transfers, etc. Available in multiple variants, if your project uses BLE then you will have to program the Soft Device to your NRF. 

API (Application Program Interface):

An API is a software intermediary that allows two applications to communicate with each other.

Ex: When you are using a movie booking app, and are asked to enter your credit card information, the app uses an API to send your credit card information to a remote application that verifies if the information is correct or not. Once payment is confirmed, the remote application sends a response back to the app saying, payment is verified and continues to issue the tickets. The API format will look something like this,

sendCardData (cardNum, expDate, CCV, holderName)

This format is just to show how the API takes the details, but in the real-world each and every information a user enters is highly encrypted.

nRF provides APIs for almost every task and this is extensively documented. There are APIs to set pin direction as input/output, ready pin status, scan for Bluetooth devices, transmit Bluetooth data, receive Bluetooth data, etc. Users need not worry about the low-level implementation of these functions rather they can concentrate on getting their project finished

Compiler Selection:

Multiple Compilers are available for nRF Development – SEGGER Embedded Studio, KEIL, GNU. We recommend the Segger Embedded Studio as it can directly program and upload codes to your nRF5 DK, debug programs, if free for download, and is the recommended compiler by Nordic

Image Source: Segger Embedded Studio.

Understanding the nRF SDK Directory Structure

Follow these steps to upload and execute your first program on your nRF52 DK

To get started with nRF Development, download the latest nRF SDK from Nordics website.

The Examples folder in the SDK contains programs grouped together in relevant folders. For example, the BLE Central folder contains multiple example programs that show us how to use the nRF IC as a Central Device. The peripheral folder contains examples for using the IC peripherals- GPIO Pins, PWM, TWI, UART, etc.

Each example program will have these folders –

            hex – folder containing the precompiled hex files. Upload these files to your nRF and the programs will start executing.

          pca100XXX – these folders contain code for the respective development kit. For instance, PCA10040 contains the blinky example code for the PCA10040 development kit from Nordic. You can find this device id printed on the development kit.

Nordic provides each example setup in multiple configurations. Under each example program and the hardware device id folder, you will get sub folders such as – mbr, blank and s132 folders.

If you would like to use the Master Boot Reset with your program, use the MBR folder. IF you would like to use a soft device with your example, use the s1xx, s2xx, s3xx folder. If you do not want the MBR or the Soft Device, use the blank Folder.

After choosing your configuration, Nordic gives you an option for opening the example program in a variety of compilers – Segger Embedded Studio(SES), IAR, GCC, etc.

Select SES, and open the. emProject file to open the example in SES.

Uploading a sample Program

  • Connect the nRF DK to your computer using a mini USB cable.
  • On a successful connection, the board will show up as an external drive on your PC named JLINK.
  • Start by uploading the simplest program – blinky, which blinks the onboard LEDs. To upload the program, open the hex file in the blinky program directory.
  • NRF SDK -> examples -> peripherals -> blinky -> hex -> blinky_pca10040.hexCopy the hex file to the JLINK drive to upload the program to the NRF Microcontroller. The upload will complete in some time and the drive will automatically disconnect from your computer. You can then see the blinky program executing on the NRF DK board – the LEDs blink one by one.

To upload any sample programs to the nRF board the procedure remains the same.

Basically speaking if the above steps are executed the user can check if the Nrf52 board is working or not. Then he/she can move forward with the respective examples or programs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version