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

i2c data on ble

hello there . i want to get i2c data on ble advertising packet

int main(void)
{
    uint32_t err_code;
    bool erase_bonds;
	ret_code_t ret_code;
	 int16_t x_val;
    int16_t y_val;
    int16_t z_val;
    uint8_t  start_string[] = START_STRING;
	   ret_code = twi_master_init();
    
    ret_code = ADXL375_I2C_init(&m_twi_master);
    
    // Initialize.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
    uart_init();
    buttons_leds_init(&erase_bonds);
    ble_stack_init();
    gap_params_init();
    services_init();
    advertising_init();
	advertising_start();
    conn_params_init();
    
   printf("%s",start_string);

    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);
    
    // Enter main loop.
        for (;;)
        {  printf("rushin");
    			 ADXL375_I2C_acc_data_read(&x_val,&y_val,&z_val);
    			printf("X: %d  \r", x_val) ;
    			delay_ms(100000);
    				delay_ms(100000);
    			  printf("Y: %d \r",y_val);
    			delay_ms(100000);
    				delay_ms(100000);
    			  printf("Z: %d \r" , z_val); 
    			delay_ms(100000);
    				delay_ms(100000);
    			printf("\n");
            power_manage();
        }
    }

in main function i am getting data.but now i want to get data on advertising function code is here

static void advertising_init(void)
{
     uint32_t            err_code;
	int16_t x_val;
    int16_t y_val;
    int16_t z_val;
    ble_advdata_t       advdata;    // Struct containing advertising parameters
    uint8_t             flags       = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    ble_uuid_t          adv_uuids[] = {{0x1234, BLE_UUID_TYPE_BLE}};  
 ADXL375_I2C_acc_data_read(&x_val,&y_val,&z_val);
    ble_advdata_manuf_data_t        manuf_data; // Variable to hold manufacturer specific data
    uint8_t data[3]                      = {x_val,y_val,z_val}; // Our data to adverise
    manuf_data.company_identifier       = 0x0059; // Nordics company ID
    manuf_data.data.p_data              = data;     
    manuf_data.data.size                = sizeof(data);

    // Populate the advertising packet
    // Always initialize all fields in structs to zero or you might get unexpected behaviours
    memset(&advdata, 0, sizeof(advdata));

    advdata.name_type               = BLE_ADVDATA_SHORT_NAME;                   // Use short name
    advdata.short_name_len          = 6;                                        // Advertise first 6 letters of name
    advdata.flags                   = flags;                                    // Set some flags. This is a topic for another tutorial
    advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]); // Create a list of UUIDs. This is a topic for another tutorial
    advdata.uuids_complete.p_uuids  = adv_uuids;                                // Create a list of UUIDs. This is a topic for another tutorial
    advdata.p_manuf_specific_data   = &manuf_data;                              // Load the manufacturer specific data into advertising packet
    // Set the advertisement and scan response packet. 
    err_code = ble_advdata_set(&advdata, NULL);
    APP_ERROR_CHECK(err_code);// Check for errors
}

here i want to data in uint8_t data[3] array. but my data is int16_t.on advertising packet i am getting constant data like Manufacture specific data:59-00-05-F3-FF. can you help me??

Parents
  • no of course you can't use the company identifier.

    If you want three int16_t then define data as an array of ... 3 x int16_t instead of 3 x uint8_t. You must have the compiler warnings turned down, assigning three 16 bit values to an 8-bit array is usually something it would tell you about. Change to (not checked with a compiler, just typed straight in)

    uint16_t data[3] = { x_val, y_val , z_val };
    manuf_data.p_data = (uint8_t*)data;
    manuf_data.data.size = sizeof( data )
    

    .. and if you're thinking that will update the advertising data each time x_val etc change, it won't, but it will put the current values in.

Reply
  • no of course you can't use the company identifier.

    If you want three int16_t then define data as an array of ... 3 x int16_t instead of 3 x uint8_t. You must have the compiler warnings turned down, assigning three 16 bit values to an 8-bit array is usually something it would tell you about. Change to (not checked with a compiler, just typed straight in)

    uint16_t data[3] = { x_val, y_val , z_val };
    manuf_data.p_data = (uint8_t*)data;
    manuf_data.data.size = sizeof( data )
    

    .. and if you're thinking that will update the advertising data each time x_val etc change, it won't, but it will put the current values in.

Children
No Data
Related