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

Transmit number via ble

Hello! I have uint32_t adc_value (from external ADC converter) And try to send it value through ble. My code:

main.c: ....

 for (;;)
    {
	Weighing();
        power_manage();    			 
			if(adc_value)    				
			{
				SEGGER_RTT_printf(0, "%d\n", adc_value);
				ble_adc_send(&m_nus, &adc_value);
			}
			nrf_delay_ms(100);
    }

here's send value function from ble_nus.c:

uint32_t ble_adc_send(ble_nus_t * p_nus, uint32_t *adc_value)
{
    ble_gatts_hvx_params_t hvx_params;

    VERIFY_PARAM_NOT_NULL(p_nus);

    if ((p_nus->conn_handle == BLE_CONN_HANDLE_INVALID) || (!p_nus->is_notification_enabled))
    {
        return NRF_ERROR_INVALID_STATE;
    }
		uint16_t length = 10;
    if (length > BLE_NUS_MAX_DATA_LEN)
    {
        return NRF_ERROR_INVALID_PARAM;
    }
		
    memset(&hvx_params, 0, sizeof(hvx_params));

    hvx_params.handle = p_nus->rx_handles.value_handle;
    hvx_params.p_data = (uint8_t*) adc_value;
    hvx_params.p_len  = &length;
    hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;

    return sd_ble_gatts_hvx(p_nus->conn_handle, &hvx_params);
}
  1. Segger RTT terminal shows correct values but in mobile phone I getting garbage data. Notification works properly by the way.

  2. What is the easiest way to convert int to string. Before working with 8-bit MC I used ultoa/utoa function from the lib with avg gcc compiler, here it's not working. But vice versa converting string to int (itoa) works good

Thanks

Parents Reply Children
Related