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

Slow transfer rate, nrf51822 to Android

Hi,

I've finally managed to create a functional app for nrf51822 dongle which sends and receives data via BT and UART.

But, I have low transfer speed over Bluetooth. I've read several posts here but non worked in increasing the transfer rates.

Code is below, it's very similar to examples, especialy "nus" example.

On Android I have a queue as everybody else, and I can get max 2kbps. I measure sending of 1000 packets of 20 bytes to nRf and sending it back from nRf to Android, and it takes around 20 seconds. 1000 * 20 bytes / 20 seconds = 1000 bytes per second.

Regarding this link: devzone.nordicsemi.com/.../ The transfer rate could be better, correct? How to achieve that?

This is how I set connection intervals:

#define MIN_CONN_INTERVAL               MSEC_TO_UNITS(7.5, UNIT_1_25_MS)
#define MAX_CONN_INTERVAL               MSEC_TO_UNITS(8, UNIT_1_25_MS) 

This is how I set characteristic which recieves and sends data on nrf:

static uint32_t data_char_add(ble_alps_t* p_alps, const ble_alps_init_t* p_alps_init)
{
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_t    attr_char_value;
    ble_uuid_t          ble_uuid;
    ble_gatts_attr_md_t attr_md;
    
    memset(&char_md, 0, sizeof(char_md));
    
    char_md.char_props.write = 0;
		char_md.char_props.write_wo_resp = 1;
		char_md.char_props.notify = 1;
    char_md.p_char_user_desc  = NULL;
    char_md.p_char_pf         = NULL;
    char_md.p_user_desc_md    = NULL;
    char_md.p_cccd_md         = NULL;
    char_md.p_sccd_md         = NULL;
    
    ble_uuid.type = p_alps->uuid_type;
    ble_uuid.uuid = ALPS_UUID_DATA_CHARACTERISTIC;
    
    memset(&attr_md, 0, sizeof(attr_md));

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    
    attr_md.vloc       = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth    = 0;
    attr_md.wr_auth    = 0;
    attr_md.vlen       = 1;
    
    memset(&attr_char_value, 0, sizeof(attr_char_value));

    attr_char_value.p_uuid       = &ble_uuid;
    attr_char_value.p_attr_md    = &attr_md;
    attr_char_value.init_len     = DATA_CHAR_MIN_PACKET_SIZE;
    attr_char_value.init_offs    = 0;
    attr_char_value.max_len      = DATA_CHAR_MAX_PACKET_SIZE;
    attr_char_value.p_value      = NULL;
    
    return sd_ble_gatts_characteristic_add(p_alps->service_handle, &char_md,
                                               &attr_char_value,
                                               &p_alps->data_char_handles);
}

And this is how I send data:

uint32_t ble_nus_send_string(ble_nus_t * p_nus, uint8_t * string, uint16_t length)
{
    ble_gatts_hvx_params_t hvx_params;

    if (p_nus == NULL)
    {
        return NRF_ERROR_NULL;
    }
    
    if ((p_nus->conn_handle == BLE_CONN_HANDLE_INVALID) || (!p_nus->is_notification_enabled))
    {
        return NRF_ERROR_INVALID_STATE;
    }
    
    if (length > BLE_NUS_MAX_DATA_LEN)
    {
        return NRF_ERROR_INVALID_PARAM;
    }
    
    memset(&hvx_params, 0, sizeof(hvx_params));

    hvx_params.handle = p_nus->rx_handles.value_handle;
    hvx_params.p_data = string;
    hvx_params.p_len  = &length;
    hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
    
    return sd_ble_gatts_hvx(p_nus->conn_handle, &hvx_params);
}
Parents Reply Children
No Data
Related