LoginSignup
3
3

More than 5 years have passed since last update.

nRF52840 の sleep を試す (Nordic SDK/Softdevice)

Last updated at Posted at 2019-02-09

ble_app_uart を使ってテスト。

ble_app_uartとは

  • Nordic の サンプルプログラム
  • SDK 中 examples/ble_peripheral/ble_app_uart に収録
  • BLE で UART のように送受信するもの。

元々は、180秒で以下が実行される


static void sleep_mode_enter(void)
{
    uint32_t err_code = bsp_indication_set(BSP_INDICATE_IDLE);
    APP_ERROR_CHECK(err_code);

    // Prepare wakeup buttons.
    err_code = bsp_btn_ble_sleep_mode_prepare();
    APP_ERROR_CHECK(err_code);

    // Go to system-off mode (this function will not return; wakeup will cause a reset).
    err_code = sd_power_system_off();
    APP_ERROR_CHECK(err_code);
}

ちなみに、bsp_btn_ble_sleep_mode_prepare の中身はこんな感じ。bsp_btn_ble.cの中にある。


uint32_t bsp_btn_ble_sleep_mode_prepare(void)
{
    uint32_t err_code;

    err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP);
    RETURN_ON_ERROR_NOT_NOT_SUPPORTED(err_code);

    err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP_BOND_DELETE);
    RETURN_ON_ERROR_NOT_NOT_SUPPORTED(err_code);

    return NRF_SUCCESS;
}

BTN_ID_WAKEUPは、同じく bsp_btn_ble.cの中にある。


#define BTN_ID_WAKEUP             0  /**< ID of button used to wake up the application. */
#define BTN_ID_SLEEP              0  /**< ID of button used to put the application into sleep mode. */
#define BTN_ID_DISCONNECT         0  /**< ID of button used to gracefully terminate a connection on long press. */
#define BTN_ID_WAKEUP_BOND_DELETE 1  /**< ID of button used to wake up the application and delete all bonding information. */
#define BTN_ID_WHITELIST_OFF      1  /**< ID of button used to turn off usage of the whitelist. */

ということでボタンIDは0. PCA10056 (nRF52840 DK)ではButton1~Button4、MDBT50Q DB 上では SW1~SW4として実装されているが、このうちのButton1(SW1)を押すとスリープから復帰する。

System OFF mode

sleep_mode_enter とはなっているが、中身は sd_power_system_off();を実行するようになっていて、
「System OFF mode」に入る。

「System OFF mode」とは、データーシートによると以下のトリガで復帰することができる。

1.The DETECT signal, optionally generated by the GPIO peripheral.
2.The ANADETECT signal, optionally generated by the LPCOMP module.
3.The SENSE signal, optionally generated by the NFC module to wake-on-field.
4.Detecting a valid USB voltage on the VBUS pin (V BUS,DETECT ).
5.A reset.

しかしながら復帰時にはリセットを伴う。

WFI (wait for interrupt)/WFE (wait for event) sleep

sd_app_evt_wait()を使うと、WFIに入り低消費電力になります。
しかしながら

先の
static void sleep_mode_enter(void)


    err_code = bsp_btn_ble_sleep_mode_prepare();


    err_code = sd_app_evt_wait();

に変更しても、CPUは停止しませんでした。別スレッドでソフトウェアループを回していたのですがそれを止める操作を入れないといけない感じです。(調査中)

追記

GPIOによる System OFF mode からの復帰について書きました
https://qiita.com/nanbuwks/items/36c32989543399f3aa62

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3