Hello there,
I'm sending IMU data (16bytes) using a notification from a custom board to a phone. My final goal is to send this packet of data (16 bytes) every 10 milliseconds. My first step was to generate a program that sends a new packet (16 bytes) as soon as the previous one has been sent (waiting for BLE_EVT_TX_COMPLETE)
this is my main.c:
while(!papaya)getConnected(&papaya); //wait for phone to connect waitMS(5000); ble_hrs_heart_rate_measurement_send(&m_hrs, data); // Enter main loop. for (;;) { while(true){ collectAvocados(data); //collects data from MPU9250 while(!avocado)getSent(&avocado); //wait for previous packet to be sent ble_hrs_heart_rate_measurement_send(&m_hrs, data); avocado = 0; } }
this is my ble_thingy.c:
void getSent(int *avocado){ if(flag1 == 1){ *avocado = 1; flag1 = 0; } } void getConnected(int *papaya){ if(flag2 == 1){ *papaya = 1; } } void ble_hrs_on_ble_evt(ble_hrs_t * p_hrs, ble_evt_t * p_ble_evt) { switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: on_connect(p_hrs, p_ble_evt); flag2 = 1; break; case BLE_GAP_EVT_DISCONNECTED: on_disconnect(p_hrs, p_ble_evt); break; case BLE_GATTS_EVT_WRITE: on_write(p_hrs, p_ble_evt); break; case BLE_EVT_TX_COMPLETE : flag1 = 1; nrf_gpio_pin_set(14);nrf_gpio_pin_clear(14); break; default: // No implementation needed. break; } }
If I touch the connection intervals in order to increase the frequency in which the TX buffer is emptied:
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(10, UNIT_1_25_MS) /**< Minimum acceptable connection interval (0.4 seconds). */ #define MAX_CONN_INTERVAL MSEC_TO_UNITS(10, UNIT_1_25_MS) /**< Maximum acceptable connection interval (0.65 second). */ #define SLAVE_LATENCY 0 /**< Slave latency. */ #define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) /**< Connection supervisory timeout (4 seconds). */
I can see that the frequency in which BLE_EVT_TX_COMPLETE activates is irregular (I use a gpio pin to output this: it changes from time to time) and doesn't happen every 10 ms. Next image is taken by a digital Logic 8 analyser:
(Time between frames: 0.135s, 0.18s, 0.0897s, etc.)
How can I increase the frequency of my notification using a correct method that allows me to send 1 packet every 10ms?