Digital Pressure Sensor

Committer:
mcm
Date:
Tue Sep 11 11:35:00 2018 +0000
Revision:
3:60816c745222
Parent:
2:3a52d110213a
The driver was completed and tested ( NUCLEO-L152RE ), it works as expected

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mcm 2:3a52d110213a 1 /**
mcm 2:3a52d110213a 2 * @brief BMP180.cpp
mcm 2:3a52d110213a 3 * @details Digital Pressure Sensor.
mcm 2:3a52d110213a 4 * Functions file.
mcm 2:3a52d110213a 5 *
mcm 2:3a52d110213a 6 *
mcm 2:3a52d110213a 7 * @return N/A
mcm 2:3a52d110213a 8 *
mcm 2:3a52d110213a 9 * @author Manuel Caballero
mcm 2:3a52d110213a 10 * @date 11/September/2018
mcm 2:3a52d110213a 11 * @version 11/September/2018 The ORIGIN
mcm 2:3a52d110213a 12 * @pre N/A
mcm 2:3a52d110213a 13 * @warning N/A
mcm 2:3a52d110213a 14 * @pre This code belongs to Nimbus Centre ( http://www.nimbus.cit.ie ).
mcm 2:3a52d110213a 15 */
mcm 2:3a52d110213a 16
mcm 2:3a52d110213a 17 #include "BMP180.h"
mcm 2:3a52d110213a 18
mcm 2:3a52d110213a 19
mcm 2:3a52d110213a 20 BMP180::BMP180 ( PinName sda, PinName scl, uint32_t addr, uint32_t freq )
mcm 2:3a52d110213a 21 : _i2c ( sda, scl )
mcm 2:3a52d110213a 22 , _BMP180_Addr ( addr )
mcm 2:3a52d110213a 23 {
mcm 2:3a52d110213a 24 _i2c.frequency( freq );
mcm 2:3a52d110213a 25 }
mcm 2:3a52d110213a 26
mcm 2:3a52d110213a 27
mcm 2:3a52d110213a 28 BMP180::~BMP180()
mcm 2:3a52d110213a 29 {
mcm 2:3a52d110213a 30 }
mcm 2:3a52d110213a 31
mcm 2:3a52d110213a 32
mcm 2:3a52d110213a 33
mcm 2:3a52d110213a 34 /**
mcm 2:3a52d110213a 35 * @brief BMP180_GetID ( BMP180_chip_id_data_t* )
mcm 2:3a52d110213a 36 * @details It gets the chip-ID.
mcm 2:3a52d110213a 37 *
mcm 2:3a52d110213a 38 * @param[in] N/A.
mcm 2:3a52d110213a 39 *
mcm 2:3a52d110213a 40 * @param[out] myID: Chip-ID
mcm 2:3a52d110213a 41 *
mcm 2:3a52d110213a 42 *
mcm 2:3a52d110213a 43 * @return Status of BMP180_GetID.
mcm 2:3a52d110213a 44 *
mcm 2:3a52d110213a 45 * @author Manuel Caballero
mcm 2:3a52d110213a 46 * @date 11/September/2018
mcm 2:3a52d110213a 47 * @version 11/September/2018 The ORIGIN
mcm 2:3a52d110213a 48 * @pre It must be 0x55.
mcm 2:3a52d110213a 49 * @warning N/A.
mcm 2:3a52d110213a 50 */
mcm 2:3a52d110213a 51 BMP180::BMP180_status_t BMP180::BMP180_GetID ( BMP180_chip_id_data_t* myID )
mcm 2:3a52d110213a 52 {
mcm 2:3a52d110213a 53 char cmd = 0U;
mcm 2:3a52d110213a 54 uint32_t aux;
mcm 2:3a52d110213a 55
mcm 2:3a52d110213a 56
mcm 2:3a52d110213a 57 /* Get ID */
mcm 2:3a52d110213a 58 cmd = BMP180_ID;
mcm 2:3a52d110213a 59 aux = _i2c.write ( _BMP180_Addr, &cmd, 1U, true );
mcm 2:3a52d110213a 60 aux = _i2c.read ( _BMP180_Addr, (char*)&myID->id, 1U );
mcm 2:3a52d110213a 61
mcm 2:3a52d110213a 62
mcm 2:3a52d110213a 63
mcm 2:3a52d110213a 64
mcm 2:3a52d110213a 65 if ( aux == I2C_SUCCESS ) {
mcm 2:3a52d110213a 66 return BMP180_SUCCESS;
mcm 2:3a52d110213a 67 } else {
mcm 2:3a52d110213a 68 return BMP180_FAILURE;
mcm 2:3a52d110213a 69 }
mcm 2:3a52d110213a 70 }
mcm 2:3a52d110213a 71
mcm 2:3a52d110213a 72
mcm 2:3a52d110213a 73
mcm 2:3a52d110213a 74 /**
mcm 2:3a52d110213a 75 * @brief BMP180_SoftReset ( void )
mcm 2:3a52d110213a 76 * @details It performs a soft reset.
mcm 2:3a52d110213a 77 *
mcm 2:3a52d110213a 78 * @param[in] N/A.
mcm 2:3a52d110213a 79 *
mcm 2:3a52d110213a 80 * @param[out] N/A
mcm 2:3a52d110213a 81 *
mcm 2:3a52d110213a 82 *
mcm 2:3a52d110213a 83 * @return Status of BMP180_SoftReset.
mcm 2:3a52d110213a 84 *
mcm 2:3a52d110213a 85 * @author Manuel Caballero
mcm 2:3a52d110213a 86 * @date 11/September/2018
mcm 2:3a52d110213a 87 * @version 11/September/2018 The ORIGIN
mcm 2:3a52d110213a 88 * @pre N/A
mcm 2:3a52d110213a 89 * @warning N/A.
mcm 2:3a52d110213a 90 */
mcm 2:3a52d110213a 91 BMP180::BMP180_status_t BMP180::BMP180_SoftReset ( void )
mcm 2:3a52d110213a 92 {
mcm 2:3a52d110213a 93 char cmd[] = { 0, 0 };
mcm 2:3a52d110213a 94 uint32_t aux;
mcm 2:3a52d110213a 95
mcm 2:3a52d110213a 96
mcm 2:3a52d110213a 97 cmd[0] = BMP180_SOFT;
mcm 2:3a52d110213a 98 cmd[1] = SOFT_SOFT_RESET;
mcm 2:3a52d110213a 99 aux = _i2c.write ( _BMP180_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), false );
mcm 2:3a52d110213a 100
mcm 2:3a52d110213a 101
mcm 2:3a52d110213a 102
mcm 2:3a52d110213a 103
mcm 2:3a52d110213a 104 if ( aux == I2C_SUCCESS ) {
mcm 2:3a52d110213a 105 return BMP180_SUCCESS;
mcm 2:3a52d110213a 106 } else {
mcm 2:3a52d110213a 107 return BMP180_FAILURE;
mcm 2:3a52d110213a 108 }
mcm 2:3a52d110213a 109 }
mcm 2:3a52d110213a 110
mcm 2:3a52d110213a 111
mcm 2:3a52d110213a 112 /**
mcm 2:3a52d110213a 113 * @brief BMP180_Get_Cal_Param ( BMP180_calibration_data_t* )
mcm 2:3a52d110213a 114 * @details It reads the calibration data.
mcm 2:3a52d110213a 115 *
mcm 2:3a52d110213a 116 * @param[in] N/A.
mcm 2:3a52d110213a 117 *
mcm 2:3a52d110213a 118 * @param[out] myCalibrationData: Calibration data from the sensor.
mcm 2:3a52d110213a 119 *
mcm 2:3a52d110213a 120 *
mcm 2:3a52d110213a 121 * @return Status of BMP180_Get_Cal_Param.
mcm 2:3a52d110213a 122 *
mcm 2:3a52d110213a 123 * @author Manuel Caballero
mcm 2:3a52d110213a 124 * @date 11/September/2018
mcm 2:3a52d110213a 125 * @version 11/September/2018 The ORIGIN
mcm 2:3a52d110213a 126 * @pre N/A
mcm 2:3a52d110213a 127 * @warning N/A
mcm 2:3a52d110213a 128 */
mcm 2:3a52d110213a 129 BMP180::BMP180_status_t BMP180::BMP180_Get_Cal_Param ( BMP180_calibration_data_t* myCalibrationData )
mcm 2:3a52d110213a 130 {
mcm 2:3a52d110213a 131 char cmd[22] = { 0U };
mcm 2:3a52d110213a 132 uint32_t aux;
mcm 2:3a52d110213a 133
mcm 2:3a52d110213a 134
mcm 2:3a52d110213a 135 /* Read out all calibration data from the sensor ( auto-increment ) */
mcm 2:3a52d110213a 136 cmd[0] = BMP180_AC1_MSB;
mcm 2:3a52d110213a 137 aux = _i2c.write ( _BMP180_Addr, &cmd[0], 1U, true );
mcm 2:3a52d110213a 138 aux = _i2c.read ( _BMP180_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
mcm 2:3a52d110213a 139
mcm 2:3a52d110213a 140
mcm 2:3a52d110213a 141 /* Parse the data */
mcm 2:3a52d110213a 142 myCalibrationData->ac1 = cmd[0];
mcm 2:3a52d110213a 143 myCalibrationData->ac1 <<= 8U;
mcm 2:3a52d110213a 144 myCalibrationData->ac1 |= cmd[1];
mcm 2:3a52d110213a 145
mcm 2:3a52d110213a 146 myCalibrationData->ac2 = cmd[2];
mcm 2:3a52d110213a 147 myCalibrationData->ac2 <<= 8U;
mcm 2:3a52d110213a 148 myCalibrationData->ac2 |= cmd[3];
mcm 2:3a52d110213a 149
mcm 2:3a52d110213a 150 myCalibrationData->ac3 = cmd[4];
mcm 2:3a52d110213a 151 myCalibrationData->ac3 <<= 8U;
mcm 2:3a52d110213a 152 myCalibrationData->ac3 |= cmd[5];
mcm 2:3a52d110213a 153
mcm 2:3a52d110213a 154 myCalibrationData->ac4 = cmd[6];
mcm 2:3a52d110213a 155 myCalibrationData->ac4 <<= 8U;
mcm 2:3a52d110213a 156 myCalibrationData->ac4 |= cmd[7];
mcm 2:3a52d110213a 157
mcm 2:3a52d110213a 158 myCalibrationData->ac5 = cmd[8];
mcm 2:3a52d110213a 159 myCalibrationData->ac5 <<= 8U;
mcm 2:3a52d110213a 160 myCalibrationData->ac5 |= cmd[9];
mcm 2:3a52d110213a 161
mcm 2:3a52d110213a 162 myCalibrationData->ac6 = cmd[10];
mcm 2:3a52d110213a 163 myCalibrationData->ac6 <<= 8U;
mcm 2:3a52d110213a 164 myCalibrationData->ac6 |= cmd[11];
mcm 2:3a52d110213a 165
mcm 2:3a52d110213a 166 myCalibrationData->b1 = cmd[12];
mcm 2:3a52d110213a 167 myCalibrationData->b1 <<= 8U;
mcm 2:3a52d110213a 168 myCalibrationData->b1 |= cmd[13];
mcm 2:3a52d110213a 169
mcm 2:3a52d110213a 170 myCalibrationData->b2 = cmd[14];
mcm 2:3a52d110213a 171 myCalibrationData->b2 <<= 8U;
mcm 2:3a52d110213a 172 myCalibrationData->b2 |= cmd[15];
mcm 2:3a52d110213a 173
mcm 2:3a52d110213a 174 myCalibrationData->mb = cmd[16];
mcm 2:3a52d110213a 175 myCalibrationData->mb <<= 8U;
mcm 2:3a52d110213a 176 myCalibrationData->mb |= cmd[17];
mcm 2:3a52d110213a 177
mcm 2:3a52d110213a 178 myCalibrationData->mc = cmd[18];
mcm 2:3a52d110213a 179 myCalibrationData->mc <<= 8U;
mcm 2:3a52d110213a 180 myCalibrationData->mc |= cmd[19];
mcm 2:3a52d110213a 181
mcm 2:3a52d110213a 182 myCalibrationData->md = cmd[20];
mcm 2:3a52d110213a 183 myCalibrationData->md <<= 8U;
mcm 2:3a52d110213a 184 myCalibrationData->md |= cmd[21];
mcm 2:3a52d110213a 185
mcm 2:3a52d110213a 186
mcm 2:3a52d110213a 187
mcm 2:3a52d110213a 188
mcm 2:3a52d110213a 189
mcm 2:3a52d110213a 190 if ( aux == I2C_SUCCESS ) {
mcm 2:3a52d110213a 191 return BMP180_SUCCESS;
mcm 2:3a52d110213a 192 } else {
mcm 2:3a52d110213a 193 return BMP180_FAILURE;
mcm 2:3a52d110213a 194 }
mcm 2:3a52d110213a 195 }
mcm 2:3a52d110213a 196
mcm 2:3a52d110213a 197
mcm 2:3a52d110213a 198
mcm 2:3a52d110213a 199 /**
mcm 2:3a52d110213a 200 * @brief BMP180_Get_UT ( BMP180_uncompensated_data_t* )
mcm 2:3a52d110213a 201 * @details It reads uncompensated temperature value.
mcm 2:3a52d110213a 202 *
mcm 2:3a52d110213a 203 * @param[in] N/A.
mcm 2:3a52d110213a 204 *
mcm 2:3a52d110213a 205 * @param[out] myUT: Uncompensated temperature value.
mcm 2:3a52d110213a 206 *
mcm 2:3a52d110213a 207 *
mcm 2:3a52d110213a 208 * @return Status of BMP180_Get_UT.
mcm 2:3a52d110213a 209 *
mcm 2:3a52d110213a 210 * @author Manuel Caballero
mcm 2:3a52d110213a 211 * @date 11/September/2018
mcm 2:3a52d110213a 212 * @version 11/September/2018 The ORIGIN
mcm 2:3a52d110213a 213 * @pre This function checks the bit SCO until the conversion is complete instead of
mcm 2:3a52d110213a 214 * 4.5ms.
mcm 2:3a52d110213a 215 * @warning N/A
mcm 2:3a52d110213a 216 */
mcm 2:3a52d110213a 217 BMP180::BMP180_status_t BMP180::BMP180_Get_UT ( BMP180_uncompensated_data_t* myUT )
mcm 2:3a52d110213a 218 {
mcm 2:3a52d110213a 219 char cmd[] = { 0U, 0U };
mcm 2:3a52d110213a 220 uint32_t myTimeout = 0U;
mcm 2:3a52d110213a 221 uint32_t aux;
mcm 2:3a52d110213a 222
mcm 2:3a52d110213a 223
mcm 2:3a52d110213a 224 /* Read out the uncompensated temperature data */
mcm 2:3a52d110213a 225 cmd[0] = BMP180_CTRL_MEAS;
mcm 2:3a52d110213a 226 cmd[1] = BMP180_TRIGGER_TEMPERATURE;
mcm 2:3a52d110213a 227 aux = _i2c.write ( _BMP180_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), false );
mcm 2:3a52d110213a 228
mcm 2:3a52d110213a 229
mcm 2:3a52d110213a 230 /* Wait until conversion is complete or timeout */
mcm 2:3a52d110213a 231 myTimeout = 0x232323;
mcm 2:3a52d110213a 232 do {
mcm 2:3a52d110213a 233 cmd[0] = BMP180_CTRL_MEAS;
mcm 2:3a52d110213a 234 aux = _i2c.write ( _BMP180_Addr, &cmd[0], 1U, true );
mcm 2:3a52d110213a 235 aux = _i2c.read ( _BMP180_Addr, &cmd[0], 1U );
mcm 2:3a52d110213a 236 myTimeout--;
mcm 2:3a52d110213a 237 } while ( ( ( cmd[0] & CTRL_MEAS_SCO_MASK ) == CTRL_MEAS_SCO_CONVERSION_IN_PROGRESS ) && ( myTimeout > 0U ) );
mcm 2:3a52d110213a 238
mcm 2:3a52d110213a 239
mcm 2:3a52d110213a 240 /* Parse the data only if not timeout */
mcm 2:3a52d110213a 241 if ( myTimeout > 0U ) {
mcm 2:3a52d110213a 242 cmd[0] = BMP180_OUT_MSB;
mcm 2:3a52d110213a 243 aux = _i2c.write ( _BMP180_Addr, &cmd[0], 1U, true );
mcm 2:3a52d110213a 244 aux = _i2c.read ( _BMP180_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
mcm 2:3a52d110213a 245
mcm 2:3a52d110213a 246 /* Parse the data */
mcm 2:3a52d110213a 247 myUT->ut = cmd[0];
mcm 2:3a52d110213a 248 myUT->ut <<= 8U;
mcm 2:3a52d110213a 249 myUT->ut |= cmd[1];
mcm 2:3a52d110213a 250 }
mcm 2:3a52d110213a 251
mcm 2:3a52d110213a 252
mcm 2:3a52d110213a 253
mcm 2:3a52d110213a 254
mcm 2:3a52d110213a 255
mcm 2:3a52d110213a 256 if ( ( aux == I2C_SUCCESS ) && ( myTimeout > 0U ) ) {
mcm 2:3a52d110213a 257 return BMP180_SUCCESS;
mcm 2:3a52d110213a 258 } else {
mcm 2:3a52d110213a 259 return BMP180_FAILURE;
mcm 2:3a52d110213a 260 }
mcm 2:3a52d110213a 261 }
mcm 2:3a52d110213a 262
mcm 2:3a52d110213a 263
mcm 2:3a52d110213a 264
mcm 2:3a52d110213a 265 /**
mcm 2:3a52d110213a 266 * @brief BMP180_Get_UP ( BMP180_pressure_resolution_t , BMP180_uncompensated_data_t* )
mcm 2:3a52d110213a 267 * @details It reads uncompensated pressure value.
mcm 2:3a52d110213a 268 *
mcm 2:3a52d110213a 269 * @param[in] myPressureResolutionMode: Resolution mode.
mcm 2:3a52d110213a 270 *
mcm 2:3a52d110213a 271 * @param[out] myUP: Uncompensated pressure value.
mcm 2:3a52d110213a 272 *
mcm 2:3a52d110213a 273 *
mcm 2:3a52d110213a 274 * @return Status of BMP180_Get_UP.
mcm 2:3a52d110213a 275 *
mcm 2:3a52d110213a 276 * @author Manuel Caballero
mcm 2:3a52d110213a 277 * @date 11/September/2018
mcm 2:3a52d110213a 278 * @version 11/September/2018 The ORIGIN
mcm 2:3a52d110213a 279 * @pre This function checks the bit SCO until the conversion is complete instead of
mcm 2:3a52d110213a 280 * the delay depending of the resolution mode:
mcm 2:3a52d110213a 281 * - Ultra low power mode 4.5ms ( max. )
mcm 2:3a52d110213a 282 * - Standard mode 7.5ms ( max. )
mcm 2:3a52d110213a 283 * - High resolution mode 13.5ms ( max. )
mcm 2:3a52d110213a 284 * - Ultra high resolution mode 25.5ms ( max. )
mcm 2:3a52d110213a 285 * @warning N/A
mcm 2:3a52d110213a 286 */
mcm 2:3a52d110213a 287 BMP180::BMP180_status_t BMP180::BMP180_Get_UP ( BMP180_pressure_resolution_t myPressureResolutionMode, BMP180_uncompensated_data_t* myUP )
mcm 2:3a52d110213a 288 {
mcm 2:3a52d110213a 289 char cmd[] = { 0U, 0U, 0U };
mcm 2:3a52d110213a 290 uint32_t myTimeout = 0U;
mcm 2:3a52d110213a 291 uint32_t aux;
mcm 2:3a52d110213a 292
mcm 2:3a52d110213a 293
mcm 2:3a52d110213a 294 /* Read out the uncompensated pressure data according to the chosen resolution mode */
mcm 2:3a52d110213a 295 cmd[0] = BMP180_CTRL_MEAS;
mcm 2:3a52d110213a 296 cmd[1] = ( BMP180_TRIGGER_PRESSURE | myPressureResolutionMode ) ;
mcm 2:3a52d110213a 297 aux = _i2c.write ( _BMP180_Addr, &cmd[0], 2U, false );
mcm 2:3a52d110213a 298
mcm 2:3a52d110213a 299
mcm 2:3a52d110213a 300 /* Wait until conversion is complete or timeout */
mcm 2:3a52d110213a 301 myTimeout = 0x232323;
mcm 2:3a52d110213a 302 do {
mcm 2:3a52d110213a 303 cmd[0] = BMP180_CTRL_MEAS;
mcm 2:3a52d110213a 304 aux = _i2c.write ( _BMP180_Addr, &cmd[0], 1U, true );
mcm 2:3a52d110213a 305 aux = _i2c.read ( _BMP180_Addr, &cmd[0], 1U );
mcm 2:3a52d110213a 306 myTimeout--;
mcm 2:3a52d110213a 307 } while ( ( ( cmd[0] & CTRL_MEAS_SCO_MASK ) == CTRL_MEAS_SCO_CONVERSION_IN_PROGRESS ) && ( myTimeout > 0U ) );
mcm 2:3a52d110213a 308
mcm 2:3a52d110213a 309
mcm 2:3a52d110213a 310 /* Parse the data only if not timeout */
mcm 2:3a52d110213a 311 if ( myTimeout > 0U ) {
mcm 2:3a52d110213a 312 cmd[0] = BMP180_OUT_MSB;
mcm 2:3a52d110213a 313 aux = _i2c.write ( _BMP180_Addr, &cmd[0], 1U, true );
mcm 2:3a52d110213a 314 aux = _i2c.read ( _BMP180_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
mcm 2:3a52d110213a 315
mcm 2:3a52d110213a 316 /* Parse the data */
mcm 2:3a52d110213a 317 myUP->up = cmd[0];
mcm 2:3a52d110213a 318 myUP->up <<= 8U;
mcm 2:3a52d110213a 319 myUP->up |= cmd[1];
mcm 2:3a52d110213a 320 myUP->up <<= 8U;
mcm 2:3a52d110213a 321 myUP->up |= cmd[2];
mcm 2:3a52d110213a 322 myUP->up >>= ( 8U - ( myPressureResolutionMode >> 6U ) );
mcm 2:3a52d110213a 323 }
mcm 2:3a52d110213a 324
mcm 2:3a52d110213a 325
mcm 2:3a52d110213a 326
mcm 2:3a52d110213a 327
mcm 2:3a52d110213a 328
mcm 2:3a52d110213a 329 if ( ( aux == I2C_SUCCESS ) && ( myTimeout > 0U ) ) {
mcm 2:3a52d110213a 330 return BMP180_SUCCESS;
mcm 2:3a52d110213a 331 } else {
mcm 2:3a52d110213a 332 return BMP180_FAILURE;
mcm 2:3a52d110213a 333 }
mcm 2:3a52d110213a 334 }
mcm 2:3a52d110213a 335
mcm 2:3a52d110213a 336
mcm 2:3a52d110213a 337
mcm 2:3a52d110213a 338 /**
mcm 2:3a52d110213a 339 * @brief BMP180_Get_Temperature ( BMP180_calibration_data_t , BMP180_uncompensated_data_t )
mcm 2:3a52d110213a 340 * @details It calculates true temperature.
mcm 2:3a52d110213a 341 *
mcm 2:3a52d110213a 342 * @param[in] myCalibrationData: Calibration data.
mcm 2:3a52d110213a 343 * @param[in] myUT: Uncompensated temperature value.
mcm 2:3a52d110213a 344 *
mcm 2:3a52d110213a 345 * @param[out] N/A.
mcm 2:3a52d110213a 346 *
mcm 2:3a52d110213a 347 *
mcm 2:3a52d110213a 348 * @return True temperature.
mcm 2:3a52d110213a 349 *
mcm 2:3a52d110213a 350 * @author Manuel Caballero
mcm 2:3a52d110213a 351 * @date 11/September/2018
mcm 2:3a52d110213a 352 * @version 11/September/2018 The ORIGIN
mcm 2:3a52d110213a 353 * @pre True temperature in 0.1 C.
mcm 2:3a52d110213a 354 * @pre It is sufficient to measure the temperature only once per second and use this value for all pressure measurements during the same period.
mcm 2:3a52d110213a 355 * @warning This function should have been called at least once: BMP180_Get_Cal_Param.
mcm 2:3a52d110213a 356 * @warning This function should have been called before: BMP180_Get_UT.
mcm 2:3a52d110213a 357 */
mcm 2:3a52d110213a 358 BMP180::BMP180_temperature_data_t BMP180::BMP180_Get_Temperature ( BMP180_calibration_data_t myCalibrationData, BMP180_uncompensated_data_t myUT )
mcm 2:3a52d110213a 359 {
mcm 2:3a52d110213a 360 int32_t x1 = 0, x2 = 0;
mcm 2:3a52d110213a 361
mcm 2:3a52d110213a 362 BMP180_temperature_data_t myTrueData;
mcm 2:3a52d110213a 363
mcm 2:3a52d110213a 364
mcm 2:3a52d110213a 365 /* Calculate X1 */
mcm 2:3a52d110213a 366 x1 = ( myUT.ut - myCalibrationData.ac6 ) * myCalibrationData.ac5 / 32768.0f;
mcm 2:3a52d110213a 367
mcm 2:3a52d110213a 368 /* Calculate X2 */
mcm 2:3a52d110213a 369 x2 = ( myCalibrationData.mc * 2048.0f );
mcm 2:3a52d110213a 370 x2 /= ( x1 + myCalibrationData.md );
mcm 2:3a52d110213a 371
mcm 2:3a52d110213a 372 /* Calculate B5 */
mcm 2:3a52d110213a 373 myTrueData.b5 = ( x1 + x2 );
mcm 2:3a52d110213a 374
mcm 2:3a52d110213a 375 /* Calculate True Temperature */
mcm 2:3a52d110213a 376 myTrueData.temp = ( myTrueData.b5 + 8.0f ) / 16.0f;
mcm 2:3a52d110213a 377
mcm 2:3a52d110213a 378
mcm 2:3a52d110213a 379
mcm 2:3a52d110213a 380 return myTrueData;
mcm 2:3a52d110213a 381 }
mcm 2:3a52d110213a 382
mcm 2:3a52d110213a 383
mcm 2:3a52d110213a 384
mcm 2:3a52d110213a 385 /**
mcm 2:3a52d110213a 386 * @brief BMP180_Get_CalPressure ( BMP180_calibration_data_t , BMP180_data_t , BMP180_pressure_resolution_t , BMP180_uncompensated_data_t )
mcm 2:3a52d110213a 387 * @details It calculates true pressure.
mcm 2:3a52d110213a 388 *
mcm 2:3a52d110213a 389 * @param[in] myCalibrationData: Calibration data.
mcm 2:3a52d110213a 390 * @param[in] myB5: Temperature parameter value.
mcm 2:3a52d110213a 391 * @param[in] myPressureResolutionMode: Resolution mode.
mcm 2:3a52d110213a 392 * @param[in] myUP: Uncompensated pressure value.
mcm 2:3a52d110213a 393 *
mcm 2:3a52d110213a 394 * @param[out] N/A.
mcm 2:3a52d110213a 395 *
mcm 2:3a52d110213a 396 *
mcm 2:3a52d110213a 397 * @return True Pressure.
mcm 2:3a52d110213a 398 *
mcm 2:3a52d110213a 399 * @author Manuel Caballero
mcm 2:3a52d110213a 400 * @date 11/September/2018
mcm 2:3a52d110213a 401 * @version 11/September/2018 The ORIGIN
mcm 2:3a52d110213a 402 * @pre True temperature in Pa.
mcm 2:3a52d110213a 403 * @pre It is sufficient to measure the temperature only once per second and use this value for all pressure measurements during the same period.
mcm 2:3a52d110213a 404 * @warning These functions should have been called at least once: BMP180_Get_Cal_Param and BMP180_Get_Temperature.
mcm 2:3a52d110213a 405 * @warning This function should have been called before: BMP180_Get_UP.
mcm 2:3a52d110213a 406 */
mcm 2:3a52d110213a 407 BMP180::BMP180_pressure_data_t BMP180::BMP180_Get_CalPressure ( BMP180_calibration_data_t myCalibrationData, BMP180_temperature_data_t myB5, BMP180_pressure_resolution_t myPressureResolutionMode, BMP180_uncompensated_data_t myUP )
mcm 2:3a52d110213a 408 {
mcm 2:3a52d110213a 409 int32_t b6 = 0, x1 = 0, x2 = 0, x3 = 0, b3 = 0;
mcm 2:3a52d110213a 410 uint32_t b4 = 0, b7 = 0;
mcm 2:3a52d110213a 411
mcm 2:3a52d110213a 412 BMP180_pressure_data_t myTrueData;
mcm 2:3a52d110213a 413
mcm 2:3a52d110213a 414
mcm 2:3a52d110213a 415 /* Calculate B6 */
mcm 2:3a52d110213a 416 b6 = ( myB5.b5 - 4000.0f );
mcm 2:3a52d110213a 417
mcm 2:3a52d110213a 418 /* Calculate X1 */
mcm 2:3a52d110213a 419 x1 = ( myCalibrationData.b2 * ( b6 * b6 / 4096.0f ) ) / 2048.0f;
mcm 2:3a52d110213a 420
mcm 2:3a52d110213a 421 /* Calculate X2 */
mcm 2:3a52d110213a 422 x2 = myCalibrationData.ac2 * b6 / 4096.0f;
mcm 2:3a52d110213a 423
mcm 2:3a52d110213a 424 /* Calculate X3 */
mcm 2:3a52d110213a 425 x3 = x1 + x2;
mcm 2:3a52d110213a 426
mcm 2:3a52d110213a 427 /* Calculate B3 */
mcm 2:3a52d110213a 428 b3 = ( ( ( ( (long)myCalibrationData.ac1 * 4 + x3 ) << ( myPressureResolutionMode >> 6U ) ) + 2 ) ) / 4.0f;
mcm 2:3a52d110213a 429
mcm 2:3a52d110213a 430 /* Re-calculate X1 */
mcm 2:3a52d110213a 431 x1 = ( myCalibrationData.ac3 * b6 ) / 524288.0f;
mcm 2:3a52d110213a 432
mcm 2:3a52d110213a 433 /* Re-calculate X2 */
mcm 2:3a52d110213a 434 x2 = ( myCalibrationData.b1 * ( b6 * b6 / 4096.0f ) ) / 65536.0f;
mcm 2:3a52d110213a 435
mcm 2:3a52d110213a 436 /* Re-calculate X3 */
mcm 2:3a52d110213a 437 x3 = ( ( x1 + x2 ) + 2.0f ) / 4.0f;
mcm 2:3a52d110213a 438
mcm 2:3a52d110213a 439 /* Calculate B4 */
mcm 2:3a52d110213a 440 b4 = myCalibrationData.ac4 * (unsigned long)( x3 + 32768.0f ) / 32768.0f;
mcm 2:3a52d110213a 441
mcm 2:3a52d110213a 442 /* Calculate B7 */
mcm 2:3a52d110213a 443 b7 = ( (unsigned long)myUP.up - b3 ) * ( 50000 >> ( myPressureResolutionMode >> 6U ) );
mcm 2:3a52d110213a 444
mcm 2:3a52d110213a 445
mcm 2:3a52d110213a 446 if ( b7 < 0x80000000 ) {
mcm 2:3a52d110213a 447 myTrueData.press = ( b7 * 2.0f ) / b4;
mcm 2:3a52d110213a 448 } else {
mcm 2:3a52d110213a 449 myTrueData.press = ( b7 / b4 ) * 2.0f;
mcm 2:3a52d110213a 450 }
mcm 2:3a52d110213a 451
mcm 2:3a52d110213a 452 /* Re-calculate X1 */
mcm 2:3a52d110213a 453 x1 = ( myTrueData.press / 256.0f ) * ( myTrueData.press / 256.0f );
mcm 2:3a52d110213a 454 x1 = ( x1 * 3038.0f ) / 65536.0f;
mcm 2:3a52d110213a 455
mcm 2:3a52d110213a 456 /* Re-calculate X2 */
mcm 2:3a52d110213a 457 x2 = ( -7357.0f * myTrueData.press ) / 65536.0f;
mcm 2:3a52d110213a 458
mcm 2:3a52d110213a 459 /* Calculate True Pressure */
mcm 2:3a52d110213a 460 myTrueData.press += ( x1 + x2 + 3791.0f ) / 16.0f;
mcm 2:3a52d110213a 461
mcm 2:3a52d110213a 462
mcm 2:3a52d110213a 463
mcm 2:3a52d110213a 464 return myTrueData;
mcm 2:3a52d110213a 465 }