Hi all,
I am using PCA10040 with nRF5_SDK_14.2.0 and using the ble_app_uart example.
Basically I have a large array of size 18750 to send out and having read on the forum, I understand that I need to split up the data into smaller chunks and call ble_nus_string_send multiple times. Most people manage to get it to work by splitting into chuck of 20 bytes.
What I have tried so far is that I can provide a 150 byte array into the ble_nus_string_send function without any problem and its receiving well on a mobile phone. I also made a few changes:
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(7.5, UNIT_1_25_MS) /**< Minimum acceptable connection interval (20 ms), Connection interval uses 1.25 ms units. */
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(7.5, UNIT_1_25_MS) /**< Maximum acceptable connection interval (75 ms), Connection interval uses 1.25 ms units. */
Inside the gatt_init function, I also increase the max MUT size to 247:
err_code = nrf_ble_gatt_att_mtu_periph_set(&m_gatt, 247);
This is what I did in the main function:
// Enter main loop.
for (;;)
{
UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
power_manage();
if(start_transfer)
{
start_transfer = false;
uint16_t length = 150;
uint8_t j = 0;
uint16_t k = 0;
for(j=0; j<125; j++)
{
do
{
err_code = ble_nus_string_send(&m_nus, mybuffer+k, &length);
if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) )
{
APP_ERROR_CHECK(err_code);
}
} while (err_code == NRF_ERROR_BUSY);
k = k + 150;
while(!tx_complete);
tx_complete = false;
}
}
}
Each call to ble_nus_string_send, I am sending out 150 bytes, and I go this in a for loop that iterates for 125 times, so essentially I will transfer all 18750 bytes. After each call to ble_nus_string send, I am checking a flag tx_complete , which is set to true when a BLE_GATTS_EVT_HVN_TX_COMPLETE event happens.
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
tx_complete = true;
break;
This is working well except that the transfer seems to be still fairly slow about 19-20 seconds to send everything over. Is there anything I am doing wrong? How can I make this go much more faster?