I wanted to experiment with Bluetooth Low Energy:
- Can you hack together in your garage an antenna and RF section that will work at 2.4GHz?
- If it works, who good/bad will it be?
- What is hand soldering QFN packages like? Many BLE devices are only available in CSP or QFN48.
If you want to make IoT and Wearable devices that can be controlled from your phone/tablet/whatever, ZigBee is a neat mesh networking technology; but it’s not in any phones. Bluetooth (and more recently) Bluetooth Low Energy is in all of them. It’s easy to write a BLE control app write yourself using the Cocoa frameworks or download one like the excellent LightBlue for iPhone:
Make a Board
So, I broke out Eagle and designed a PCB around the Nordic nRF51822 chip, basing the design on a reference from the Nordic data sheet,
I picked the Nordic device because:
- There aren’t many catalogue BLE devices around yet
- It’s Cortex M0. No need to learn ARC (CSR).
- The CPU is integrated into the SoC (unlike the TI device)
The nRF51822 worked great, but it wasn’t all good. More on that later…
My Eagle board design is on GitHub here.
The most challenging part was the 2.4GHz antenna design. The key decisions were:
- Pi network or balun
- Chip antenna or the “real thing”
Since I wanted some RF experience, I picked both of the harder options i.e. pi network and PCB strip antenna.
This whole project was brought to you by app notes…. the best I found on antenna design by far are on the TI website especially:
- AN058. Antenna selection by Richard Wallace. Great app note that steps through all the major categories of antenna choice.
- DN0007. 2.4GHz Inverted F Antenna app note by Audun Andersen. Provides a dimensioned design of the antenna configuration I ended up going with
- DN035. Antenna Selection Quick Guide. Awesome one pager with all the major antenna design choices, pros and cons.
- NWP017 by Nordic Micro. Antenna tuning. Goes through the steps of using a network analyzer, Smith charts and pi-network design/callibration
I went with the inverted F antenna since, although the largest PCB strip antenna, it looked easiest to tune and has the highest efficiency meaning it might be most tolerant of my hack design/build.
To my surprise, I could not find an Eagle-ready 2.4GHz design so I drew up my own using TI’s app note DN0007.
QFN soldering by hand
Need to learn to do this if you want to experiment with the latest RF enabled MCUs. They tend only to be offered in a QFN or CSP (=impossible: you need a reflow or hacked toaster oven).
QFN’s by hand are indeed possible. I found that you need a microscope to do a good job. Many tutorials on the Web on how to do it. The best I found was Dave Jones’ video on EEVBlog on QFP soldering. Same principles here with a couple of differences:
- The pads on the side of the package are almost nonexistent. You need to use a LOT of flux and let the soldier flow from the PCB pad up to the side of the package. Tricky. Using the smallest chisel tip (not cone tip) at 400-500 degrees makes it easier. I find that the small cone tips just don’t have enough thermal capacity to heat pads on a board.
- The famous thermal pad underneath the package (which is also a ground connection). Some people recommend tinning the pad first, placing the device and then using a heat gun. This did NOT work well for me; the mound of solder on thermal pad, though small, is big enough such that the device does not sit flat on the board and is thereby impossible to orient/tack. I chose instead to follow an approach I found in Elektor magazine June 12013 page 43 where you drill a hole (or make a via) so the other side of the board. Once the chip is tacked in place on the main side, flip the board over and drop some solder in from the other side like this:
The Fun bit: Antenna tuning
I was fortunate enough to have access to a network analyzer for Smith charting of S11 parameters.
I designed my board so that, unpopulated, the antenna is isolated and I could solder on a small SMA connector to connect up the analyzer. I also made the antenna strip itself 30% longer than it needed to be so that I could use advanced tuning techniques (aka scraping away the copper track bit by bit with a screw driver):
Worked a treat. Here is the final antenna resonance I went with:
17 Ohms rather than the ideal 50Ohms centre at 2.43GHz, but way good enough for my needs.
It’s Alive! Bring up.
I used the bring up method I described in a previous post with a Segger JLink JTAG box in Single Wire Debug mode.
Really useful since you can peek at on-chip flash memory addresses without needing to get any of the rest of the system working.
Nordic has a handy CPU ID at location 0x1000005C which you can peek like this:
One of the attractions of the Nordic solution is that a full BLE protocol stack is available to registered developers from the Nordic site
To use it, you have to use Nordic’s nRFGo Studio to program the stack by creating a special 80KB region in flash memory. This is NOT then available to the user. Nordic call it their “Soft Peripheral”. Treat it indeed like a peripheral with some predefined function calls like CMSIS:
One of the gotchas of this approach is from that moment on, you can NOT use directly the peripherals of the MCU in the normal way by writing to memory map. You are forced instead to use what feel like OS calls to do even basic stuff like GPIO. This is to ensure that real time constraints of the BLE stack are not interfered with. However it’s a pain in the neck. A two core M0 approach would be MUCH better. One core for BLE, the other 100% open to the user.
This is what I believe Sunrise Micro is doing. Kudos.
Using Nordic Example Code
I wanted to develop the code on Eclipse/Mac OS. However after much tooling around, it became clear that this was not a viable route.
Even though Nordic has an app note on Eclipse use, they do not support it. None of their BLE examples are built for Eclipse. I tried hard to port over example code for beacon and heart rate monitors. This was a real challenge even after Doxygen analysis of all the dependencies. Not a good use of time. So I gave up and went with the example heart rate monitor project built for ARM Keil toolchain (Windows only). This was easy and worked first time.
Mystery touch problem
First power up of the completed system… tuned board with Nordic BLE soft peripheral and example heart rate monitor code. Initially the board’s behavior was very strange. Sometimes LightBlue would detect the BLE peripheral, sometimes nothing.
LightBlue has a really useful function for plotting relative signal strengths of BLE devices it finds; here’s what happened (time=0 to the right):
A finger touch of the board brought everything to life. The problem turned out to be in the 16MHz oscillator reference design. The nRF51822 has on board Colpitts oscillator that needs external caps and crystal. I ignored the recommended 12pF 2% values thinking that 10pF was close enough. Wrong…a finger touch added just enough capacitance to bring the oscillator within spec. The timing tolerances on the oscillator are actually quite tight. This is because there is only a 1 MHz spacing between BLE channels, so by the time you PLL up the 16MHz crystal to 2.43GHz, it doesn’t take much error on the oscillator to overlap channels.
Now to see how far I could send and receive low baud data. I found the best combination of tools to be iPhone LightBlue for basic peripheral detection/ signal strength measurement and the TI SmartRF packet sniffer. The latter is not locked to TI devices and works really well with the nRF51822. Here is an example screen dump of detecting BLE advertising packets and locking on:
The Nordic packet sniffer I found to be terrible. Based on Wireshark, it’s a stack of bits of code that don’t work together in a friendly way like TI’s excellent GUI.
I got as far as 100 feet before signal strength sending advertising packets dipped below 90 dBm. A long way off from the BLE spec of 100 metres, but not bad for a hack…