July 09, 2015 | Electronics |
This is a short note on using the nRF51-DK to program an nRF51822 chip on an external board. So far I have (click to jump to section):
- RedBearLab Nano
- nRF51822 modules with the dual 2x9 1.27 mm pins, on an adapter board designed by me in collaboration with Explore Embedded.
I will keep adding to this article as I try other boards.
Before you read further, please take a look at my previous article on nRF51-DK programming using GCC, since we’re going to use the same setup here.
nRF51-DK SWD Interface
One of the major advantages of getting the nRF5-DK1 is that it has a built-in JTAG adapter and hence can be used to program external chips. The standard 10-pin adapter is shown below in red. But there’s also a more convenient way to get the debug output using the P20 pin headers to the right of it. The P20 uses standard pin spacing of 2.54 mm which makes it easy to hook up some wires to a breadboard.
The complete hardware files for the nRF51-DK are available from Nordic, and the schematic has the P20 connections used above. (Look for nRF51-DK-HW in the Downloads section.)
Let’s first look at how to program the RedBearLab Nano, which seems to be a popular BLE board.
To program the RedBearLab Nano, you need to make a couple of changes in the toolchain. The Nano has less memory compared to the chip on the nRF51-DK, so you need to make a corresponding change in ble_app_uart_gcc_nrf51.ld. (The RAM LENGTH below is decreased to 0x2000.)
The second change is really not necessary unless you want to use Nordic’s BSP (Board Support Package) but I am including it in this project since you are likely to encounter it. Save the contents below to a file named custom_board.h in the examples/bsp folder in the SDK.
You can read more about custom_board.h at the nRF51 SDK documentation on this topic.
Here are the pin connections for the Nano:
Hook up the SWD interface as follows (Thanks to Lijun’s write-up on this topic.):
|SH GND DETECT||GND|
If you are powering the Nano externally, connect VDD to the power supply - it has to be less than 3.3 V. Or you can power it from the VDD of nRF51-DK itself.
Here is a photo of how I hooked it up:
To program the board, just go into the rbl_nano/s110/armgcc and build like before. The nRF51-DK will automatically detect the external target and upload the code.
There are some slight changes I made for the Nano compared to my previous project, and I use the same main.c for both projects by using an #ifdef BOARD_CUSTOM:
- The Nano has its built in LED on pin 19, so I used that instead of 22.
- For some reason I could not get ADC input 2 to work, hence I am using ADC input 5 for the Nano. So the LDR resistor divider output need to go into pin P0_4 (RedBearLab calls it A3 which is inconsistent with Nordic’s numbering of the same pin as Analog input 5.)
RebBearLabs has brilliantly placed the LED under the Nano board, so you just need to turn off all the lights in the room to check if it’s blinking. (Or ask your pet ant to check under the board.)
Once you have everything hooked up, the board will appear as “ADC-UART-Nano” on your BLE app and you can get the LDR light values over NUS (Nordic UART Service) as before.
There are several inexpensive (≈USD 5) nRF51822 modules available on sites like aliexpress. But these usually come with a dual 2x9 1.27 mm pitch headers, making it very difficult to work with them. In collaboration with Explore Embedded, I have designed a breakout board with these adapters, and that’s what I will be using for this article. (Note that what I say is valid whether you use this breakout board or not.)
Here is the backside of the board. (We plan to offer these boards for sale soon.)
Now, let’s take a look at the chip that’s on the module. To find out the variant of nRF51822 chip, you can look at the Product Anomaly Notice from Nordic, which has the following:
In my case, the chip says QFAAG0 and 140888. So it has 256 kB flash, 16 kB RAM, and it was made in 2014. What we’re really interested is in flash and RAM, since we need to put that into our build files. So what we find is that in this case, I can use the same configuration as for the RedBearLab Nano.
The SWD connections for the breakout board are as follows:
|SH GND DETECT||GND|
In my breakout board, there’s an LED on P0.21, and accordingly I have the following code:
BOARD_E3BO is defined in the Makefile.
To build the code, go into the nrf51_breakout/s110/armgcc and build as follows. First, build the code:
Then, erase the chip:
Upload the Softdevice as follows:
Finally, upload your code:
You can find files for this project at the github link below. Do your builds in the rbl_nano/s110/armgcc folder or nrf51_breakout/s110/armgcc as appropriate.
- Lijun’s article on using P20 of the nRF51-DK.
Need help with a hardware project or product? Drop us an email at email@example.com. We offer consulting services on AVR and Nordic nRF BLE - hardware design, firmware development, prototyping, PCB design/assembly, sourcing and manufacturing. We can help you bring your product to market!
Bluey nRF52 BLE IoT dev board
We love hearing from our readers. Email us at firstname.lastname@example.org for questions or comments on this article. If you found this article useful, please support us by buying some of our hardware products.