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

BLE disconnects after sending a packet

HI,

i am using nrf51422  with sdk13.3.0 and soft device 130

i am receiving 69 byte of data through UART, i am compressing data in two packets. here after transmitting a packet  BLE is disconnected

i don't want BLE to be disconnected after sending a packet. can you please help me to overcome from this.

regards,

Bindushree

void removeChar(char *s, int c,int c_1,int c_2){

    int j, n = strlen(s);
    for (int i=j=0; i<n; i++)
       if ((s[i] != c)&&(s[i]!=c_1)&&(s[i]!=c_2))
          s[j++] = s[i];

    s[j] = '\0';
}

void my_method(char *s)
{
	uint32_t       err_code;
  char ANALOG_DATA[17];	
  removeChar(s, '.','/',':');
        
  char *start=strtok(s,",");
  char *HGS=strtok(NULL,",");
  char *AT_1=strtok(NULL,",");
  char *RT_1=strtok(NULL,",");
  char *EM=strtok(NULL,",");
  char *OUTPUT=strtok(NULL,",");
  char *INPUT=strtok(NULL,",");
  char *FAULT_DATA=strtok(NULL,",");
  char *MODE=strtok(NULL,",");
  char *DATE=strtok(NULL,",");
  char *TIME=strtok(NULL,",");
  char *AT_2=strtok(NULL,",");
  char *RT_2=strtok(NULL,",");
  sprintf(ANALOG_DATA,"%s%s%s%s%s%s%s","A",HGS,AT_1,RT_1,AT_2,RT_2,"#");
	
 err_code=ble_nus_string_send(&m_nus,(uint8_t*)ANALOG_DATA, 17);
  if (err_code != NRF_ERROR_INVALID_STATE)
    {
       APP_ERROR_CHECK(err_code);
    }


}
void uart_event_handle(app_uart_evt_t * p_event)
{
	    

	   uint16_t j;
     char my_data[72];
	   static uint8_t data_array[72];
    
    switch (p_event->evt_type)
    {
        case APP_UART_DATA_READY:
         UNUSED_VARIABLE(app_uart_get(&data_array[index]));
				 index++;
				for(j=0;j<72;j++)
				{
				my_data[j]=data_array[j];
				}
        if ((data_array[0] == '$') && (data_array[68] == '#'))
            {
							
							my_method((char*)my_data);
              							
              index = 0;
            }
           
            break;

        case APP_UART_COMMUNICATION_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_communication);
            break;

        case APP_UART_FIFO_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_code);
            break;

        default:
            break;
    }
}

Parents
  • Hello,

    Why does the device disconnect?

    Does the connection time out? What are you connected to? Does it give some reason for why it disconnected?

    I assume you use SDK 12.3.0? My initial guess is that ble_nus_string_send returns something other than NRF_SUCCESS.

    Try to define DEBUG in your preprocessor defines, and watch your log (RTT log, not UART). Use J-Link RTT Viewer to monitor the RTT log.

    Best regards,

    Edvin

  • i have not modified any parameters used  in ble_app_uart  example, i only processing the data received through UART

    i sending data from docklight, for the first transmission i am able to receive the packet in mobile app successfully, but if i try to send more than once i am not able to receive the packet and soon after ble will disconnets

    i connected nRF UART app in my mobile

    no it is not giving any reasons for disconnection

    yes i am using SDK 12.3.0

  • Hi Edvin,

    thank you for your suggestion

    i am able to find out the error, i am getting APP_UART_COMMUNICATION_ERROR

    with regards,

    shrushrutha

  • Hi Edvin, i am not able to come out of APP_UART_COMMUNICATION_ERROR, please suggest me solution for this

    thank you,

    with regards,

    shrushrutha

  • Hello shrushrutha,

    I am sorry for the late reply. Most of our support engineers have been away for Christmas holidays.

    I see. The way to avoid the fatal errors on Communication errors is simply to comment out the APP_ERROR_HANDLER(p_event->data.error_communication);

            case APP_UART_COMMUNICATION_ERROR:
                // APP_ERROR_HANDLER(p_event->data.error_communication);
                break;

    But you should be aware that when you get this event, something weird has happened on your UART, and you may have lost a UART Packet.

    Do you use the same baud rate on both devices? Is your buffer filled? Can you check what the value of p_event->data.error_communication has (by debugging)?

    The bits of this is described in the reference manual.

    Please find the nRF51422 reference manual from this site. On page 155, you should see table 279: ERRORSRC which is the UART error register. The value from p_event->data.error_communication is reflected here. Do you get a framing error? This suggests that you are either having a mismatch in baud rates, or that you have some floating pins (the UART is not connected).

    Best regards,

    Edvin

  • hi,

    yes, i am using same baud rate on both sides and i am clearing the buffer using app_uart_flush() 

    after sending around 30 packets  i am getting overrun error. even if i use hardware flow control and reduce the baud rate same error is coming.

    thank you

    with regards

    shrushruta

  • Edvin said:
    Do you use the same baud rate on both devices? Is your buffer filled? Can you check what the value of p_event->data.error_communication has (by debugging)?
Reply Children
Related