Hello,
I'm trying to transfer data from peripheral to Central (based on Central Uart and Peripheral Uart samples) continuously with a delay between each packet of about 450us.
peripheral device static void measure() { for (int i = 0; i < SAMPLES_PER_CYCLE; i++) { double sample = sin(theta); theta += theta_increment; // Scale the sample to fit within the range of 0 to 255 int scaled_sample = (int)(sample * AMPLITUDE) + AMPLITUDE; // Ensure the sample is within the valid range if (scaled_sample < 0) scaled_sample = 0; else if (scaled_sample > 255) scaled_sample = 255; for (uint8_t i = 0 ; i < CHUNK_NUMBER ; i++) { chunks[i].detial.sensor.data = (uint8_t)scaled_sample; if (i == 2) {// check chunk 3 (counting from 0) chunks[i].detial.reserved1.data += 1; } if (bt_nus_send(NULL, &chunks[i].data, sizeof(chunks[i].data))) { // LOG_WRN("Failed to send data over BLE connection"); } // printChunks(i); // k_sleep(K_MSEC(1000)); k_usleep(450); } } // k_sleep(K_MSEC(50)); } static void sensor_simulated_thread_fn(void) { printk("initialize measure thread.\n"); while (true) { measure(); } }
Bluetooth LE parameters are accordingly
Central device
prj.conf CONFIG_BT=y CONFIG_BT_CENTRAL=y CONFIG_BT_SMP=n CONFIG_BT_GATT_CLIENT=y CONFIG_BT_NUS_SECURITY_ENABLED=n CONFIG_BT_USER_PHY_UPDATE=y CONFIG_BT_USER_DATA_LEN_UPDATE=y CONFIG_BT_BUF_ACL_RX_SIZE=50 CONFIG_BT_BUF_ACL_TX_SIZE=50 CONFIG_BT_L2CAP_TX_MTU=40 hci_ipc.conf CONFIG_BT_CTLR_SDC_MAX_CONN_EVENT_LEN_DEFAULT=4000000 CONFIG_BT_CTLR_PHY_2M=y CONFIG_BT_CTLR_DATA_LENGTH_MAX=50 CONFIG_BT_BUF_ACL_RX_SIZE=50 CONFIG_BT_BUF_ACL_TX_SIZE=50 CONFIG_BT_MAX_CONN=2 CONFIG_BT_CTLR_PHY_CODED=y CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y CONFIG_BT_CTLR_RX_BUFFERS=18
peripheral device
prj.conf CONFIG_BT_USER_PHY_UPDATE=y CONFIG_BT_NUS_SECURITY_ENABLED=n CONFIG_BT_PERIPHERAL_PREF_MIN_INT=6 CONFIG_BT_PERIPHERAL_PREF_MAX_INT=6 CONFIG_BT_USER_DATA_LEN_UPDATE=y CONFIG_BT_ATT_PREPARE_COUNT=2 CONFIG_BT_L2CAP_TX_BUF_COUNT=10 CONFIG_BT_BUF_ACL_TX_COUNT=10 CONFIG_BT_CONN_TX_MAX=10 CONFIG_BT_SMP=n CONFIG_BT_BUF_ACL_RX_SIZE=50 CONFIG_BT_BUF_ACL_TX_SIZE=50 CONFIG_BT_L2CAP_TX_MTU=40 hci_ipc.conf CONFIG_BT_CTLR_PHY_2M=y CONFIG_BT_CTLR_SDC_MAX_CONN_EVENT_LEN_DEFAULT=4000000 CONFIG_BT_CTLR_DATA_LENGTH_MAX=50 CONFIG_BT_BUF_ACL_RX_SIZE=50 CONFIG_BT_BUF_ACL_TX_SIZE=50 CONFIG_BT_MAX_CONN=2 CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
By sniffering the communication, I noticed that Central sends frequently empty PDU each 150us, and after around 10 packets, a delay of around 1733us till the Master sends an empty PDU before the slave starts again to transmit data.
What I expected here is that an event packet or empty pdu should never be sent since the peripheral keeps transmitting data each 450us (data size = 35 bytes including all ble headers).
here are the connection, extension length and MTU parameters
What should I do to avoid those empty PDU packets and force peripheral to keep sending packets each 450us?
another question regarding PHY coded mode, when I select Coded mode with S2 coding. I notice a big delay with transmitting the packet over the air (around 1233us) for a packet of 35 bytes and the communication is overloaded with big delay around 6000us before the slave starts to transmit the next packet again.
according to my calculation, it shouldn't be more than 720us right?
ncs: v2.6.0
slave & master (soc) nrf5340
samples: Peripheral UART (slave), Central Uart (master).
thanks in advance!