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

notification packet interval

Hi, I got a problem.

I created a timer, interval is 30ms.

#define MIN_CONN_INTERVAL                MSEC_TO_UNITS(150, UNIT_10_MS)           /**< Minimum acceptable connection interval (0.02  seconds). */
#define MAX_CONN_INTERVAL                MSEC_TO_UNITS(400, UNIT_10_MS)           /**< Maximum acceptable connection interval (0.20  second). */


static void notify_timeout_handler(void * p_context){
  uint32_t err_code;
  uint8_t fifo_number;
  int fifo_get_data;	

  flag_30ms_interrupt = true;
	fifo_number = fifo_status(&m_FIFO); 

	if(ble_connect_status && fifo_number != 0 && m_nus.is_notification_enabled == true){
					
				if(can_get_new_fifo_array){
						fifo_get_data = fifo_get(&m_FIFO);
						for(int i=0;i<20;i++)
								nus_data_array[i] = ecg_fifo[m_FIFO.buf[fifo_get_data]]->data_array[i];
						nus_data_array_index = ecg_fifo[m_FIFO.buf[fifo_get_data]]->data_length;
						can_get_new_fifo_array = false;
					  
				}
				
				err_code = ble_nus_string_send(&m_nus, nus_data_array, nus_data_array_index);

				if (err_code == NRF_SUCCESS)
				{
						nus_data_array_index = 0;								//Data has been buffered in softdevice for transmission so we can write data_array with new data.
						can_get_new_fifo_array = true;
					  LEDS_INVERT(BSP_LED_0_MASK);
				}
				else if (err_code == NRF_ERROR_INVALID_STATE ||
						err_code == BLE_ERROR_NO_TX_PACKETS ||
						err_code == NRF_ERROR_BUSY)
				{
						//Do nothing. data_array still contains data for subsequent transmission. 
						//data_array content will be transmitted on another UART RX interrupt, TX_COMPLETE event or BLE services enabled event.
				}
				else
				{
						APP_ERROR_CHECK(err_code);
				}	
	}
}

Using SDK11, 51822, S130V2.

But when I using Lightblue app on iPhone6, sometimes the packet interval only 2~15ms.

13:06:32.053 notified:XXXXXXXXXXX

13:06:32.113 notified:XXXXXXXXXXX

13:06:32.114 notified:XXXXXXXXXXX

13:06:32.143 notified:XXXXXXXXXXX

My android engineers also got the same result on android phone. And they said it's too fast.

Is there any way I can do to avoid it? make it more stable?

  • Ok, it seems I misunderstand min_conn_interval / max_conn_interval.

    If I want notify every 30ms, the max_conn_interval should be less than 30ms.

    I changed to

    #define MIN_CONN_INTERVAL                MSEC_TO_UNITS(80, UNIT_10_MS)           /**< Minimum acceptable connection interval (0.008  seconds). */
    #define MAX_CONN_INTERVAL                MSEC_TO_UNITS(100, UNIT_10_MS)           /**< Maximum acceptable connection interval (0.010  second). */
    

    and problem seems solved.

    Please let me know if I was doing the wrong thing >"<.

  • The notifications will be sent next connection event, so if you try to send two notifications before a connection event has happened then both notifications will be sent during the next connection event.

    Also, why are you using MSEC_TO_UNITS(80, UNIT_10_MS) and not MSEC_TO_UNITS(8, UNIT_1_25_MS)? The connection interval is specified in 1.25ms units, so if you want to set it to 8ms (it will be actually be set to 7.5ms as this is factor of 1.25ms) you have to use MSEC_TO_UNITS(8, UNIT_1_25_MS). Also be aware that the central decides the connection interval and it may not accept the intervals proposed by the peripheral.

  • Hi Ole bauk, thanks for comment, I'll fix it and test again:)

Related