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 Reply
  • 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

Children
Related