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

send data more than 20 byte via ble_nus_string_send() nRF51 SDK 9

I want to send some data more than 20 bytes. I use ble_nus_string_send(&m_nus, tx_stuffed, 10); 3 times.

In the advertizer.c in the function on_ble_evt I insert code

case BLE_EVT_TX_COMPLETE: 
        b_ble_tx_complette = true;
        break;

But after first use

ble_nus_string_send(&m_nus, tx_stuffed, 10);

I don't receive my flag b_ble_tx_complette equal true; I can send 3 times

ble_nus_string_send(&m_nus, tx_stuffed, 20);
ble_nus_string_send(&m_nus, tx_stuffed + 20, 20);
ble_nus_string_send(&m_nus, tx_stuffed + 40, 20);

with success but without flag b_ble_tx_complette set. Why?

  • advertiser.c may not have much to do when the device is in connection. I would suggest to put your check for BLE_EVT_TX_COMPLETE event inside on_ble_evt() inside main.c if it's already implemented. If not you can create one, make sure you put it inside ble_evt_dispatch(). When calling ble_nus_string_send() you should check for return code, before you call it again. You can queue several hvx command since we have a buffer of 7 command for notification and write command. What do you receive on the peer device, do you see the notifications arrive ?

  • Thanks for answer. I can insert case BLE_EVT_TX_COMPLETE into ble_evt_dispatch. But I think that same. Ok, how I should in the code check return flag? Which construction? While...?

    Now when I transfer 3 times string

    ble_nus_string_send(&m_nus, tx_stuffed, 10);
    

    as result after that I see status BLE_EVT_TX_COMPLETE.

    Is it possible that just I not correct check this flag after sending?

  • I think, I decided this case. I don't should use a

    while (flag == 0);
    

    when I wait this flag.

    I should wait this flag in the event and call from this event next sending.

  • I don't think you should wait for any flag, simply start sending if you have data, or if you already have data need to send, send it when you receive BLE_EVT_TX_COMPLETE event.

    You get the return code for each command by doing like this

    err_code = ble_nus_string_send(&m_nus, tx_stuffed, 10);
    

    Then check the err_code after the call.

Related