This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to program nRF52832 in C/C++ from bottom up?

Hi there,

A little background in my experiences first: I've programmed a couple PIC24 microcontrollers in the past for VERY simple embedded system projects (i.e. making some LEDs blink, controlling a keypad, creating a simple ADC, etc.). In all of these projects, I programmed the PIC24 from the bottom up, i.e. doing all of the configuration of the timers, interrupts, input/output ports, communication devices, etc. I'm used to writing ALL of the setup/configuration code in plain C/C++ or assembly, so I'm used to having a complete understanding and control over how it all works.

Now:

I'm working on a new project - I bought the RedBear BLE Nano Kit v2 because of its simple Bluetooth communication ability (necessary to transmit data to an App I'm developing) and all of the open-source material on the internet. The problem is that the project I'm working on requires the same amount of nit-picky control that I got used to in my other projects, but I cannot for the life of me figure out how to do that. I've been trying to use the Arduino IDE to program it, but the very few example programs provided don't seem to really do any of the setup themselves. I've got the datasheet, so if I could figure out how to write a simple C/C++ program to run on the chip, all of my problems would be solved.

To summarize, I just want to be able to program the nRF52832 as I have other microcontrollers; to get complete control over the configuration and pin input/output and information processing. How exactly can I do that?

I've been searching through here for hours now and it doesn't seem like anyone else is asking this, so maybe I'm missing something really simple, or maybe I'm asking the wrong questions, I don't know. Any help would be GREATLY appreciated.

Thank you

  • I can empathize with your desire to completely control everything yourself, but the Nordic processor is way more complex than simple microcontrollers and of course, that requires much more complex software. Fortunately, Nordic provides libraries and API's that abstract most of the complexity for us.

    Much of the complexity is handled in Nordic's 'softdevice' which combines the functionality of a simple OS, I/O drivers and BLE protocol stack.

    The SDK also contains many sample projects covering most of the I/O functionality you might want. I suggest the best way to get started is with one of the simple sample applications. You might also consider getting Nordic's NRF52-DK dev kit, that gives you some LED's and buttons to play with.

  • I think you will find most people in all facets of embedded work do a mix of straight C, C with libraries (mainly drivers) and occasionally a little assembly.

    Generally the mix varies depending on how familiar they are with the hardware and how good they are at coding for embedded. The people coming from Objective C, html, java, etc. generally complain about driver support and why there isn't a driver for every little thing they ever thought of.

    The people who are from hardware, VHDL, FPGA, DSP, and other mixed logic design generally talk a lot about which register does what.

    It's really not worth your time to try to do everything in assembly.  But, I would say that it can be fruitful to learn how the registers work and make the hardware dance that way.  Often you can do in one or two lines of code by writing to registers what may take a few hundred lines using the drivers.

    All the registers are well defined in the product specs.  And there are many examples within the devzone where people have posted enough code for you to figure out how to work with the registers.

    As Richard D. pointed out the the BLE stack is really complex and would be a big, big feat to try to replicate. Just use the SoftDevice.  If you are just making beacons you could probably code them directly in C without much effort.  But it would only be for your education, since it would not satisfy bluetooth SIG standards.

    Also, I have occasionally seen people on the devzone refer to ble stacks on github for other processors.  If you really want to dig into it, that could be a way.

    Have fun!

  • The following links are what you are looking for : 

    Blog : Bluetooth LE with Nordic nRF51 & nRF52 series The easy way!

    Library : IOsonata Object oriented programming for MCU (nRF51, nRF52, nRF53, nRF91, LCP11xx, LPC17xx, STM32,...)

Related