首页 > 解决方案 > nRF52 DK BLE 无法睡眠

问题描述

我正在使用 Nordic nRF52 DK 来制作一个 BLE 应用程序,该应用程序通过具有读取和通知属性的自定义特征来广播数据。

我目前正在为这个项目使用PlatformIOVisual Studio Code

项目设置向导

为了测量功耗,我使用了Power Profiler 套件

功耗始终在2.3mA以上,基于Online Power Profiler For Ble ,这是非常高的。

用于 Ble 的在线电源分析器设置:

{
  "chip": "1",
  "voltage": "3",
  "dcdc": "on",
  "lf_clock": "lfrc",
  "radio_tx": "-40",
  "ble_type": "adv",
  "ble_int": "1000",
  "tx_size": "20"
}

我的目标是让开发板进入休眠状态,直到建立新的蓝牙连接,然后执行 eventQueue 以进行传感器值更新和其他过程。在断开事件之后,板必须再次进入睡眠状态。

首先,我尝试为具有 BLE 功能BLE_BatteryLevel的 mbed 示例项目实现睡眠。

注意:我从示例代码中删除了闪烁事件。

我在 onDisconnectionComplete 回调函数中添加了 _event_queue,break_dispatch(),以强制 ble 从其函数中退出。我不知道这是否是正确的选择,但我想以某种方式退出 ble 的事件队列并让董事会休眠。

断开连接完成

我尝试了以下方法:


int main()
{
    while (true)
    {
        ThisThread::sleep_for('5s');
        {
            DeepSleepLock dp;
            BLE &ble = BLE::Instance();
            ble.onEventsToProcess(schedule_ble_events);
            BatteryDemo demo(ble, event_queue);
            demo.start();
            ThisThread::sleep_for('5s');
        }
    }
}

int main()
{                  
            BLE &ble = BLE::Instance();
            ble.onEventsToProcess(schedule_ble_events);
            BatteryDemo demo(ble, event_queue);
            demo.start();                               
            ble.shutdown();
            sleep();            
}

BLE onDisconection 的 Power Profiler 屏幕截图 功率分析器屏幕截图

int main()
{
    BLE &ble = BLE::Instance();
    ble.onEventsToProcess(schedule_ble_events);
    BatteryDemo demo(ble, event_queue);
    demo.start();
    ble.shutdown();
    hal_sleep();
}
  mbed_file_handle(STDIN_FILENO)->enable_input(false);
  mbed_file_handle(STDIN_FILENO)->enable_output(false);
int main()
{    
    rtos::Kernel::attach_idle_hook(&sleep);               
    BLE &ble = BLE::Instance();
    ble.onEventsToProcess(schedule_ble_events);
    BatteryDemo demo(ble, event_queue);
    demo.start();                               
}

似乎没有什么让板子进入睡眠状态,功耗总是很高。

功率分析器屏幕截图

在此处输入图像描述

在此处输入图像描述

我找不到任何使用 BLE 的功耗和睡眠示例。

标签: bluetoothembeddedbluetooth-lowenergymbedplatformio

解决方案


推荐阅读