Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: bmp280prova mbed
Fork of F411RE_I2C_IMU10D0F by
main.cpp
- Committer:
- rudyvic
- Date:
- 2017-04-11
- Revision:
- 2:85bf51c4766f
- Parent:
- 1:a25cc3641119
- Child:
- 3:03eaa31f1ff8
File content as of revision 2:85bf51c4766f:
#include "mbed.h"
#include "bmp280.c"
#include <stdio.h>
Serial pc(SERIAL_TX,SERIAL_RX);
#define ADDRESS_BMP280 0x77
I2C dispositivo(I2C_SDA,I2C_SCL);
int main() {
struct bmp280_t bmp280;
// eldi culo
//s32 res = bmp280_init(&obj);
s32 pres, temp;
/* The variable used to assign the standby time*/
u8 v_standby_time_u8 = BMP280_INIT_VALUE;
/* The variables used in individual data read APIs*/
/* The variable used to read uncompensated temperature*/
s32 v_data_uncomp_tem_s32 = BMP280_INIT_VALUE;
/* The variable used to read uncompensated pressure*/
s32 v_data_uncomp_pres_s32 = BMP280_INIT_VALUE;
/* The variable used to read real temperature*/
s32 v_actual_temp_s32 = BMP280_INIT_VALUE;
/* The variable used to read real pressure*/
u32 v_actual_press_u32 = BMP280_INIT_VALUE;
/* The variables used in combined data read APIs*/
/* The variable used to read uncompensated temperature*/
s32 v_data_uncomp_tem_combined_s32 = BMP280_INIT_VALUE;
/* The variable used to read uncompensated pressure*/
s32 v_data_uncomp_pres_combined_s32 = BMP280_INIT_VALUE;
/* The variable used to read real temperature*/
s32 v_actual_temp_combined_s32 = BMP280_INIT_VALUE;
/* The variable used to read real pressure*/
u32 v_actual_press_combined_u32 = BMP280_INIT_VALUE;
/* result of communication results*/
s32 com_rslt = ERROR;
/*********************** START INITIALIZATION ************************/
bmp280.dev_addr = BMP280_I2C_ADDRESS2;
/*--------------------------------------------------------------------------*
* This function used to assign the value/reference of
* the following parameters
* I2C address
* Bus Write
* Bus read
* Chip id
*-------------------------------------------------------------------------*/
pc.printf("before - ");
com_rslt = bmp280_init(&bmp280);
pc.printf("after\n");
/* 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 += bmp280_set_power_mode(BMP280_NORMAL_MODE);
/* For reading the pressure and temperature data it is required to
* set the work mode
* The measurement period in the Normal mode is depends on the setting of
* over sampling setting of pressure, temperature and standby time
*
* OSS pressure OSS temperature OSS
* ultra low power x1 x1
* low power x2 x1
* standard resolution x4 x1
* high resolution x8 x2
* ultra high resolution x16 x2
*/
/* The oversampling settings are set by using the following API*/
com_rslt += bmp280_set_work_mode(BMP280_ULTRA_LOW_POWER_MODE);
/*------------------------------------------------------------------------*
************************* 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 BMP280_STANDBYTIME_125_MS.
* Usage Hint : BMP280_set_standbydur(BMP280_STANDBYTIME_125_MS)*/
com_rslt += bmp280_set_standby_durn(BMP280_STANDBY_TIME_1_MS);
/* This API used to read back the written value of standby time*/
com_rslt += bmp280_get_standby_durn(&v_standby_time_u8);
/*-----------------------------------------------------------------*
************************* END GET and SET FUNCTIONS ****************
*------------------------------------------------------------------*/
/************************* END INITIALIZATION *************************/
/*------------------------------------------------------------------*
****** INDIVIDUAL APIs TO READ UNCOMPENSATED PRESSURE AND TEMPERATURE*******
*---------------------------------------------------------------------*/
/* API is used to read the uncompensated temperature*/
com_rslt += bmp280_read_uncomp_temperature(&v_data_uncomp_tem_s32);
/* API is used to read the uncompensated pressure*/
com_rslt += bmp280_read_uncomp_pressure(&v_data_uncomp_pres_s32);
/* API is used to read the true temperature*/
/* Input value as uncompensated temperature*/
v_actual_temp_s32 = bmp280_compensate_temperature_int32(v_data_uncomp_tem_s32);
/* API is used to read the true pressure*/
/* Input value as uncompensated pressure*/
v_actual_press_u32 = bmp280_compensate_pressure_int32(v_data_uncomp_pres_s32);
/*------------------------------------------------------------------*
******* STAND-ALONE APIs TO READ COMBINED TRUE PRESSURE AND TEMPERATURE********
*---------------------------------------------------------------------*/
/* API is used to read the uncompensated temperature and pressure*/
com_rslt += bmp280_read_uncomp_pressure_temperature(&v_data_uncomp_pres_combined_s32,
&v_data_uncomp_tem_combined_s32);
pc.printf("pres %d - temp %d",v_data_uncomp_pres_combined_s32,v_data_uncomp_tem_combined_s32);
/* API is used to read the true temperature and pressure*/
com_rslt += bmp280_read_pressure_temperature(&v_actual_press_combined_u32,
&v_actual_temp_combined_s32);
com_rslt += bmp280_set_power_mode(BMP280_SLEEP_MODE);
/*
while(1) {
char v, primo, secondo;
char reg = 0xD0;
dispositivo.write(ADDRESS_BMP280<<1,®,1);
dispositivo.read(ADDRESS_BMP280<<1,&v,1);
reg = 0xF4;
dispositivo.write(ADDRESS_BMP280<<1,®,1);
dispositivo.read(ADDRESS_BMP280<<1,&primo,1);
reg = 0xF4;
dispositivo.write(ADDRESS_BMP280<<1,®,1);
dispositivo.write(ADDRESS_BMP280<<1,&v,1);
reg = 0xF4;
dispositivo.write(ADDRESS_BMP280<<1,®,1);
dispositivo.read(ADDRESS_BMP280<<1,&secondo,1);
pc.printf("%#08x - %#08x - %#08x\n",v,primo,secondo);
wait(2);
}
*/
}
