Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
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 :
- include "mbed.h"
- 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();
} }