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

How to write uint32_t to characteristic?

I will write time to my ble device and need write uint32_t via characteristic. When i try only (uint8_t)data[0] is correct.

How can I do writable characteristics (uint32_t)? Example please.

Parents
  • Stefan it is other problem.

    I try create writable characteristic with 4 byte data len.

    My on_write ble event handler is:

    static void on_write(ble_dls_t * p_dls, ble_evt_t * p_ble_evt)
    {
        ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
    		uint32_t temp_val = 0;
        
        if ((p_evt_write->handle == p_dls->dl_char_handles.value_handle) &&
            (p_evt_write->len == 4) &&
            (p_dls->dl_write_handler != NULL))
        {
    				p_dls->dl_write_handler(p_dls, p_evt_write);
        }
    		
    }
    

    and dl_write_handler is function:

    static void dl_timestamp_write_handler(ble_dls_t * p_dls, ble_gatts_evt_write_t * p_evt_write)
    {
    
    	volatile uint8_t value1 = ((p_evt_write->data[0]));
    	volatile uint8_t value2 = ((p_evt_write->data[1]));
    	volatile uint8_t value3 = ((p_evt_write->data[2]));
    	volatile uint8_t value4 = ((p_evt_write->data[3]));
    
    }
    

    in debuger when I write in Master Control Panel value 0x12345678:

    value1 = 0x78
    value2 = 0x78
    value3 = 0x78
    value4 = 0x78
    

    how can I resolv problem?

Reply
  • Stefan it is other problem.

    I try create writable characteristic with 4 byte data len.

    My on_write ble event handler is:

    static void on_write(ble_dls_t * p_dls, ble_evt_t * p_ble_evt)
    {
        ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
    		uint32_t temp_val = 0;
        
        if ((p_evt_write->handle == p_dls->dl_char_handles.value_handle) &&
            (p_evt_write->len == 4) &&
            (p_dls->dl_write_handler != NULL))
        {
    				p_dls->dl_write_handler(p_dls, p_evt_write);
        }
    		
    }
    

    and dl_write_handler is function:

    static void dl_timestamp_write_handler(ble_dls_t * p_dls, ble_gatts_evt_write_t * p_evt_write)
    {
    
    	volatile uint8_t value1 = ((p_evt_write->data[0]));
    	volatile uint8_t value2 = ((p_evt_write->data[1]));
    	volatile uint8_t value3 = ((p_evt_write->data[2]));
    	volatile uint8_t value4 = ((p_evt_write->data[3]));
    
    }
    

    in debuger when I write in Master Control Panel value 0x12345678:

    value1 = 0x78
    value2 = 0x78
    value3 = 0x78
    value4 = 0x78
    

    how can I resolv problem?

Children
No Data
Related