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

device disconnect when sending uin32_t

Hi Nordic's community,

I have an issue when writing uint32_t to a characteristic, i don't understand when i write uint16_t or uin8_t, it works ! but don't when i send an uin32_t value to my characteristic ?

My Android device (with Master control panel) disconnect when i try to write to this characteristic...

I add my characteristic like this:

attr_char_value.p_uuid       = &ble_uuid;
attr_char_value.p_attr_md    = &attr_md;
attr_char_value.init_len     = sizeof(uint32_t);
attr_char_value.init_offs    = 0;
attr_char_value.max_len      = sizeof(uint32_t);
attr_char_value.p_value      = (uint8_t*) &initalValueAlarm;

with initialValueAlarm is an uin32_t type variable.

My write funtion handler is like this:

if ( (p_evt_write->handle == p_lbs->led_char_handles.value_handle) && (p_evt_write->len == 4) && (p_lbs->led_write_handler != NULL)) 
	
{
    p_lbs->led_write_handler(p_lbs, *( (uint32_t*) p_evt_write->data )); 
			SEGGER_RTT_printf(0, "%d\n", *( (uint32_t*) p_evt_write->data ));
}

It works perfeclty with uint16_t or uint8_t type but not with uint32_t type, and i don't understand why... Thanks for your help.

EDIT 13/06/2016:

I add two pictures of the nrf master control panel, one with the characteristic and one with the error:

and the error on the NRF MCP:

image description

and the characteristic:

image description

EDIT 14/06/2016:

I add the demo project:experimental_ble_app_blinky.zip folder.

EDIT 15/06/2016:

I add the modified ble_lbs librarie:

ble_lbs.zip

Parents
  • Hi mbredes, you need to do operation inside a for(...) loop.I resolve my problem like this:

    if ( p_evt_write->handle == p_lbs->vibration_on_char_handles.value_handle && (p_evt_write->len == 2) 
    		&& (p_lbs->vibrationOn_write_handler != NULL))  
    	
    	{
    		
    		  uint16_t value_vibration_ON = 0;
    		
    			for(uint8_t i=0 ; i<p_evt_write->len ; i++) {
    			
    				value_vibration_ON += p_evt_write->data[i] << i * 8;
    			}		
    			
    		 p_lbs->vibrationOn_write_handler(p_lbs, value_vibration_ON); 
    		
    	}
    

    You need to work at the low level with bit and byte. You can see on google how you can do for an array of two float.I can see tomorrow if i have time. I suggest you to open an other thread, maybe you may have better answer than mine :)

    regards.

  • Your answer was enough to help me figure it out. Thanks!

Reply Children
No Data
Related