8 years ago.

2 questions for nrf51422 problems

Dear All,

I am new here and i need your help for my project. hope you acn help me.

I am using nrf DK51 board. and there is nrf 51422 on it. i have some problems about it. here you can see below.

my first question is : my phone and the nrf51422 sometimes can see each other sometimes can not. my second question is : when my phone and the nrf51422 is seeing each other but can not connect.

here you can see the code i used :

  1. include "mbed.h"
  2. include "ble/BLE.h"

DigitalOut led1(LED1); DigitalOut led2(LED2);

static const char DEVICE_NAME[] = "ABCDEFG";

void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { BLE::Instance().gap().startAdvertising(); }

void periodicCallback(void) { led1 = !led1;

}

void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) { BLE& ble = params->ble; ble_error_t error = params->error;

if (error != BLE_ERROR_NONE) {

onBleInitError(ble, error); return; }

if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { return; }

ble.gap().onDisconnection(disconnectionCallback);

ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);

ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(1000); ble.gap().startAdvertising(); }

int main(void) { led1 = 1; led2 = 1; Ticker ticker; ticker.attach(periodicCallback, 1);

BLE &ble = BLE::Instance(); ble.init(bleInitComplete);

while (ble.hasInitialized() == false) { }

while (true) { if (ble.gap().getState().connected) { led2 = 0;

} else { led2=1; } ble.waitForEvent();

} }

Question relating to:

Bluetooth Low Energy (a.k.a Bluetooth LE, BTLE, Bluetooth Smart)
Be the first to answer this question.