3 years, 5 months ago.

My phone can't connect to my nRF52 DK

I've uploaded sample programs and my own program to the nRF52 DK, but it dosent seem to connect. I've tried basic non BLE programs (blinky) and they work fine, so the problem is somewhere in the connection. I used nRF Connect, Bluetooth terminal, tryed to connect it via options and still nothing. I just can't connect it.

In the past I used nRF51 DK and it worked like a charm!

Im not a great progamer, my c++ is at a basic basic level. I used other code and merged it with my code.

Is it problem in my code or what???

heres my code:


#include "mbed.h"
#include "ble/BLE.h"
#include "GattService.h"
#include "ble/GattServer.h"
#include "ble/GattCharacteristic.h"

#define ECG_SERVICE_UUID            0xC033

Serial pc(USBTX,USBRX);

static const char     DEVICE_NAME[]        = "Portable ECG";
static const uint16_t uuid16_list[]        = {ECG_SERVICE_UUID};

DigitalIn wireOneConnect(p11, PullDown);
DigitalIn wireTwoConnect(p12, PullDown);

AnalogIn signalWire(p3);

uint8_t sensorData = 0;

uint16_t uuid = ECG_SERVICE_UUID;


WriteOnlyGattCharacteristic<uint8_t> ECGcharacteristic(ECG_CHARACTERISTIC_UUID, &sensorData, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NONE);

 * This function is called when a device is connected
void connectionCallback(const Gap::ConnectionCallbackParams_t *params) {

/* Restart Advertising on disconnection*/
void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
    pc.printf("Disconnected, starting advertising\n\r");

 * This function is called when the ble initialization process has failed
void onBleInitError(BLE &ble, ble_error_t error)
    /* Avoid compiler warnings */
    (void) ble;
    (void) error;
    /* Initialization error handling should go here */

 * Callback triggered when the ble initialization process has finished
void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
    BLE&        ble   = params->ble;
    ble_error_t error = params->error;

    if (error != BLE_ERROR_NONE) {
        /* In case of error, forward the error handling to onBleInitError */
        onBleInitError(ble, error);

    /* Ensure that it is the default instance of BLE */
    if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {


    /* setup advertising */
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
    ble.gap().setAdvertisingInterval(1); /* 10ms */

int main(void)
    Ticker ticker;

    BLE &ble = BLE::Instance();
    /* SpinWait for initialization to complete. This is necessary because the
     * BLE object is used in the main loop below. */
    while (ble.hasInitialized()  == false) { /* spin loop */ }

    pc.printf("Initialization done\n\r");

    while (true) {
        if (ble.gap().getState().connected) {
            if ((wireOneConnect == 1) || (wireTwoConnect == 1)){
                //no electrodes connected or error on ECG sensor
            } else {
                //read sensor data and send it to the phone
                sensorData = signalWire.read()*256;
                ble.gattServer().write(ECGcharacteristic.getValueHandle(), &sensorData, 1);
        } else {

3 Answers

3 years, 3 months ago.

I have the same problem

1 year, 8 months ago.

did you solve this problem ?? I have same problem and I need to learn this problem solve

Hi Adil,

I believe those examples [[]https://github.com/ARMmbed/mbed-os-example-ble] are working fine for BLE feature, if you still have some issues with those examples, you can open a new question.

Please feel free to ask me any questions!


Desmond, team Mbed

posted by Desmond Chen 11 Feb 2019
1 year, 8 months ago.

If you have some difficulties with writing a case brief, you are not alone. You should look for reliable websites. Almost all students do so to get good marks and to fulfill their dreams. Here is one of the best one https://topwritingservice.com/buy-a-case-brief/