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

ble data transfer

Hi,

I am using the following statements for send a string data over BLE.

static uint8_t Name3[BLE_NUS_MAX_DATA_LEN]= "xxxxxxxx";
	err_code = ble_nus_string_send(&m_nus, Name3, 20);	
	if (err_code != NRF_ERROR_INVALID_STATE)
	{
		APP_ERROR_CHECK(err_code);
	}	

But I am unable to send integers and floating values. Is there a function where I can send non-string data variables via BLE.

Regards Siva

Parents
  • So assume you want to send a uint16_t value of say 10000. This is of course two bytes and you must assign each byte of value to each element of the array Name3. One fairly easy way to do this is bit masking and shifting. So do this:

    Name3[0] = (value & 0xFF00) >> 8;
    Name3[1] = (value & 0x00FF);
    

    Now say value was a unit32_t, which is 4 bytes long, then do this

    Name3[0] = (value & 0xFF000000) >> 24;
    Name3[1] = (value & 0x00FF0000) >> 16;
    Name3[2] = (value & 0x0000FF00) >> 8;
    Name3[3] = (value & 0x000000FF);
    
Reply
  • So assume you want to send a uint16_t value of say 10000. This is of course two bytes and you must assign each byte of value to each element of the array Name3. One fairly easy way to do this is bit masking and shifting. So do this:

    Name3[0] = (value & 0xFF00) >> 8;
    Name3[1] = (value & 0x00FF);
    

    Now say value was a unit32_t, which is 4 bytes long, then do this

    Name3[0] = (value & 0xFF000000) >> 24;
    Name3[1] = (value & 0x00FF0000) >> 16;
    Name3[2] = (value & 0x0000FF00) >> 8;
    Name3[3] = (value & 0x000000FF);
    
Children
Related