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

In the long range mode streaming data between the ble_app_uart_c_central and ble_app_uart_peripheral

Hi,

I am using the two units talking with each other for the BLE uart. 

One is running with the example ble_app_uart_c_central. The other is running with the ble_app_uart_peripheral. Both example based on the SDK version nRF5_SDK_17.0.2_d674dde.

It was working fine, when I am using them in the orginal mode for the sensor data streaming.

But, when I did some changes to it, to make both of them into the long range mode with 8dbm and coded mode. The connection is fine, but when I sending more data will make the peripheral fails. When I debugging on it, I find was the data I send is too long or too much. 

Here is some code and error added 

In the peripheral side, when it call the intrruption function "void in_pin_handler(void)" been called for each 20 seconds, in each call it sending the bluetooth package to the centeral unit by the function "void niklas_ble_send_array_handler(void)". when the package is big, for example size is 70 as below the parameter set, then comes out memory issues. 

ble_tx_buffer_acc_len=70;
ble_tx_buffer_ang_len=70;

code as below

void niklas_ble_send_array_handler(void)
{
  uint32_t       err_code;
  #ifdef DEBUG_BLE_SEND_DEBUG
  printf("G1 \r\n");nrf_delay_ms(1);
  #endif
  if(ble_tx_buffer_acc_len<BLE_NUS_MAX_DATA_LEN)
  {
     do
     {
     
         err_code = ble_nus_data_send(&m_nus, ble_tx_buffer_acc, &ble_tx_buffer_acc_len, m_conn_handle);
         if ((err_code != NRF_ERROR_INVALID_STATE) &&
             (err_code != NRF_ERROR_RESOURCES) &&
             (err_code != NRF_ERROR_NOT_FOUND))
         {
             APP_ERROR_CHECK(err_code);
         }
     } while (err_code == NRF_ERROR_RESOURCES);	  
  }

  #ifdef DEBUG_BLE_SEND_DEBUG
  printf("G2 \r\n");nrf_delay_ms(1);
  #endif
  if(ble_tx_buffer_acc_len<BLE_NUS_MAX_DATA_LEN)
  {  
     do
     {
         
         err_code = ble_nus_data_send(&m_nus, ble_tx_buffer_ang, &ble_tx_buffer_ang_len, m_conn_handle);
         if ((err_code != NRF_ERROR_INVALID_STATE) &&
             (err_code != NRF_ERROR_RESOURCES) &&
             (err_code != NRF_ERROR_NOT_FOUND))
         {
             APP_ERROR_CHECK(err_code);
         }
     } while (err_code == NRF_ERROR_RESOURCES);
  }
  #ifdef DEBUG_BLE_SEND_DEBUG 
  printf("G3 \r\n");nrf_delay_ms(1);
  #endif
}

void in_pin_handler(void)
{
    //nrf_drv_gpiote_out_toggle(PIN_OUT);
    printf("INTC\n");nrf_delay_ms(1);
    uint8_t k=0;
    uint32_t err_code;  
    uint8_t channel;
    k=read_out_FIFO_float();
	
    bsp_board_led_invert(BSP_BOARD_LED_2);
	
    #ifdef DEBUG_FIFO_SIZE_INSIDE
	 printf("P3:%d\n", k);nrf_delay_ms(1);
	 printf("s_connected=%d\n",status_connected);nrf_delay_ms(1);
    #endif
	
    #ifdef DEBUG_BLE_SEND_DEBUG
  	 printf("ble_tx_buffer_acc_len=%d\n",ble_tx_buffer_acc_len);nrf_delay_ms(1);
  	 printf("ble_tx_buffer_ang_len=%d\n",ble_tx_buffer_ang_len);nrf_delay_ms(1);
  	 printf("BLE_NUS_MAX_DATA_LEN=%d\n",BLE_NUS_MAX_DATA_LEN);nrf_delay_ms(1);
    #endif
	
	//if((status_connected==1)&&(status==9)){niklas_ble_send_handler();}
	if((status_connected==1)&&(status==9))
        {
          
          #ifdef LONG_RANGE_HIGH_SPEED_BLE_STREAMING_SLOW
            ble_tx_buffer_acc_len=70;
            ble_tx_buffer_ang_len=70;
          #endif
          niklas_ble_send_array_handler();


          
          
          //reference https://www.jianshu.com/p/c81c576bbdf5
          /*
		  err_code =sd_ble_gap_rssi_get(m_conn_handle,&rssi_value,&channel);
          printf("RSSI=%d\n",rssi_value);nrf_delay_ms(1);
          APP_ERROR_CHECK(err_code);
		  */

        
        }

}

Parents Reply Children
Related