RoboNucleo / Mbed 2 deprecated F411RE_I2C_IMU10D0F

Dependencies:   bmp280prova mbed

Fork of F411RE_I2C_IMU10D0F by Rudy Vicario

Committer:
rudyvic
Date:
Tue Apr 11 09:51:38 2017 +0000
Revision:
2:85bf51c4766f
Parent:
1:a25cc3641119
Child:
3:03eaa31f1ff8
eldi culo;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rudyvic 0:a5bd062b9449 1 #include "mbed.h"
rudyvic 1:a25cc3641119 2 #include "bmp280.c"
rudyvic 0:a5bd062b9449 3 #include <stdio.h>
rudyvic 0:a5bd062b9449 4
rudyvic 0:a5bd062b9449 5 Serial pc(SERIAL_TX,SERIAL_RX);
rudyvic 0:a5bd062b9449 6
rudyvic 1:a25cc3641119 7 #define ADDRESS_BMP280 0x77
rudyvic 1:a25cc3641119 8
rudyvic 1:a25cc3641119 9 I2C dispositivo(I2C_SDA,I2C_SCL);
rudyvic 1:a25cc3641119 10
rudyvic 0:a5bd062b9449 11 int main() {
rudyvic 1:a25cc3641119 12 struct bmp280_t bmp280;
rudyvic 2:85bf51c4766f 13 // eldi culo
rudyvic 1:a25cc3641119 14 //s32 res = bmp280_init(&obj);
rudyvic 1:a25cc3641119 15
rudyvic 1:a25cc3641119 16 s32 pres, temp;
rudyvic 1:a25cc3641119 17 /* The variable used to assign the standby time*/
rudyvic 1:a25cc3641119 18 u8 v_standby_time_u8 = BMP280_INIT_VALUE;
rudyvic 1:a25cc3641119 19
rudyvic 1:a25cc3641119 20 /* The variables used in individual data read APIs*/
rudyvic 1:a25cc3641119 21 /* The variable used to read uncompensated temperature*/
rudyvic 1:a25cc3641119 22 s32 v_data_uncomp_tem_s32 = BMP280_INIT_VALUE;
rudyvic 1:a25cc3641119 23 /* The variable used to read uncompensated pressure*/
rudyvic 1:a25cc3641119 24 s32 v_data_uncomp_pres_s32 = BMP280_INIT_VALUE;
rudyvic 1:a25cc3641119 25 /* The variable used to read real temperature*/
rudyvic 1:a25cc3641119 26 s32 v_actual_temp_s32 = BMP280_INIT_VALUE;
rudyvic 1:a25cc3641119 27 /* The variable used to read real pressure*/
rudyvic 1:a25cc3641119 28 u32 v_actual_press_u32 = BMP280_INIT_VALUE;
rudyvic 1:a25cc3641119 29
rudyvic 1:a25cc3641119 30 /* The variables used in combined data read APIs*/
rudyvic 1:a25cc3641119 31 /* The variable used to read uncompensated temperature*/
rudyvic 1:a25cc3641119 32 s32 v_data_uncomp_tem_combined_s32 = BMP280_INIT_VALUE;
rudyvic 1:a25cc3641119 33 /* The variable used to read uncompensated pressure*/
rudyvic 1:a25cc3641119 34 s32 v_data_uncomp_pres_combined_s32 = BMP280_INIT_VALUE;
rudyvic 1:a25cc3641119 35 /* The variable used to read real temperature*/
rudyvic 1:a25cc3641119 36 s32 v_actual_temp_combined_s32 = BMP280_INIT_VALUE;
rudyvic 1:a25cc3641119 37 /* The variable used to read real pressure*/
rudyvic 1:a25cc3641119 38 u32 v_actual_press_combined_u32 = BMP280_INIT_VALUE;
rudyvic 1:a25cc3641119 39
rudyvic 1:a25cc3641119 40 /* result of communication results*/
rudyvic 1:a25cc3641119 41 s32 com_rslt = ERROR;
rudyvic 1:a25cc3641119 42 /*********************** START INITIALIZATION ************************/
rudyvic 1:a25cc3641119 43
rudyvic 1:a25cc3641119 44 bmp280.dev_addr = BMP280_I2C_ADDRESS2;
rudyvic 1:a25cc3641119 45
rudyvic 1:a25cc3641119 46 /*--------------------------------------------------------------------------*
rudyvic 1:a25cc3641119 47 * This function used to assign the value/reference of
rudyvic 1:a25cc3641119 48 * the following parameters
rudyvic 1:a25cc3641119 49 * I2C address
rudyvic 1:a25cc3641119 50 * Bus Write
rudyvic 1:a25cc3641119 51 * Bus read
rudyvic 1:a25cc3641119 52 * Chip id
rudyvic 1:a25cc3641119 53 *-------------------------------------------------------------------------*/
rudyvic 1:a25cc3641119 54 pc.printf("before - ");
rudyvic 1:a25cc3641119 55 com_rslt = bmp280_init(&bmp280);
rudyvic 1:a25cc3641119 56 pc.printf("after\n");
rudyvic 1:a25cc3641119 57 /* For initialization it is required to set the mode of
rudyvic 1:a25cc3641119 58 * the sensor as "NORMAL"
rudyvic 1:a25cc3641119 59 * data acquisition/read/write is possible in this mode
rudyvic 1:a25cc3641119 60 * by using the below API able to set the power mode as NORMAL*/
rudyvic 1:a25cc3641119 61 /* Set the power mode as NORMAL*/
rudyvic 1:a25cc3641119 62 com_rslt += bmp280_set_power_mode(BMP280_NORMAL_MODE);
rudyvic 1:a25cc3641119 63 /* For reading the pressure and temperature data it is required to
rudyvic 1:a25cc3641119 64 * set the work mode
rudyvic 1:a25cc3641119 65 * The measurement period in the Normal mode is depends on the setting of
rudyvic 1:a25cc3641119 66 * over sampling setting of pressure, temperature and standby time
rudyvic 1:a25cc3641119 67 *
rudyvic 1:a25cc3641119 68 * OSS pressure OSS temperature OSS
rudyvic 1:a25cc3641119 69 * ultra low power x1 x1
rudyvic 1:a25cc3641119 70 * low power x2 x1
rudyvic 1:a25cc3641119 71 * standard resolution x4 x1
rudyvic 1:a25cc3641119 72 * high resolution x8 x2
rudyvic 1:a25cc3641119 73 * ultra high resolution x16 x2
rudyvic 1:a25cc3641119 74 */
rudyvic 1:a25cc3641119 75 /* The oversampling settings are set by using the following API*/
rudyvic 1:a25cc3641119 76 com_rslt += bmp280_set_work_mode(BMP280_ULTRA_LOW_POWER_MODE);
rudyvic 1:a25cc3641119 77 /*------------------------------------------------------------------------*
rudyvic 1:a25cc3641119 78 ************************* START GET and SET FUNCTIONS DATA ****************
rudyvic 1:a25cc3641119 79 *---------------------------------------------------------------------------*/
rudyvic 1:a25cc3641119 80 /* This API used to Write the standby time of the sensor input
rudyvic 1:a25cc3641119 81 * value have to be given*/
rudyvic 1:a25cc3641119 82 /* Normal mode comprises an automated perpetual cycling between an (active)
rudyvic 1:a25cc3641119 83 * Measurement period and an (inactive) standby period.
rudyvic 1:a25cc3641119 84 * The standby time is determined by the contents of the register t_sb.
rudyvic 1:a25cc3641119 85 * Standby time can be set using BMP280_STANDBYTIME_125_MS.
rudyvic 1:a25cc3641119 86 * Usage Hint : BMP280_set_standbydur(BMP280_STANDBYTIME_125_MS)*/
rudyvic 1:a25cc3641119 87
rudyvic 1:a25cc3641119 88 com_rslt += bmp280_set_standby_durn(BMP280_STANDBY_TIME_1_MS);
rudyvic 1:a25cc3641119 89
rudyvic 1:a25cc3641119 90 /* This API used to read back the written value of standby time*/
rudyvic 1:a25cc3641119 91 com_rslt += bmp280_get_standby_durn(&v_standby_time_u8);
rudyvic 1:a25cc3641119 92 /*-----------------------------------------------------------------*
rudyvic 1:a25cc3641119 93 ************************* END GET and SET FUNCTIONS ****************
rudyvic 1:a25cc3641119 94 *------------------------------------------------------------------*/
rudyvic 1:a25cc3641119 95
rudyvic 1:a25cc3641119 96 /************************* END INITIALIZATION *************************/
rudyvic 1:a25cc3641119 97
rudyvic 1:a25cc3641119 98 /*------------------------------------------------------------------*
rudyvic 1:a25cc3641119 99 ****** INDIVIDUAL APIs TO READ UNCOMPENSATED PRESSURE AND TEMPERATURE*******
rudyvic 1:a25cc3641119 100 *---------------------------------------------------------------------*/
rudyvic 1:a25cc3641119 101 /* API is used to read the uncompensated temperature*/
rudyvic 1:a25cc3641119 102 com_rslt += bmp280_read_uncomp_temperature(&v_data_uncomp_tem_s32);
rudyvic 1:a25cc3641119 103
rudyvic 1:a25cc3641119 104 /* API is used to read the uncompensated pressure*/
rudyvic 1:a25cc3641119 105 com_rslt += bmp280_read_uncomp_pressure(&v_data_uncomp_pres_s32);
rudyvic 1:a25cc3641119 106
rudyvic 1:a25cc3641119 107 /* API is used to read the true temperature*/
rudyvic 1:a25cc3641119 108 /* Input value as uncompensated temperature*/
rudyvic 1:a25cc3641119 109 v_actual_temp_s32 = bmp280_compensate_temperature_int32(v_data_uncomp_tem_s32);
rudyvic 1:a25cc3641119 110
rudyvic 1:a25cc3641119 111 /* API is used to read the true pressure*/
rudyvic 1:a25cc3641119 112 /* Input value as uncompensated pressure*/
rudyvic 1:a25cc3641119 113 v_actual_press_u32 = bmp280_compensate_pressure_int32(v_data_uncomp_pres_s32);
rudyvic 1:a25cc3641119 114
rudyvic 1:a25cc3641119 115 /*------------------------------------------------------------------*
rudyvic 1:a25cc3641119 116 ******* STAND-ALONE APIs TO READ COMBINED TRUE PRESSURE AND TEMPERATURE********
rudyvic 1:a25cc3641119 117 *---------------------------------------------------------------------*/
rudyvic 1:a25cc3641119 118
rudyvic 1:a25cc3641119 119
rudyvic 1:a25cc3641119 120 /* API is used to read the uncompensated temperature and pressure*/
rudyvic 1:a25cc3641119 121 com_rslt += bmp280_read_uncomp_pressure_temperature(&v_data_uncomp_pres_combined_s32,
rudyvic 1:a25cc3641119 122 &v_data_uncomp_tem_combined_s32);
rudyvic 1:a25cc3641119 123
rudyvic 1:a25cc3641119 124 pc.printf("pres %d - temp %d",v_data_uncomp_pres_combined_s32,v_data_uncomp_tem_combined_s32);
rudyvic 1:a25cc3641119 125
rudyvic 1:a25cc3641119 126 /* API is used to read the true temperature and pressure*/
rudyvic 1:a25cc3641119 127 com_rslt += bmp280_read_pressure_temperature(&v_actual_press_combined_u32,
rudyvic 1:a25cc3641119 128 &v_actual_temp_combined_s32);
rudyvic 1:a25cc3641119 129
rudyvic 1:a25cc3641119 130 com_rslt += bmp280_set_power_mode(BMP280_SLEEP_MODE);
rudyvic 1:a25cc3641119 131
rudyvic 1:a25cc3641119 132 /*
rudyvic 0:a5bd062b9449 133 while(1) {
rudyvic 1:a25cc3641119 134 char v, primo, secondo;
rudyvic 1:a25cc3641119 135 char reg = 0xD0;
rudyvic 1:a25cc3641119 136 dispositivo.write(ADDRESS_BMP280<<1,&reg,1);
rudyvic 1:a25cc3641119 137 dispositivo.read(ADDRESS_BMP280<<1,&v,1);
rudyvic 1:a25cc3641119 138
rudyvic 1:a25cc3641119 139 reg = 0xF4;
rudyvic 1:a25cc3641119 140 dispositivo.write(ADDRESS_BMP280<<1,&reg,1);
rudyvic 1:a25cc3641119 141 dispositivo.read(ADDRESS_BMP280<<1,&primo,1);
rudyvic 1:a25cc3641119 142
rudyvic 1:a25cc3641119 143 reg = 0xF4;
rudyvic 1:a25cc3641119 144 dispositivo.write(ADDRESS_BMP280<<1,&reg,1);
rudyvic 1:a25cc3641119 145 dispositivo.write(ADDRESS_BMP280<<1,&v,1);
rudyvic 1:a25cc3641119 146
rudyvic 1:a25cc3641119 147 reg = 0xF4;
rudyvic 1:a25cc3641119 148 dispositivo.write(ADDRESS_BMP280<<1,&reg,1);
rudyvic 1:a25cc3641119 149 dispositivo.read(ADDRESS_BMP280<<1,&secondo,1);
rudyvic 1:a25cc3641119 150
rudyvic 1:a25cc3641119 151 pc.printf("%#08x - %#08x - %#08x\n",v,primo,secondo);
rudyvic 1:a25cc3641119 152 wait(2);
rudyvic 1:a25cc3641119 153 }
rudyvic 1:a25cc3641119 154 */
rudyvic 0:a5bd062b9449 155 }