We are developing a BLE device that will act as a central and send data to a peripheral. To begin with, I have used the uart central example code from SDK to set up a central device on PCA10040 and using the uart peripheral code from SDK on our custom board that has BL652. I am using NRF52832 with SDK 15.3.0, softdevice S132.
In the central code, I commented out the uart_init() so that there are no UART events.
I created a timer and am sending a 8-byte packet to the periperal:
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
static uint32_t i;
uint8_t dummyData[8] = { 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59 };
nrf_gpio_pin_toggle(24);
send_ble_data(dummyData, sizeof(dummyData));
}
void send_ble_data(uint8_t * p_data, uint16_t length)
{
static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
memcpy(data_array, p_data, length);
ble_nus_c_string_send(&m_ble_nus_c, data_array, length);
}
On the peripheral side, I am using the nus_data_handler() service to receive the data and modified the function from the uart peripheral example thus:
static void nus_data_handler(ble_nus_evt_t * p_evt)
{
if (p_evt->type == BLE_NUS_EVT_RX_DATA)
{
uint32_t err_code;
NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
if (p_evt->params.rx_data.p_data[0] == 0x52)
{
nrf_gpio_pin_toggle(24);
}
nrf_drv_spis_buffers_set(&spis_handle, //The SPI part is specific to our application
(uint8_t*)p_evt->params.rx_data.p_data,
p_evt->params.rx_data.length,
m_rx_buf,
m_length);
}
}
All configurations in sdk_config.h are default from the SDK examples for central and peripheral.
When I set the timer in central to 100 ms, if I watch GPIO24 on oscilloscope simultaneously on central and peripheral boards, I can see that there is a delay of ~30 ms between send from central and receive on peripheral. When I reduce the timer interval further to say 10 ms, I can see that the central pin toggles consistently at 10 ms while the peripheral pin toggles erratically, most of the times at 30 ms, indicating data is getting 'missed'.
I read about connection interval and according to Infocenter, "The connection interval defines how often the devices must listen on the radio.". This is set to min 7.5 and max 30 default from the example.
Our product needs the central device to transfer 8 byte data reliably to peripheral at 1 ms interval. How can we achieve this? Does the connection interval parameter set a limit on the max transfer rate?