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

my bluetooth gets disconnected while sending continous stream of data

hi, i am using uart example from nrf51822 example. when i am sending continuous stream of data then my connection breaks. it disconnects from peripheral device. how should i overcome from this situation. i think i am missing some data exchange concept for sending devices based on connection interval and all different parameters.

can anyone please guide me what should i do to make connection live while sending continuous data over ble uart.

thanks!!

  • Hi, you might be using the NUS example. Can you tell me what SDK you are using?

    Also can you tell me how you "send continuous stream"?

    As you know, when using ble_nus_send_string, the maximum length is 20.

    Are you calling ble_nus_send_string mutiple times like this?

    for(uint16_t k = 0 ; k < 1000 ; k++) {
          err_code = ble_nus_send_string(&m_nus, (uint8_t *) "Hello World", 11);
          APP_ERROR_CHECK(err_code); // a bad way in my opinion
    }
    

    Or are you using BLE_EVT_TX_COMPLETE to taking care of this?

    You will get an BLE_EVT_TX_COMPLETE every time a packet you have queued for transmission.
    

    (ref. link)

    Before I answer your question, I expect you'll get an error when calling ble_nus_send_string.

    So the device resets and disconnects. Can you check the error code?

  • hi, yes you are right i am using like this only in switch loop my data get updated each time. and device resets and disconnects.

    btw here is my code i am using to send data. and i am using 10 sdk NUS example.

    case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&data_array[index]));
                index++;
    						push++;
    						if(index%3 == 0)
    						{
    							count++;
    							err_code = app_timer_cnt_get(&uart_time);
    							APP_ERROR_CHECK(err_code);
    	
    							uart_time = app_timer_ms(uart_time);
    							sent_time = app_timer_ms(sent_time);
    							duration_time = app_timer_ms(duration_time);
    							
    							//diff
    							err_code = app_timer_cnt_diff_compute(uart_time,sent_time,&duration_time);
    							APP_ERROR_CHECK(err_code);
    							
    							SEGGER_RTT_printf(0, "uart:%d\tsent:%d\tduration:%d\n",uart_time,sent_time,duration_time);
    							//SEGGER_RTT_printf(0, "previous time:%d\n",previous_time);
    							//SEGGER_RTT_printf(0, "duration time:\t%d\n",app_timer_ms(duration_time));
    							
    							
    							
    							
    							SEGGER_RTT_printf(0, "current:%d\tsent:%d\n",uart_time,sent_time);
    								
    								if(uart_time<sent_time+waiting_time)
    								{
    										const uint8_t* midiData = parseMIDItoAppleBle(3, data_array);
    										for(int i=0;i<5;i++)
    										{
    												data[i] = midiData[i];
    										}
    										SEGGER_RTT_printf(0, "%x\t%x\t%x\t%x\t%x\tcnt:%d\n",data[0], data[1],data[2],data[3], data[4],count);
    										sendData(data,5);
    										err_code = app_timer_cnt_get(&sent_time);
    										APP_ERROR_CHECK(err_code);
    								}
    								
    						
    							index = 0;
    							//rx_buf_num=0;
    
    							//previous_time = current_time;
    							preCount=count;
    							//count=0;
    						}
    

    thanks!!

  • Oh, you are meaning that you continuously print debugging logs to the terminal program via UART?

    I thought you were sending BLE NUS packets to the central continuously. My mistake.

    Is the app_timer_cnt_diff_compute from SDK 10 or is it your personal function?

    I used SDK 7.2 most of the time, so it will take a while to check.

    Then what function returns an error code to make your device to reset?

    Since I don't know your purpose of your code (and will take quite a time),

    I think checking the error number will solve the problem.

    Place a breakpoint at app_error_handler to check the error number and call stack before calling NVIC reset.

    If you are using IAR EWARM, go to view -> call stack (while debugging), and it will reveal what functions are called.

    By the way, are you using a Eval board or a custom board? Also do you use the scheduler from the SDK?

  • hi, actually i am new to ble development. i am printing only to see the output of my program. i am sending the data using sendData() function in the program

    void sendData(uint8_t data[],int index)
    {
    	uint32_t err_code;
    	err_code = ble_nus_string_send(&m_nus, data, index);
                    if (err_code != NRF_ERROR_INVALID_STATE)
                    {
                        APP_ERROR_CHECK(err_code);
                    }
    }
    

    please explain me how can i send continuous data using this way. or is there any other way to do this.

    and yes app_timer_cnt_diff_compute i am using from SDK 10 only. one more issue i am having regarding timer. after connecting to peripheral device timer always gives 0. can you explain me why it is so. and how can i get time after connecting.

    thanks!!

  • Hmm, alright. I will just check again about your program is doing

    because I don't know exactly your output is. I guess it's creating frequency and a piezo or speaker makes sounds since you wrote midiData.

    You press keyboard button from your computer while you run a terminal program. ->

    UART Interrupt is called. Also, it calculates the elapsed time or whatever it is. ->

    Then midiData is created and you want to see the value via BLE NUS at your phone, is it?

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

    I will post an answer how to send multiple NUS packets soon.

    Before posting, please note me if I understood your code.

    Also, I think the reason of reset is that the timer or UART handling process is too long.

    I wish you can check when your code calls NVIC reset.

Related