コード例 #1
0
ファイル: bmm050_user.c プロジェクト: SergeyPopovGit/MICO
OSStatus bmm050_data_readout(s16 *v_mag_datax_s16, s16 *v_mag_datay_s16, s16 *v_mag_dataz_s16)
{
  OSStatus err = kUnknownErr;
  struct bmm050_mag_data_s16_t data;
  
  /* result of communication results*/
  s32 com_rslt = BMM050_ERROR;
  
  //-------------------------- NOTE ----------------------------------
  // this is to avoid i2c pin is re-init by other module because they use the same pin.
  MicoI2cInitialize(&bmm050_i2c_device);
  //------------------------------------------------------------------
    
  /************ START READ TRUE PRESSURE, TEMPERATURE AND HUMIDITY DATA *********/

  /* accessing the bmm050_mdata parameter by using data*/
  com_rslt = bmm050_read_mag_data_XYZ(&data);/* Reads the mag x y z data*/
  
  *v_mag_datax_s16 = data.datax;
  *v_mag_datay_s16 = data.datay;
  *v_mag_dataz_s16 = data.dataz;
  /************ END READ TRUE PRESSURE, TEMPERATURE AND HUMIDITY ********/
  
  if(0 == com_rslt){
    err = kNoErr;
  }
  return err;
}
コード例 #2
0
static int sensor_board_bmm150_read(i2c_device dev)
{
        /* Structure used for read the mag xyz data*/
        struct bmm050_mag_data_s16_t data;
        /* result of communication results*/
        s32 com_rslt = ERROR;
        bmm150_dev = dev;
        bool sign;
        uint32_t conv_val;

        /*
         * Initialize driver data, feed Bosch driver with functions needed to access I2C bus.
         */
        com_rslt = bmm050_init(&bmm150);

        /*
         * For initialization it is required to set the state of
         * the sensor as "NORMAL MODE"
         * data acquisition/read/write is possible in this mode
         * by using the below API able to set the power mode as NORMAL
         */
        com_rslt += bmm050_set_functional_state(BMM050_NORMAL_MODE);

        /*
         * Set data rate
         */
        com_rslt += bmm050_set_data_rate(BMM050_DATA_RATE_30HZ);

        /* Wait for data ready */
        OS_DELAY(1000 / 30 + 1);

        /* accessing the bmm050_mdata parameter by using data*/
        com_rslt += bmm050_read_mag_data_XYZ(&data);

        /* print raw values */
        printf(NEWLINE "Compensated magnetometer data (raw 16 bit) - x: %04X, y: %04X, z: %04X",
                        (uint16_t) data.datax, (uint16_t) data.datay, (uint16_t) data.dataz);
        /* convert and print values in uT (microtesla unit) */
        printf(NEWLINE "Compensated magnetometer data  - ");
        convert_xy_value(data.datax, &sign, &conv_val);
        printf("x: %s%lu.%02lu uT, ", (sign ? "-" : ""), conv_val / 100, conv_val % 100);
        convert_xy_value(data.datay, &sign, &conv_val);
        printf("y: %s%lu.%02lu uT, ", (sign ? "-" : ""), conv_val / 100, conv_val % 100);
        convert_z_value(data.dataz, &sign, &conv_val);
        printf("z: %s%lu.%02lu uT", (sign ? "-" : ""), conv_val / 100, conv_val % 100);

        /* For de-initialization it is required to set the mode of
         * the sensor as "SUSPEND"
         * the SUSPEND mode set from the register 0x4B bit BMM050_INIT_VALUE should be disabled
         * by using the below API able to set the power mode as SUSPEND
         */
        com_rslt += bmm050_set_functional_state(BMM050_SUSPEND_MODE);

        return com_rslt;
}
コード例 #3
0
ファイル: bmm050_user.c プロジェクト: SergeyPopovGit/MICO
/* This function is an example for reading sensor data
 *	\param: None
 *	\return: communication result
 */
s32 bmm050_data_readout_template(void)
{
	/* Structure used for read the mag xyz data*/
	struct bmm050_mag_data_s16_t data;
	/* Structure used for read the mag xyz data with 32 bit output*/
	struct bmm050_mag_s32_data_t data_s32;
	/* Structure used for read the mag xyz data with float output*/
	struct bmm050_mag_data_float_t data_float;
	/* Variable used to get the data rate*/
	u8 v_data_rate_u8 = BMM050_INIT_VALUE;
	/* Variable used to set the data rate*/
	u8 v_data_rate_value_u8 = BMM050_INIT_VALUE;
	/* result of communication results*/
	s32 com_rslt = 0;

/*---------------------------------------------------------------------------*
 *********************** START INITIALIZATION ************************
 *--------------------------------------------------------------------------*/
 /*	Based on the user need configure I2C or SPI interface.
  *	It is sample code to explain how to use the bmm050 API*/
	#ifdef BMM050_API
	BMM050_I2C_routine();
	/*BMM050_SPI_routine(); */
	#endif
/*--------------------------------------------------------------------------*
 *  This function used to assign the value/reference of
 *	the following parameters
 *	I2C address
 *	Bus Write
 *	Bus read
 *	company_id
*-------------------------------------------------------------------------*/
	com_rslt = bmm050_init(&bmm050_t);

/*	For initialization it is required to set the mode of
 *	the sensor as "NORMAL"
 *	but before set the mode needs to configure the power control bit
 *	in the register 0x4B bit BMM050_INIT_VALUE should be enabled
 *	This bit is enabled by calling bmm050_init function
 *	For the Normal data acquisition/read/write is possible in this mode
 *	by using the below API able to set the power mode as NORMAL*/
	/* Set the power mode as NORMAL*/
	com_rslt += bmm050_set_functional_state(BMM050_NORMAL_MODE);
/*--------------------------------------------------------------------------*
************************* END INITIALIZATION *************************
*---------------------------------------------------------------------------*/

/*------------------------------------------------------------------------*
************************* START GET and SET FUNCTIONS DATA ****************
*---------------------------------------------------------------------------*/
	/* This API used to Write the data rate of the sensor, input
	value have to be given
	data rate value set from the register 0x4C bit 3 to 5*/
	v_data_rate_value_u8 = BMM050_DATA_RATE_30HZ;/* set data rate of 30Hz*/
	com_rslt += bmm050_set_data_rate(v_data_rate_value_u8);

	/* This API used to read back the written value of data rate*/
	com_rslt += bmm050_get_data_rate(&v_data_rate_u8);
/*-----------------------------------------------------------------*
************************* END GET and SET FUNCTIONS ****************
*-------------------------------------------------------------------*/
/*------------------------------------------------------------------*
************************* START READ SENSOR DATA(X,Y and Z axis) ********
*------------------------------------------------------------------*/
	/* accessing the bmm050_mdata parameter by using data*/
	com_rslt += bmm050_read_mag_data_XYZ(&data);/* Reads the mag x y z data*/


	/* accessing the bmm050_mdata_float parameter by using data_float*/
	com_rslt += bmm050_read_mag_data_XYZ_float(&data_float);/* Reads mag xyz data output as 32bit value*/

	/* accessing the bmm050_mdata_s32 parameter by using data_s32*/
	com_rslt += bmm050_read_mag_data_XYZ_s32(&data_s32);/* Reads mag xyz data output as float value*/

/*--------------------------------------------------------------------*
************************* END READ SENSOR DATA(X,Y and Z axis) ************
*-------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*
************************* START DE-INITIALIZATION ***********************
*-------------------------------------------------------------------------*/
/*	For de-initialization it is required to set the mode of
 *	the sensor as "SUSPEND"
 *	the SUSPEND mode set from the register 0x4B bit BMM050_INIT_VALUE should be disabled
 *	by using the below API able to set the power mode as SUSPEND*/
	/* Set the power mode as SUSPEND*/
	com_rslt += bmm050_set_functional_state(BMM050_SUSPEND_MODE);
/*---------------------------------------------------------------------*
************************* END DE-INITIALIZATION **********************
*---------------------------------------------------------------------*/
return com_rslt;
}