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

where use sd_ble_gattc_read

Hi, I would like read a long characteristic. I know that I have to use sd_ble_gattc_read and I have to multiple call this function. But I don't know where I have to call this function? After service discovery in this block? In some 'for loop' ?

if (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE &&
        p_evt->params.discovered_db.srv_uuid.uuid == BLE_DEUFOL_SERVICE_UUID &&
        p_evt->params.discovered_db.srv_uuid.type == p_deufol->uuid_type)
    {
counter++;
for(uint16_t x=0;x<25;x++)
											err_code = sd_ble_gattc_read(p_deufol->conn_handle,p_chars[i].characteristic.handle_value , x * 20);


}

You don't have any central example for long read.

When I tried use volatile global variable as counter, but counter is still zero. I increased counter in that block too. Why this variable is not hold in memory ?

Parents
  • Hi,

    dont call functions which trigger events inside event handlers.

    Call sd_ble_gattc_read inside main anytime you have a connection (m_conn_handle != BLE_CONN_HANDLE_INVALID).

    After you get BLE_GATTC_EVT_READ_RSP, call sd_ble_gattc_read(m_conn_handle, handle, 20) again with some offset (e.g. 20).

    Again, wait for the BLE_GATTC_EVT_READ_RSP, and then you can concatenate the first and the second data into one (array) variable.

  • You get an error, because you are looping through sd_ble_gattc_read without a delay.

        while(1)
            {           
                    if(m_deufol.conn_handle != BLE_CONN_HANDLE_INVALID)
                    {
                        if(m_deufol.common_handles.value_handle != 0)
                        {
                            for(uint8_t x=0;x<2;x++) {
                                          sd_ble_gattc_read(m_deufol.conn_handle,m_deufol.common_handles.value_handle , x*20);
                             DELAY 
                            }
                        }
                          DELAY
                }
    

    It should work with proper delays, but thenafter you should rewrite your code without delays in such a way that you wait for events.

Reply
  • You get an error, because you are looping through sd_ble_gattc_read without a delay.

        while(1)
            {           
                    if(m_deufol.conn_handle != BLE_CONN_HANDLE_INVALID)
                    {
                        if(m_deufol.common_handles.value_handle != 0)
                        {
                            for(uint8_t x=0;x<2;x++) {
                                          sd_ble_gattc_read(m_deufol.conn_handle,m_deufol.common_handles.value_handle , x*20);
                             DELAY 
                            }
                        }
                          DELAY
                }
    

    It should work with proper delays, but thenafter you should rewrite your code without delays in such a way that you wait for events.

Children
No Data
Related