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.
7 years, 7 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:
BLE ECG
#include "mbed.h" #include "ble/BLE.h" #include "GattService.h" #include "ble/GattServer.h" #include "ble/GattCharacteristic.h" #define ECG_SERVICE_UUID 0xC033 #define ECG_CHARACTERISTIC_UUID 0xC034 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; BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE); 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) { pc.printf("Connected\n\r"); } /* Restart Advertising on disconnection*/ void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { pc.printf("Disconnected, starting advertising\n\r"); BLE::Instance().gap().startAdvertising(); } /** * 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); return; } /* Ensure that it is the default instance of BLE */ if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { return; } ble.gap().onDisconnection(disconnectionCallback); ble.gap().onConnection(connectionCallback); /* 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::THERMOMETER_EAR); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(1); /* 10ms */ ble.gap().startAdvertising(); } int main(void) { wait(2); Ticker ticker; BLE &ble = BLE::Instance(); ble.init(bleInitComplete); /* 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 { ble.waitForEvent(); } } }
3 Answers
5 years, 10 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!
Thanks,
Desmond, team Mbed
posted by 11 Feb 20195 years, 10 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/