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

[Sending big size data over BLE nrf51822]

Dear Nordic,

I am following this test example [https://github.com/NordicSemiconductor/nrf51-ble-app-lbs/tree/throughput-test-5.2.0] while using nrf51822 dev board.

I am unable to flash it to nrf51822 (pca10028 board). considering nRF51 SDK version 5.2.0, S110 SoftDevice version 6.0.0. Its showing error : programming failed, Invalid parameter error!

Please suggest the solution. I really need to understand this example to send big size data.

Thanks.

  • Hi,

    Have a look at this answer. Hopefully it will cover some of the information you are looking for.

    Best regards,

    Øyvind

  • @ Oyvind: Hi~ Thanks for your reply~ I understood it (well explained example)

    well, there is something strange I am facing....like it sending 20 byte data once I press the button, but it continuously sending the same 20 Byte data again and again....with a non stop series. It should be auto stopped once it check for the condition [BLE_EVT_TX_COMPLETE]; but its only stop once I re-press the button. Transmitting On and Off is getting controlled by button. why so? Please clear. I want to send the data only the time when I press the button but not indefinite number of times (non stop)...... Thanks.

  • It is kind of hard trying to debug this without seeing your code, if you could upload it, that would be great.

  • Hi Øyvind,

    I am sharing main code portion, which I used for this application; Please have a look and suggest~ Thanks

    */ Data_Send Function (main.c) ********************************************************************/

        static void data_send(void)
        {
        uint32_t 		err_code;
        uint8_t 		data[20]        = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
    
                
        if (!m_is_sending_data)
        {
            return;
        }
        
        while (1)
        {
            err_code = ble_lbs_data_send(&m_lbs, data);
            if (err_code != NRF_SUCCESS &&
                err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
                err_code != NRF_ERROR_INVALID_STATE &&
                err_code != BLE_ERROR_NO_TX_BUFFERS)
            {
                APP_ERROR_CHECK(err_code);
            }
    
            // If transmission succeeded, increment payload. 
            if (err_code == NRF_SUCCESS)
            {
                data[0] += 1;
                for (uint8_t i = 0; i < BLE_LBS_DATA_CHAR_LEN-1; i++)
                {
                    if (data[i] == 0)
                        ++data[i+1];
                    else 
                        break;
                }
            }
            else
            {
                break;
            }
    
        }
    }
    

    /*************************************************************************************************/

    */ Data_Characteristics (ble_lbs.c) ********************************************************/

    static uint32_t data_char_add(ble_lbs_t * p_lbs, const ble_lbs_init_t * p_lbs_init)
    {
    ble_gatts_char_md_t 			char_md;
    ble_gatts_attr_md_t 			cccd_md;
    ble_gatts_attr_t    			attr_char_value;
    ble_uuid_t          			        ble_uuid;
    ble_gatts_attr_md_t 			attr_md;
    
    
    memset(&cccd_md, 0, sizeof(cccd_md));
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
    cccd_md.vloc = BLE_GATTS_VLOC_STACK;
    
    	
    memset(&char_md, 0, sizeof(char_md));
    char_md.char_props.read   	= 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         	= &cccd_md;
    char_md.p_sccd_md         	= NULL;
    
    	
    ble_uuid.type = p_lbs->uuid_type;
    ble_uuid.uuid = LBS_UUID_DATA_CHAR;
    memset(&attr_md, 0, sizeof(attr_md));
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm);
    attr_md.vloc       = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth    = 0;
    attr_md.wr_auth    = 0;
    attr_md.vlen       = 0;
    
    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     = 20;//sizeof(uint8_t);	
    attr_char_value.init_offs    = 0;
    attr_char_value.max_len      = 20;//sizeof(uint8_t);	
    attr_char_value.p_value      = NULL;
    
    return sd_ble_gatts_characteristic_add(p_lbs->service_handle, &char_md, &attr_char_value,  
                                                                 &p_lbs->data_char_handles);
    																				 
    

    }

    /********************************************************************************************************/

    **/**HVX_Notifications (ble_lbs.c)********************************************************************/

        uint32_t ble_lbs_data_send(ble_lbs_t * p_lbs, uint8_t data[BLE_LBS_DATA_CHAR_LEN])
     {
    
      ble_gatts_hvx_params_t params;
      uint16_t len = BLE_LBS_DATA_CHAR_LEN;
      memset(&params, 0, sizeof(params));
      params.type 	= BLE_GATT_HVX_NOTIFICATION;
      params.handle = p_lbs->data_char_handles.value_handle;
      params.p_data = data;
      params.p_len 	= &len;
       
      return sd_ble_gatts_hvx(p_lbs->conn_handle, &params);
    
     }
    

    /*******************************************************************************************************/

    / Data_packet_notification (ble_lbs.h)********************************************************/

    #define BLE_LBS_DATA_CHAR_LEN 	20
    uint32_t ble_lbs_data_send(ble_lbs_t * p_lbs, uint8_t data[BLE_LBS_DATA_CHAR_LEN]);
    

    /*****************************************************************************************************/

    //

  • You never return from your while(1) loop, meaning that it will stay there until it is interrupted by higher priority activity, such as your button press.

Related