hnhoan gravatar image

Posted 2017-12-29 07:25:52 +0100


Writing BLE firmware with a few lines of code

    No tags

Writing a BLE firmware can now be done with a few lines of code. The code example bellow is all you need to write for a non-connectable BLE firmware that advertise a counter value every second in the manufacturer private data. More details with full Eclipse GCC project ready to use on the embedded software blog page.

#include <string.h>

#include "app_util.h"

#include "istddef.h"
#include "ble_app.h"

#define DEVICE_NAME                     "Advertiser"

#define APP_ADV_INTERVAL                MSEC_TO_UNITS(100, UNIT_0_625_MS)

uint32_t g_AdvCnt = 0;

const BLEAPP_CFG s_BleAppCfg = {
    { // Clock config nrf_clock_lf_cfg_t
#ifdef IMM_NRF51822
        NRF_CLOCK_LF_SRC_RC,    // Source RC
        1, 1, 0
        NRF_CLOCK_LF_SRC_XTAL,    // Source 32KHz XTAL
#ifdef NRF51
        0, 0, NRF_CLOCK_LF_ACCURACY_20_PPM
    0,                         // Number of central link
    0,                         // Number of peripheral link
    BLEAPP_MODE_NOCONNECT,  // Connectionless beacon type
    DEVICE_NAME,            // Device name
    ISYST_BLUETOOTH_ID,     // PnP Bluetooth/USB vendor id
    1,                      // PnP Product ID
    0,                        // Pnp prod version
    false,                    // Enable device information service (DIS)
    NULL,                    // Pointer device info descriptor
    (uint8_t*)&g_AdvCnt,       // Manufacture specific data to advertise
    sizeof(g_AdvCnt),          // Length of manufacture specific data
    BLEAPP_SECTYPE_NONE,    // Secure connection type
    BLEAPP_SECEXCHG_NONE,   // Security key exchange
    NULL,                      // Service uuids to advertise
    0,                         // Total number of uuids
    APP_ADV_INTERVAL,       // Advertising interval in msec
    APP_ADV_TIMEOUT_IN_SECONDS,    // Advertising timeout in sec
    100,                        // Slow advertising interval, if > 0, fallback to
                                // slow interval on adv timeout and advertise until connected
    0,        // Min. connection interval
    0,        // Max. connection interval
    -1,        // Led port nuber
    -1,     // Led pin number
    0,         // Tx power
    NULL                        // RTOS Softdevice handler

void BlePeriphEvtUserHandler(ble_evt_t * p_ble_evt)
    if (p_ble_evt->header.evt_id == BLE_GAP_EVT_TIMEOUT)
        // for re-advertisement

        BleAppAdvManDataSet((uint8_t*)&g_AdvCnt, sizeof(g_AdvCnt));

int main()
    BleAppInit((const BLEAPP_CFG *)&s_BleAppCfg, true);


    return 0;


helloNordic gravatar image

Posted Dec. 30, 2017, 4:13 p.m.

good, i am learning. gravatar image

Posted Jan. 5, 2018, 9:59 a.m.

Where do the functions BleAppInit and BleAppRun come from? I searched the nRF SDK version 14.2 for both and did not find any.

Is some 3d party library required to run this code?

hnhoan gravatar image

Posted Jan. 5, 2018, 5:33 p.m.

It is from th EHAL library. It encapsulates the Nordic SDK 14 for nRF52 and SDK12 for nRF51.

Posted Jan. 9, 2018, 11:07 p.m.

Excellent post…I was pleased to have read it. Thanks for sharing. Keep up the great material: link text

Sign in to comment.

User menu

    or sign up

Recent questions

Related posts by tag

No results