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

ble_app_uart_c not receiving data that is longer than the size of a single packet.

I use the example from nrf51422 ble_app_uart_c with SDK_12.3.0 to connect via BLE to nrf52 usbd_ble_uart. When sending data that exceeds the length of one BLE packet (for example, 64 bytes), only the first packet arrives on nrf51. It’s the same way, if you repeat the transmission exceeding the length of one packet. Perhaps, nrf51 rejects or does not confirm the transfer of the next packet with data. If so, how to fix it?

  • Hi Na,

    Could you give some more information on how you send data between the peers ? Note that for notification there will be no bulk transfer so the maximum data can be send is limited to the size of one packet. 

    If you want to send bigger data, you should use read long or write long (queued write) instead. Or increase the data packet length using Data Length Extension. 

  • I send the data from nrf52. In the main function, I check if there is data to transmit in the buffer. And if there is, then I raise the event:

    int main(void){
    
        while (true)
        {
        	if(fifo_ret == NRF_SUCCESS && ble_tx_rdy == true)
    		{
    			ble_tx_rdy = false;
    			
    			ble_nus_evt_t ev;
    			ev.type = BLE_NUS_EVT_TX_RDY;
    			nus_data_handler(&ev);
    		}
        }
    }
    

    In the BLE event handler, I transmit in the data:

    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
    	else if(p_evt->type == BLE_NUS_EVT_TX_RDY) 		//Готовность отправки новых данных по BLE
    	{
    		ret_code_t fifo_ret;
    		
    		uint16_t fifo_index = 0;
    		uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    		
    		do{		//заполнить буффер на отправку
    				
    			fifo_ret = app_fifo_get(&uart_fifo, &data_array[fifo_index]);
    			
    			if (fifo_ret == NRF_SUCCESS)
    			{ 
    			    fifo_index++;
    			}
    				
    		}while(fifo_ret == NRF_SUCCESS && fifo_index < BLE_NUS_MAX_DATA_LEN);
    		
    		if(fifo_index > 0)
    		{
    			ble_nus_data_send(&m_nus, data_array, &fifo_index, m_conn_handle);
    			app_usbd_cdc_acm_write(&m_app_cdc_acm, data_array, fifo_index);			
    		}
    		else if(fifo_index == 0)
    		{
    			ble_tx_rdy = true;
    		}
    		fifo_index = 0;
    	}
    }

    When I connect from the phone, the data is larger than the length of one packet, taken completely. And ble_app_uart_c is only the first packet. From the nrf51422 side, the reception is organized in the BLE event handler:

    static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, const ble_nus_c_evt_t * p_ble_nus_evt)
    {
    	uint32_t len = (uint32_t)p_ble_nus_evt->data_len;
    	
        switch (p_ble_nus_evt->evt_type)
        {
            case BLE_NUS_C_EVT_NUS_RX_EVT:									//отправка в UART
    			
    			app_fifo_write(&ble_fifo, p_ble_nus_evt->p_data, &len);
    		
                break;
        }
    }

    If to transmit from nrf51422 to nrf52, then data of any length is correctly received. How can I arrange the same reception on nrf51422?

  • Solved. At the nRF52, the “BLE_NUS_MAX_DATA_LEN” is longer than that of the nRF51.

Related