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

error when writing more bytes than the "long char" buffer length

Hi all,

I have implemented a service with various "long char" characteristics. The buffer that I use to receive the data wrote to the "long char" characteristics is this:

#define CHAR_LENGTH_MAX 160
#define BUFF_SIZE       CEIL_DIV(CHAR_LENGTH_MAX,18)*24+2 

static uint8_t              m_cb_name_mem[BUFF_SIZE] = {0};
static ble_user_mem_block_t m_cb_name_mem_block =
{
    .p_mem = m_cb_name_mem,
    .len = BUFF_SIZE
};

I set the length of the longest characteristic as the buffer size. All works fine until the value write to the largest characteristic has a length higher than CHAR_LENGTH_MAX, when this happens I obtain the error NRF_ERROR_INVALID_STATE in function sd_ble_gatts_rw_authorize_replywhen the operation BLE_GATTS_OP_PREP_WRITE_REQis executing.

I suppose that this error is obtained because the data overflows the buffer. There's any way to limit or control the bytes wrote in "long characteristics" to not obtain this error and not overflow the buffer?

I'm using: NRF52832QFAAB0 s132 3.1 SDK 12.2

Thanks

  • FormerMember
    0 FormerMember

    Could you share more of your code, like for example where sd_ble_gatts_rw_authorize_reply() is being called?

    Do you see the same problem if you test the example experimental_ble_app_queued_writes() in the SDK?

  • Hi Kristin,

    The code is taked of example of SDK 12.2 "experimental_ble_app_eddystone". Also I've tried with this example, and writing to "Read/Write ADV Slot" char (0x750A) an array of 160 bytes the micro resets (the buffer in this case is 64 bytes lenght). There's any way to avoid this reset?

  • FormerMember
    0 FormerMember

    The reset can be avoided if treating some errors from sd_ble_gatts_rw_authorize_reply() different than others. If an error is caught by APP_ERROR_CHECK(), there will be a reset.