Hello ,
I am working on a project in which two devices(one is central and other is peripheral ) uses Nordic bluetooth controller for connection and data exchange. nrf51822 for peripheral and nrf51422 for the central. I have random disconnection when I try to send too many messages from the remote(central) to the peripheral.
The short range disconnection happens by pressing the buttons on the remote in a fast random manner at a distance of 20 metres from the peripheral. The issue does not happen, when the same buttons are pressed randomly fast in a close range(5-10 m) or if the buttons are pressed not so fast at long range(> 30m).
The analysis points to the fact that, when packets/messages sent from remote to the wheel is very high, some of the packets are lost and disconnection event is triggered by the soft device.
More analysis on the short range disconnection issue is due to distance between central and peripheral, some packets are getting lost and do not get BLE_EVT_TX_COMPLETE/BLE_GATTS_EVT_HVX_TX_COMPLETE for those messages. Due to which the transmit buffers are not cleared and on sending more messages fills up the transmit buffers very fast. This would lead to NRF_ERROR_NO_TX_PACKETS.
Our code does not use APP_ERROR_CHECK(err_code) . and no soft device resets happen due to that. Below the code to send ble messages.
#define MAX_TIMEOUT_COUNT 0xFFFF
while (ble_nus_c_control_send(&m_ble_nus_c_first_client, data_array, leng) != NRF_SUCCESS)
{
// repeat until sent or until timeout counter reached maximum count
timeout_counter++;
if(timeout_counter > MAX_TIMEOUT_COUNT)
{
break;
}
}
Could you please look at the above code that we use to send ble messages and let us know if this could cause any issues to fill up the TX buffer fast.
Kindly answer the questions below for us to help in debugging.
1, In above scenario, is it possible to tell the BLE layer to clear the transmit buffers irrespective the sent message was successful or not. Which method to use, BLE_GATT_HVX_NOTIFICATION or
BLE_GATT_HVX_INDICATION ?
2, Can you please suggest optimistic connection parameters (too short connection supervision timeout relative to the connection interval) so that only a few packet drops will lead to disconnect. In our case, we will have frequent out of range scenarios and expect to reconnect back quickly. when in range.
#define MIN_CONNECTION_INTERVAL MSEC_TO_UNITS(7.5, UNIT_1_25_MS) /**< Determines minimum connection interval in millisecond. */
#define MAX_CONNECTION_INTERVAL MSEC_TO_UNITS(30, UNIT_1_25_MS) /**< Determines maximum connection interval in millisecond. */
#define SLAVE_LATENCY 0 /**< Determines slave latency in counts of connection events. */
#define SUPERVISION_TIMEOUT MSEC_TO_UNITS(1000, UNIT_10_MS) /**< Determines supervision time-out in units of 10 millisecond. */
3, Please advise if the LF_CLK_SRC values are opptimal.
#define NRF_CLOCK_LFCLKSRC {.source = NRF_CLOCK_LF_SRC_RC, \
.rc_ctiv = 16, \
.rc_temp_ctiv = 2, \
.xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_250_PPM}
Adding the previous queries what was posted in previous mail.
1, Is it possible to increase the transmit/receive FIFO/buffer size or number of TX/RX buffer ?
2, Can we use any function to clear the TX/RX FIFO/buffer ? If yes can you please let us know what function could do this ?
Kind Regards,
Thomas