Пример #1
0
void init_bme280(struct bme280_t * sens)
{
	bme280_init_interface(sens);
	bme280_init(sens);
	bme280_set_power_mode(sens, BME280_SLEEP_MODE);
	bme280_set_standby_durn(sens, BME280_STANDBY_TIME_250_MS);
	bme280_set_oversamp_humidity(sens, BME280_OVERSAMP_1X);
	bme280_set_oversamp_temperature(sens, BME280_OVERSAMP_8X);
	bme280_set_oversamp_pressure(sens, BME280_OVERSAMP_1X);
	bme280_set_power_mode(sens, BME280_NORMAL_MODE);
}
Пример #2
0
static int sensor_board_bme280_read(i2c_device dev)
{
        /* The variable used to read uncompensated temperature */
        s32 v_data_uncomp_tem_s32 = BME280_INIT_VALUE;
        /* The variable used to read uncompensated pressure */
        s32 v_data_uncomp_pres_s32 = BME280_INIT_VALUE;
        /* The variable used to read uncompensated pressure */
        s32 v_data_uncomp_hum_s32 = BME280_INIT_VALUE;
        /* The variable used to read real temperature */
        s32 v_actual_temp_s32 = BME280_INIT_VALUE;
        /* The variable used to read real pressure */
        u32 v_actual_press_u32 = BME280_INIT_VALUE;
        /* The variable used to read real humidity */
        u32 v_actual_humity_u32 = BME280_INIT_VALUE;
        /* result of communication results */
        s32 com_rslt = 0;
        bme280_dev = dev;
        u8 delay;

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

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

        /*
         * For reading the pressure, humidity and temperature data it is required to
         * set the OSS setting of humidity, pressure and temperature
         * The "BME280_CTRLHUM_REG_OSRSH" register sets the humidity
         * data acquisition options of the device.
         * changes to this registers only become effective after a write operation to
         * "BME280_CTRLMEAS_REG" register.
         * In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
         * register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
         * the "BME280_CTRLMEAS_REG" register in the function
         */
        com_rslt += bme280_set_oversamp_humidity(BME280_OVERSAMP_1X);

        /* set the pressure oversampling */
        com_rslt += bme280_set_oversamp_pressure(BME280_OVERSAMP_2X);

        /* set the temperature oversampling */
        com_rslt += bme280_set_oversamp_temperature(BME280_OVERSAMP_4X);

        /*
         * Normal mode comprises an automated perpetual cycling between an (active)
         * Measurement period and an (inactive) standby period.
         * The standby time is determined by the contents of the register t_sb.
         * Standby time can be set using BME280_STANDBYTIME_125_MS.
         * Usage Hint : bme280_set_standbydur(BME280_STANDBYTIME_125_MS)
         */
        com_rslt += bme280_set_standby_durn(BME280_STANDBY_TIME_1_MS);

        /*
         * Computation time depends on what measurements are selected and which oversampling is
         * used. This helper function will calculate time to wait before data can be read.
         */
        bme280_compute_wait_time(&delay);

        /*
         * Wait for calculated time.
         */
        OS_DELAY_MS(delay);

        /*
         * Read raw ADC value from sensor
         */
        com_rslt += bme280_read_uncomp_pressure_temperature_humidity(&v_data_uncomp_tem_s32,
                                                &v_data_uncomp_pres_s32, &v_data_uncomp_hum_s32);

        printf(NEWLINE "Uncompensated temp=%d, pres=%d, hum=%u", v_data_uncomp_tem_s32,
                v_data_uncomp_pres_s32, v_data_uncomp_hum_s32);

        /*
         * Read the true temperature, humidity and pressure.
         * This function will convert ADC value to true values according to calibration data.
         * Pressure humidity and temperature are fixed point values.
         * Temperature in 0.01C, pressure in Pa, humidity in 0.001%.
         */
        com_rslt += bme280_read_pressure_temperature_humidity(&v_actual_press_u32,
                                                        &v_actual_temp_s32, &v_actual_humity_u32);

        printf(NEWLINE "Compensated pressure=%d.%02d hPa, temp=%d.%02d C, hum=%u.%03d %%",
                v_actual_press_u32 / 100, v_actual_press_u32 % 100,
                v_actual_temp_s32 / 100, v_actual_temp_s32 % 100,
                v_actual_humity_u32 / 1000, v_actual_humity_u32 % 1000);
        /*
         * For de-initialization it is required to set the mode of
         * the sensor as "SLEEP"
         * the device reaches the lowest power consumption only
         * In SLEEP mode no measurements are performed
         * All registers are accessible
         * by using the below API able to set the power mode as SLEEP
         */
        com_rslt += bme280_set_power_mode(BME280_SLEEP_MODE);

        return com_rslt;
}
Пример #3
0
/* This function is an example for reading sensor data
 *	\param: None
 *	\return: communication result
 */
s32 bme280_data_readout_template(void)
{
	/* The variable used to assign the standby time*/
	u8 v_stand_by_time_u8 = BME280_INIT_VALUE;
	/* The variable used to read uncompensated temperature*/
	s32 v_data_uncomp_tem_s32 = BME280_INIT_VALUE;
	/* The variable used to read uncompensated pressure*/
	s32 v_data_uncomp_pres_s32 = BME280_INIT_VALUE;
	/* The variable used to read uncompensated pressure*/
	s32 v_data_uncomp_hum_s32 = BME280_INIT_VALUE;
	/* The variable used to read real temperature*/
	s32 v_actual_temp_s32 = BME280_INIT_VALUE;
	/* The variable used to read real pressure*/
	u32 v_actual_press_u32 = BME280_INIT_VALUE;
	/* The variable used to read real humidity*/
	u32 v_actual_humity_u32 = BME280_INIT_VALUE;
	/* result of communication results*/
	s32 com_rslt = BME280_ERROR;



 /*********************** START INITIALIZATION ************************/
  /*	Based on the user need configure I2C or SPI interface.
  *	It is example code to explain how to use the bme280 API*/
  #ifdef BME280_API
	I2C_routine();
	/*SPI_routine(); */
	#endif
/*--------------------------------------------------------------------------*
 *  This function used to assign the value/reference of
 *	the following parameters
 *	I2C address
 *	Bus Write
 *	Bus read
 *	Chip id
*-------------------------------------------------------------------------*/
	com_rslt = bme280_init(&bme280);

	/*	For initialization it is required to set the mode of
	 *	the sensor as "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 += bme280_set_power_mode(BME280_NORMAL_MODE);
	/*	For reading the pressure, humidity and temperature data it is required to
	 *	set the OSS setting of humidity, pressure and temperature
	 * The "BME280_CTRLHUM_REG_OSRSH" register sets the humidity
	 * data acquisition options of the device.
	 * changes to this registers only become effective after a write operation to
	 * "BME280_CTRLMEAS_REG" register.
	 * In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
	 * register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
	 * the "BME280_CTRLMEAS_REG" register in the function*/
	com_rslt += bme280_set_oversamp_humidity(BME280_OVERSAMP_1X);

	/* set the pressure oversampling*/
	com_rslt += bme280_set_oversamp_pressure(BME280_OVERSAMP_2X);
	/* set the temperature oversampling*/
	com_rslt += bme280_set_oversamp_temperature(BME280_OVERSAMP_4X);
/*--------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*
************************* START GET and SET FUNCTIONS DATA ****************
*---------------------------------------------------------------------------*/
	/* This API used to Write the standby time of the sensor input
	 *	value have to be given
	 *	Normal mode comprises an automated perpetual cycling between an (active)
	 *	Measurement period and an (inactive) standby period.
	 *	The standby time is determined by the contents of the register t_sb.
	 *	Standby time can be set using BME280_STANDBYTIME_125_MS.
	 *	Usage Hint : bme280_set_standbydur(BME280_STANDBYTIME_125_MS)*/

	com_rslt += bme280_set_standby_durn(BME280_STANDBY_TIME_1_MS);

	/* This API used to read back the written value of standby time*/
	com_rslt += bme280_get_standby_durn(&v_stand_by_time_u8);
/*-----------------------------------------------------------------*
************************* END GET and SET FUNCTIONS ****************
*------------------------------------------------------------------*/

/************************* END INITIALIZATION *************************/

/*------------------------------------------------------------------*
************ START READ UNCOMPENSATED PRESSURE, TEMPERATURE
AND HUMIDITY DATA ********
*---------------------------------------------------------------------*/
	/* API is used to read the uncompensated temperature*/
	com_rslt += bme280_read_uncomp_temperature(&v_data_uncomp_tem_s32);

	/* API is used to read the uncompensated pressure*/
	com_rslt += bme280_read_uncomp_pressure(&v_data_uncomp_pres_s32);

	/* API is used to read the uncompensated humidity*/
	com_rslt += bme280_read_uncomp_humidity(&v_data_uncomp_hum_s32);

	/* API is used to read the uncompensated temperature,pressure
	and humidity data */
	com_rslt += bme280_read_uncomp_pressure_temperature_humidity(
	&v_data_uncomp_tem_s32, &v_data_uncomp_pres_s32, &v_data_uncomp_hum_s32);
/*--------------------------------------------------------------------*
************ END READ UNCOMPENSATED PRESSURE AND TEMPERATURE********
*-------------------------------------------------------------------------*/

/*------------------------------------------------------------------*
************ START READ TRUE PRESSURE, TEMPERATURE
AND HUMIDITY DATA ********
*---------------------------------------------------------------------*/
	/* API is used to read the true temperature*/
	/* Input value as uncompensated temperature and output format*/
	com_rslt += bme280_compensate_temperature_int32(v_data_uncomp_tem_s32);

	/* API is used to read the true pressure*/
	/* Input value as uncompensated pressure */
	com_rslt += bme280_compensate_pressure_int32(v_data_uncomp_pres_s32);

	/* API is used to read the true humidity*/
	/* Input value as uncompensated humidity and output format*/
	com_rslt += bme280_compensate_humidity_int32(v_data_uncomp_hum_s32);

	/* API is used to read the true temperature, humidity and pressure*/
	com_rslt += bme280_read_pressure_temperature_humidity(
	&v_actual_press_u32, &v_actual_temp_s32, &v_actual_humity_u32);
/*--------------------------------------------------------------------*
************ END READ TRUE PRESSURE, TEMPERATURE AND HUMIDITY ********
*-------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------*
************************* START DE-INITIALIZATION ***********************
*-------------------------------------------------------------------------*/
	/*	For de-initialization it is required to set the mode of
	 *	the sensor as "SLEEP"
	 *	the device reaches the lowest power consumption only
	 *	In SLEEP mode no measurements are performed
	 *	All registers are accessible
	 *	by using the below API able to set the power mode as SLEEP*/
	 /* Set the power mode as SLEEP*/
	com_rslt += bme280_set_power_mode(BME280_SLEEP_MODE);
/*---------------------------------------------------------------------*
************************* END DE-INITIALIZATION **********************
*---------------------------------------------------------------------*/
return com_rslt;
}