LoginSignup
2
0

More than 5 years have passed since last update.

Nordic BLE の Disconnect Reason を取得する

Posted at

アオノドンの開発でのトラブルシューティング。

Nordic の nRF52840 を搭載したアオノドン2019。特定のバージョンでconnectしてもすぐdisconnnectするようになった。

以下はデバッグのためにDisconnect Reasonを取得する方法。

テストプログラムは ble_app_uart に手を加えたものであるが、その中の ble_evt_handlar に2行追加して以下のようにした。


static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    uint32_t err_code;
    uint8_t reason;             // 追加
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            NRF_LOG_INFO("Connected");
            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
            err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GAP_EVT_DISCONNECTED:

            reason=p_ble_evt->evt.gap_evt.params.disconnected.reason;  // 追加
            NRF_LOG_INFO("Disconnected");
            // LED indication will be changed when advertising starts.
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
            break;

        case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
        {
            NRF_LOG_DEBUG("PHY update request.");
            ble_gap_phys_t const phys =
            {
                .rx_phys = BLE_GAP_PHY_AUTO,
                .tx_phys = BLE_GAP_PHY_AUTO,

ここで、追加した以下の行でブレークポイントを設置して Breakpoint をつける。


            reason=p_ble_evt->evt.gap_evt.params.disconnected.reason;  // 追加

これで、得られた reason は 0x08 であった。

「Bluetooth status codes」
https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s132.api.v3.0.0%2Fgroup___b_l_e___h_c_i___s_t_a_t_u_s___c_o_d_e_s.html&anchor=ga1bb212e3f0e4f2ef6bd02afa644b92fb

こちらで確認すると 0x08 は BLE_HCI_CONNECTION_TIMEOUT ということらしい。
切断ボタンのショートなどで発生している事象ではないことがわかる。

ということで、トラブルシューティング中・・・

2
0
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
2
0