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

nrf52832: sending BLE values

Hi all, I'm developing nRF52832.

My goal is to send ADC data to central device using BLE.

Below is part of my code.

#define SAMPLES_IN_BUFFER 123
#define NO_OF_SAADC_BUFFER 2
static uint8_t adc_ble_notify_size = SAMPLES_IN_BUFFER * sizeof(uint16_t);

void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
	if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
	{
		ret_code_t err_code;
		buffer_number ^= 0x02; //XOR
		saadc_event_callback = true;
		err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
		APP_ERROR_CHECK(err_code);
		}
}

uint32_t ble_fs_send_adc_data(uint16_t conn_handle, ble_fs_t * p_fs, uint8_t *  p_data, uint16_t length)
{
    ble_gatts_hvx_params_t params;
    uint16_t len = length;
    //p_fs->bytes_sent += len;
    memset(&params, 0, sizeof(params));
    params.type   = BLE_GATT_HVX_NOTIFICATION;
    params.handle = p_fs->adc_char_handles.value_handle;
    params.p_data = p_data;
    params.p_len  = &len;
    return sd_ble_gatts_hvx(conn_handle, &params);
}

Below is part of main function.
for (;;)
	{
		if (saadc_event_callback) {
			ble_fs_send_adc_data(m_conn_handle, &m_ble_fs, &(adc_buffer.m_buffer_ble[buffer_number * adc_ble_notify_size]), adc_ble_notify_size);
			ble_fs_send_adc_data(m_conn_handle, &m_ble_fs, &(adc_buffer.m_buffer_ble[(buffer_number * adc_ble_notify_size) + (adc_ble_notify_size)]), adc_ble_notify_size);
			saadc_event_callback = false;
		}
		idle_state_handle();
	}

Maximum MTU size is 251.

I sent data in 16-bit form, so when I receive in mobile, it looks like '(0x) 00-00-00-00-00....' for example.

That means, if I want to send 123 numbers in 16-bit form, I should get 123X2 8-bit numbers.

However, I got only 243 8-bit numbers.

Not only 123, but also for 'n' 16-bit numbers. I always get nX2-3 8-bit numbers.

So, I loss 1 complete 16-bit number and half of a 16-bit number.

Is there any recommendation for this problem? I cannot figure out how to fix it...

Best regards,

Parents
  • Hello,

    Maximum MTU size is 251.

    Are you referring to the Bluetooth SIG specifications?
    The maximum data length available to applications is in fact 244.
    The remaining 7 bytes are used by the SoftDevice.
    You can look this up by the defined NRF_SDH_BLE_GATT_MAX_MTU_SIZE(which is 247, minus OPCODE_LENGTH and HANDLE_LENGTH).

    Could you constrict your application data to 244 bytes per package, and see if it then performs as expected?

    Best regards,
    Karl

Reply
  • Hello,

    Maximum MTU size is 251.

    Are you referring to the Bluetooth SIG specifications?
    The maximum data length available to applications is in fact 244.
    The remaining 7 bytes are used by the SoftDevice.
    You can look this up by the defined NRF_SDH_BLE_GATT_MAX_MTU_SIZE(which is 247, minus OPCODE_LENGTH and HANDLE_LENGTH).

    Could you constrict your application data to 244 bytes per package, and see if it then performs as expected?

    Best regards,
    Karl

Children
No Data
Related