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

Assert on sending large data over nus

Hello

I'm trying to send an uint16_t array with 750 elements over the NUS service.

To do so I fill the data in multiplle uint_8 arrays of length "m_ble_nus_max_data_len" which is 244 in my case.

Following ist a code snippet I'm using to divide the data and send it:

static uint16_t data_array[] = { 0, 1, 2, 3, ... , 748, 749};

if (m_conn_handle != BLE_CONN_HANDLE_INVALID) {
    int8_t data_part_array[m_ble_nus_max_data_len];
    uint16_t length_da = (uint16_t)( sizeof(data_array) / sizeof(data_array[0]));
    uint8_t length_dpa = (uint8_t)( sizeof(data_part_array) / sizeof(data_part_array[0]));
    uint8_t nr_parts = (uint8_t)(length_da / (length_dpa/2));
    NRF_LOG_INFO("Data too long: dividing into %d parts",nr_parts);
    NRF_LOG_INFO("length_da: %d, length_dpa: %d",length_da, length_dpa);

    // divide in parts
    for(uint8_t part=0;part<nr_parts;part++){
    uint8_t i = 0;
    for(uint16_t n=part*(length_dpa/2); n<(length_dpa/2+(part*length_dpa/2));n++){
      // fill uint16_t in uint8_t
      data_part_array[i] = (uint8_t)(data_array[n] >> 8);
      data_part_array[i+1] = (uint8_t)data_array[n];
      i=i+2;
    }
    
    NRF_LOG_INFO("Part %d: %x %x ... %x %x",part, data_part_array[0] ,data_part_array[1],data_part_array[length_dpa-2] ,data_part_array[length_dpa-1]);
    
    // send data via nus
    do
    {
        err_code = ble_nus_data_send(&m_nus, data_part_array, &length_dpa, m_conn_handle);
        if ((err_code != NRF_ERROR_INVALID_STATE) &&
            (err_code != NRF_ERROR_RESOURCES) &&
            (err_code != NRF_ERROR_NOT_FOUND))
        {
            APP_ERROR_CHECK(err_code);
        }
    } while (err_code == NRF_ERROR_RESOURCES);
}
    

The division in multiple arrays works, but when I'm trying to send the data, it stops after the third array and otputs ERROR 7.

Following the RTT debug data:

<info> app: Debug logging for UART over RTT started.
<info> app: Connected
<info> app: Data len is set to 0xF4(244)
<info> app: Data too long: dividing into 6 parts
<info> app: length_da: 750, length_dpa: 244
<info> app: Part 0: 0 0 ... 0 79
<info> app: Part 1: 0 7A ... 0 F3
<info> app: Part 2: 0 F4 ... 1 6D
<info> app: Part 3: 1 6E ... 1 E7
<error> app: ERROR 7 [NRF_ERROR_INVALID_PARAM] at C:\Users\dariu\switchdrive\FS19\BA_Kraftmessung\05_Software\Mikrocontroller\segger\ble_Kraftmessung2\main.c:272
PC at: 0x0002A121
<error> app: End of error report

The three sent arrays are received complete. Following the data I received via nRF Connect:

09:39:21.061	Connecting to device
09:39:21.214	Connected to device F7:3F:33:92:47:0A
09:39:21.285	ATT MTU changed, new value is 247
09:39:21.649	Attribute value read, handle: 0x03, value (0x): 46-4D-53-20-44-34-35-37-38
09:39:23.306	Attribute value changed, handle: 0x10, value (0x): 01-00
09:39:23.309	Attribute value written, handle: 0x10, value (0x): 01-00
09:39:26.262	Connection parameters updated for device F7:3F:33:92:47:0A: interval 20ms, timeout 4000ms, latency: 0
09:39:31.214	Attribute value changed, handle: 0x0F, value (0x): 00-00-00-01-00-02-00-03-00-04-00-05-00-06-00-07-00-08-00-09-00-0A-00-0B-00-0C-00-0D-00-0E-00-0F-00-10-00-11-00-12-00-13-00-14-00-15-00-16-00-17-00-18-00-19-00-1A-00-1B-00-1C-00-1D-00-1E-00-1F-00-20-00-21-00-22-00-23-00-24-00-25-00-26-00-27-00-28-00-29-00-2A-00-2B-00-2C-00-2D-00-2E-00-2F-00-30-00-31-00-32-00-33-00-34-00-35-00-36-00-37-00-38-00-39-00-3A-00-3B-00-3C-00-3D-00-3E-00-3F-00-40-00-41-00-42-00-43-00-44-00-45-00-46-00-47-00-48-00-49-00-4A-00-4B-00-4C-00-4D-00-4E-00-4F-00-50-00-51-00-52-00-53-00-54-00-55-00-56-00-57-00-58-00-59-00-5A-00-5B-00-5C-00-5D-00-5E-00-5F-00-60-00-61-00-62-00-63-00-64-00-65-00-66-00-67-00-68-00-69-00-6A-00-6B-00-6C-00-6D-00-6E-00-6F-00-70-00-71-00-72-00-73-00-74-00-75-00-76-00-77-00-78-00-79
09:39:31.296	Attribute value changed, handle: 0x0F, value (0x): 00-7A-00-7B-00-7C-00-7D-00-7E-00-7F-00-80-00-81-00-82-00-83-00-84-00-85-00-86-00-87-00-88-00-89-00-8A-00-8B-00-8C-00-8D-00-8E-00-8F-00-90-00-91-00-92-00-93-00-94-00-95-00-96-00-97-00-98-00-99-00-9A-00-9B-00-9C-00-9D-00-9E-00-9F-00-A0-00-A1-00-A2-00-A3-00-A4-00-A5-00-A6-00-A7-00-A8-00-A9-00-AA-00-AB-00-AC-00-AD-00-AE-00-AF-00-B0-00-B1-00-B2-00-B3-00-B4-00-B5-00-B6-00-B7-00-B8-00-B9-00-BA-00-BB-00-BC-00-BD-00-BE-00-BF-00-C0-00-C1-00-C2-00-C3-00-C4-00-C5-00-C6-00-C7-00-C8-00-C9-00-CA-00-CB-00-CC-00-CD-00-CE-00-CF-00-D0-00-D1-00-D2-00-D3-00-D4-00-D5-00-D6-00-D7-00-D8-00-D9-00-DA-00-DB-00-DC-00-DD-00-DE-00-DF-00-E0-00-E1-00-E2-00-E3-00-E4-00-E5-00-E6-00-E7-00-E8-00-E9-00-EA-00-EB-00-EC-00-ED-00-EE-00-EF-00-F0-00-F1-00-F2-00-F3
09:39:31.339	Attribute value changed, handle: 0x0F, value (0x): 00-F4-00-F5-00-F6-00-F7-00-F8-00-F9-00-FA-00-FB-00-FC-00-FD-00-FE-00-FF-01-00-01-01-01-02-01-03-01-04-01-05-01-06-01-07-01-08-01-09-01-0A-01-0B-01-0C-01-0D-01-0E-01-0F-01-10-01-11-01-12-01-13-01-14-01-15-01-16-01-17-01-18-01-19-01-1A-01-1B-01-1C-01-1D-01-1E-01-1F-01-20-01-21-01-22-01-23-01-24-01-25-01-26-01-27-01-28-01-29-01-2A-01-2B-01-2C-01-2D-01-2E-01-2F-01-30-01-31-01-32-01-33-01-34-01-35-01-36-01-37-01-38-01-39-01-3A-01-3B-01-3C-01-3D-01-3E-01-3F-01-40-01-41-01-42-01-43-01-44-01-45-01-46-01-47-01-48-01-49-01-4A-01-4B-01-4C-01-4D-01-4E-01-4F-01-50-01-51-01-52-01-53-01-54-01-55-01-56-01-57-01-58-01-59-01-5A-01-5B-01-5C-01-5D-01-5E-01-5F-01-60-01-61-01-62-01-63-01-64-01-65-01-66-01-67-01-68-01-69-01-6A-01-6B-01-6C-01-6D
09:39:35.371	Disconnected from device F7:3F:33:92:47:0A, reason: BLE_HCI_CONNECTION_TIMEOUT

I tried to send other arrays of the same length, but it crashes after the third. When sending shorter arrays I can send more arrays before it crashes.

I beleive that some kind of buffer si full when sending larger amounts of data. Is there a way to clear this buffer?

What am I doing wrong?

I'm using an nRF52840 DK to send data, a nRF52840 Dongle to receive data, the SDK 15.2 and I'm programming with Segger embeded studio.

Thank you in advance

Related