This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Getting lots of NRF_ERROR_RESOURCES on notifications

We have an external interrupt every 4ms that collects one 24-bit sample from an analog front end via SPI. After Collecting 6 samples (18 bytes) we send a notification with the data which should then be every 4ms * 6 = 24ms. We're based on the ble_app_template example SDK v13 S132 (nRF52832) with default config settings and MIN_CONN_INTERVAL set to 7.5ms however, We're getting lots of NRF_ERROR_RESOURCES, what could be the problem?

Send function:

SEND_ERROR_CHECK(hrz_ecg_send_channel(&m_ecgs, m_ecgs.ecg_channel_1_handles, hrz_channel1, HRZ_ECGS_MAX_BUFFER_SIZE));

Error check:

#define SEND_ERROR_CHECK(ERR_CODE)                                  \
do                                                              \
{                                                               \
    const uint32_t LOCAL_ERR_CODE = (ERR_CODE);                 \
    if (LOCAL_ERR_CODE == NRF_ERROR_RESOURCES) {                \
      NRF_LOG_ERROR("Buffer full\r\n");                         \
    }                                                           \
    else if ((LOCAL_ERR_CODE != NRF_SUCCESS) &&                 \
          (LOCAL_ERR_CODE != NRF_ERROR_INVALID_STATE) &&        \
          (LOCAL_ERR_CODE != BLE_ERROR_GATTS_SYS_ATTR_MISSING)  \
        )                                                       \
      {                                                         \
          NRF_LOG_ERROR("Error code: %d\r\n", LOCAL_ERR_CODE);  \
          APP_ERROR_HANDLER(LOCAL_ERR_CODE);                    \
      }                                                         \
} while (0)

BLE_GATTS_EVT_HVN_TX_COMPLETE:

case BLE_GATTS_EVT_HVN_TX_COMPLETE:
         NRF_LOG_INFO("Buffer free ");
         NRF_LOG_INFO("Count: %d\r\n",p_ble_evt->evt.gatts_evt.params.hvn_tx_complete.count);
         break;

Maximum packets per connection event:

memset(&ble_cfg, 0, sizeof ble_cfg);
ble_cfg.conn_cfg.conn_cfg_tag                     = CONN_CFG_TAG;
ble_cfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 20;
err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &ble_cfg, ram_start);
APP_ERROR_CHECK(err_code);

Console output: image description

Parents
  • Hi JD, Even if you set the hvn_tx_queue_size to 20 but if the speed when sending is slower than the speed when you queuing then you will have buffer full.

    Your observation of BLE_GATTS_EVT_HVN_TX_COMPLETE count= 1 implied that there was only one packet per connection event. This depends on the central device you connect to, some Android device only support 1 packet per connection event.

    If you match the number of packet you queue with the count number when you receive BLE_GATTS_EVT_HVN_TX_COMPLETE you should be fine. (In my implementation I simply queue continuously until I get NRF_ERROR_RESOURCES then I stop and wait for BLE_GATTS_EVT_HVN_TX_COMPLETE then queue again. )

Reply
  • Hi JD, Even if you set the hvn_tx_queue_size to 20 but if the speed when sending is slower than the speed when you queuing then you will have buffer full.

    Your observation of BLE_GATTS_EVT_HVN_TX_COMPLETE count= 1 implied that there was only one packet per connection event. This depends on the central device you connect to, some Android device only support 1 packet per connection event.

    If you match the number of packet you queue with the count number when you receive BLE_GATTS_EVT_HVN_TX_COMPLETE you should be fine. (In my implementation I simply queue continuously until I get NRF_ERROR_RESOURCES then I stop and wait for BLE_GATTS_EVT_HVN_TX_COMPLETE then queue again. )

Children
Related