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

Write request vs. indications

Hello :)

I have a question about the timing of sending a bluetooth write request.
I am using two nrf52 developement kits, one as master and one as slave.
From my master device I send a write request using sd_ble_gattc_write.
On my slave device this triggers a BLE_GATTS_EVT_WRITE.
Then on my master device I get a BLE_GATTC_EVT_WRITE_RSP.
My connection interval is 10ms. This all works fine.

My question is: why does it take longer than one connection event to trigger the BLE_GATTS_EVT_WRITE on my slave device?
I thought it would take less than one connection interval.

I did it the other way around, from Slave to Master using Indications.
Here the time from sending the packet from my slave device until receiving the packet on my master device was less than one connection interval, like I expected.

Why is it different the other way around?
Sorry for my bad English, I hope you can awnser my question.

Parents
  • Hi Kenneth,

    Thank you for your reaction.

    I used the message sequence charts to explain what I mean.

    The first image shows the timings I measured when I was sending an indication with sd_ble_gatts_hvx. 

    The time between sending the packet and receiving it on my central (client) was variable between 0 to 10 ms, just like I expected it would be. And the time between receiving the packet on my central (client) and getting the acknowlegde on my slave (server) took one connection interval (10ms) every time.

    This is what I would expect to happen. And I also thought it would happen if I did it the other way around using a write request. But when I measured the time it took from sending the message from my central (client) to receiving it on my slave (server) it was one connection interval (10ms) every time. 

    Here is my code for calling sd_ble_gattc_write():

    tx_message_t * p_msg;
        
    uint16_t       cccd_val = true ? BLE_GATT_HVX_NOTIFICATION : 0;
        
    p_msg              = &m_tx_buffer[m_tx_insert_index++];
    m_tx_insert_index &= TX_BUFFER_MASK;
    
    uint16_t cccd_handle = p_ble_write_request->conn_handle;
    
    p_msg->req.write_req.gattc_params.handle   = cccd_handle;
    p_msg->req.write_req.gattc_params.len      = WRITE_MESSAGE_LENGTH;
    p_msg->req.write_req.gattc_params.p_value  = p_msg->req.write_req.gattc_value;
    p_msg->req.write_req.gattc_params.offset   = 0;
    p_msg->req.write_req.gattc_params.write_op = BLE_GATT_OP_WRITE_REQ;
    p_msg->req.write_req.gattc_value[0]        = LSB_16(cccd_val);
    p_msg->req.write_req.gattc_value[1]        = MSB_16(cccd_val);
    p_msg->conn_handle                         = p_ble_write_request->conn_handle;
    p_msg->type                                = WRITE_REQ;
        
    if (m_tx_index != m_tx_insert_index)
    {
        sd_ble_gattc_write(m_tx_buffer[m_tx_index].conn_handle,
                                              &m_tx_buffer[m_tx_index].req.write_req.gattc_params);
        m_tx_index++;
        m_tx_index &= TX_BUFFER_MASK;
        
    }

    Should the timings be the same of indication and write request?

    Thank you :)

  • BLE_GATT_OP_WRITE_REQ is by design slow, since it rely BLE_GATTC_EVT_WRITE_RSP from the peer. I recommend to use the BLE_GATT_OP_WRITE_CMD instead if you need faster throughput.

Reply Children
Related