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

Error enabling connection event extension in UART example

Hi all,

I use nRF52832 with the UART peripheral example.

I try to enable connection event extension in the device and get an error.

I use SDK V15.0.0 and Softdevice V 6.0.0

I put the following code at the end of the nrf_sdh_ble_default_cfg_set function:

    ble_opt_t  opt;
    memset(&opt, 0x00, sizeof(opt));
    opt.common_opt.conn_evt_ext.enable = 1;
    ret_code = sd_ble_opt_set(BLE_COMMON_OPT_CONN_EVT_EXT, &opt);
    APP_ERROR_CHECK(ret_code);

ret_code returns with 0x3001.

What am I doing wrong?

I'm am new to BLE and my knowledge is limited, specific detailed answers will be greatly appreciated.

Thank you

Parents
  • Moved the code right after ble_stack_init();

    Now the error doesn't appear, but data rate is awful.

    I have connection interval min = 15, max = 30

    Event length = 12

    sending 906 bytes every 220msec and every 4-6 packets I have a few packets missing.

    The data is sent, instead of within the interrupt, in main, using the following function:

    static void SendDataToHost(void)
    {
      static uint16_t length_to_send;
      static uint16_t current_length_to_send;
    
      uint32_t err_code;
    
      if (ring_buffer_out_point < ring_buffer_fill_point)
        length_to_send = ring_buffer_fill_point - ring_buffer_out_point;
      else if (ring_buffer_out_point > ring_buffer_fill_point)
      {
        length_to_send = kEND_OF_TX_RING_BUFFER_LOCATION - ring_buffer_out_point;
        length_to_send += (ring_buffer_fill_point - application_tx_ring_buffer);
      }
    
      do
      {
        if (f_ble_tx_complete)
        {
          if (length_to_send > m_ble_nus_max_data_len)
          {
            current_length_to_send = m_ble_nus_max_data_len;
    
            if ((current_length_to_send + ring_buffer_out_point) > kEND_OF_TX_RING_BUFFER_LOCATION)
              current_length_to_send = kEND_OF_TX_RING_BUFFER_LOCATION - ring_buffer_out_point;
    
            f_ble_tx_complete = 0;
            err_code = ble_nus_data_send(&m_nus, ring_buffer_out_point, &current_length_to_send, m_conn_handle);
    
            if (err_code != NRF_SUCCESS)
              f_ble_tx_complete = 1;
            else
            {
              ring_buffer_out_point += current_length_to_send;
              if (ring_buffer_out_point >= kEND_OF_TX_RING_BUFFER_LOCATION)
                ring_buffer_out_point = application_tx_ring_buffer;
              length_to_send -= current_length_to_send;
              current_length_to_send = 0;
            }
          }
          else if (length_to_send)
          {
            if ((length_to_send + ring_buffer_out_point) > kEND_OF_TX_RING_BUFFER_LOCATION)
              current_length_to_send = kEND_OF_TX_RING_BUFFER_LOCATION - ring_buffer_out_point;
            else
              current_length_to_send = length_to_send;
    
            f_ble_tx_complete = 0;
            err_code = ble_nus_data_send(&m_nus, ring_buffer_out_point, &current_length_to_send, m_conn_handle);
            if (err_code != NRF_SUCCESS)
              f_ble_tx_complete = 1;
            else
            {
              ring_buffer_out_point += current_length_to_send;
              if (ring_buffer_out_point >= kEND_OF_TX_RING_BUFFER_LOCATION)
                ring_buffer_out_point = application_tx_ring_buffer;
              length_to_send -= current_length_to_send;
              current_length_to_send = 0;
            }
          }
        }
      } while(length_to_send);
    
      length_to_send = 0;
      current_length_to_send = 0;
    
      (void)err_code;
    }

    The ring buffer is of 4KB.

    f_ble_tx_complete is set in BLE_GATTS_EVT_HVN_TX_COMPLETE event.

  • Hi, 

    The option API must be called after sd_ble_enable(). This is probably why you got 0x3001 error ( corresponds to BLE_ERROR_NOT_ENABLED) . As for the data rate, are you using a central device that supports Data length extension (nRF52 dev kit or a newer ios/android device)? I did a quick test with the ble_app_uart example and an iphone 7 and got ~9.8 kB/s throughput @ 30 ms , 244 byte data length, NRF_SDH_BLE_GAP_EVENT_LENGTH = 6. 

     

  • As I said, with connection interval of min = 15 max = 15 it works fine, so yes, my ring buffer implementation is good (and used in other projects as well).

    What do I do if ble_nus_data_send returns with something other than NRF_SUCCESS?
    What I currently do is leave the ring buffer indices as they are (as to force re-transmit). What is not clear is if ble_nus_data_send can return with error but manage to send parts of the data, in which case I will get distorted buffers.

    I work in debug mode so I can see if I stop in app_error_fault_handler, so I configured the RAM as was indicated the first time I got an error. still the configurations with higher event length didn't work well.

  • ble_nus_data_send() will only transfer data if it returns NRF_SUCCESS so your buffer handling appears to be correct. But you are less likely to run out of buffer space when you have a shorter CI (15 ms). Please try to increase the hvn queue size to see if it helps:

    in ble_stack_init()

    ...

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
    APP_ERROR_CHECK(err_code);

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

  • Thank you
    What is hvn queue size and is there a limit to its size?

  • Gents,

    I have absolutely the same issue with that SDK and that chip. I have set the MTU to 244 bytes. With the default connection interval (min=20. max=75mS) I get ~700bytes/sec. When I reduce the connection interval to 15mS (min and max), then the throughput increases to 2100bytes/sec.

    What are we missing? 

  • Yes, I tried it with a phone running Android 8 (Honor 9).

    I also tried it with Nordic Central (same chip, using eval board PCA10040)

Reply Children
No Data
Related