Library for supporting the Nucleo Sensor Shield.
Dependents: Nucleo_Sensors_Demo m2x-temp_ethernet_demo m2x-MEMS_ACKme_Wifi_demo m2x_MEMS_Ublox_Cellular_demo ... more
Fork of Nucleo_Sensor_Shield by
Warning: Deprecated!
Supported drivers and applications can be found at this link.
Diff: Components/LPS25H/lps25.cpp
- Revision:
- 1:354f61ffdcfb
- Parent:
- 0:0433918efb54
- Child:
- 2:57888ec40e75
diff -r 0433918efb54 -r 354f61ffdcfb Components/LPS25H/lps25.cpp --- a/Components/LPS25H/lps25.cpp Sat Dec 13 01:09:48 2014 +0000 +++ b/Components/LPS25H/lps25.cpp Sat Dec 13 02:33:16 2014 +0000 @@ -81,16 +81,19 @@ //PRESSURE_IO_Read(buffer, LPS25H_SlaveAddress, LPS25H_PRESS_POUT_XL_ADDR+0x80, 3); ret = dev_i2c.i2c_read(buffer, LPS25H_ADDRESS_HIGH, LPS25H_PRESS_POUT_XL_ADDR+0x80, 3); - /* Build the raw data */ - for (i = 0 ; i < 3 ; i++) - tempVal |= (((uint32_t) buffer[i]) << (8 * i)); + if (ret == 0) + { + /* Build the raw data */ + for (i = 0 ; i < 3 ; i++) + tempVal |= (((uint32_t) buffer[i]) << (8 * i)); - /* convert the 2's complement 24 bit to 2's complement 32 bit */ - if (tempVal & 0x00800000) - tempVal |= 0xFF000000; + /* convert the 2's complement 24 bit to 2's complement 32 bit */ + if (tempVal & 0x00800000) + tempVal |= 0xFF000000; - /* return the built value */ - *raw_press = ((uint32_t) tempVal); + /* return the built value */ + *raw_press = ((uint32_t) tempVal); + } } /** @@ -108,7 +111,7 @@ ret = dev_i2c.i2c_read(&tmp, LPS25H_ADDRESS_HIGH, LPS25H_WHO_AM_I_ADDR, 1); /* Return the ID */ - return (uint8_t)tmp; + return ((ret == 0) ? (uint8_t)tmp : 0); } /** @@ -125,43 +128,52 @@ //PRESSURE_IO_Read(&tmp1, LPS25H_SlaveAddress, LPS25H_CTRL_REG1_ADDR, 1); ret = dev_i2c.i2c_read(&tmp1, LPS25H_ADDRESS_HIGH, LPS25H_CTRL_REG1_ADDR, 1); - /* Output Data Rate selection */ - tmp1 &= ~(LPS25H_ODR_MASK); - tmp1 |= LPS25H_ODR_1Hz; - - /* Interrupt circuit selection */ - tmp1 &= ~(LPS25H_DIFF_EN_MASK); - tmp1 |= LPS25H_DIFF_ENABLE; + if (ret == 0) + { + /* Output Data Rate selection */ + tmp1 &= ~(LPS25H_ODR_MASK); + tmp1 |= LPS25H_ODR_1Hz; - /* Block Data Update selection */ - tmp1 &= ~(LPS25H_BDU_MASK); - tmp1 |= LPS25H_BDU_CONT; + /* Interrupt circuit selection */ + tmp1 &= ~(LPS25H_DIFF_EN_MASK); + tmp1 |= LPS25H_DIFF_ENABLE; - /* Serial Interface Mode selection */ - tmp1 &= ~(LPS25H_SPI_SIM_MASK); - tmp1 |= LPS25H_SPI_SIM_3W; + /* Block Data Update selection */ + tmp1 &= ~(LPS25H_BDU_MASK); + tmp1 |= LPS25H_BDU_CONT; + + /* Serial Interface Mode selection */ + tmp1 &= ~(LPS25H_SPI_SIM_MASK); + tmp1 |= LPS25H_SPI_SIM_3W; - //PRESSURE_IO_Write(&tmp1, LPS25H_SlaveAddress, LPS25H_CTRL_REG1_ADDR, 1); - ret = dev_i2c.i2c_write(&tmp1, LPS25H_ADDRESS_HIGH, LPS25H_CTRL_REG1_ADDR, 1); - - //PRESSURE_IO_Read(&tmp1, LPS25H_SlaveAddress, LPS25H_RES_CONF_ADDR, 1); - ret = dev_i2c.i2c_read(&tmp1, LPS25H_ADDRESS_HIGH, LPS25H_RES_CONF_ADDR, 1); + //PRESSURE_IO_Write(&tmp1, LPS25H_SlaveAddress, LPS25H_CTRL_REG1_ADDR, 1); + ret = dev_i2c.i2c_write(&tmp1, LPS25H_ADDRESS_HIGH, LPS25H_CTRL_REG1_ADDR, 1); + } + + if (ret == 0) + { + //PRESSURE_IO_Read(&tmp1, LPS25H_SlaveAddress, LPS25H_RES_CONF_ADDR, 1); + ret = dev_i2c.i2c_read(&tmp1, LPS25H_ADDRESS_HIGH, LPS25H_RES_CONF_ADDR, 1); - /* Pressure Res selection */ - tmp1 &= ~(LPS25H_P_RES_MASK); - tmp1 |= LPS25H_P_RES_AVG_32; + /* Pressure Res selection */ + tmp1 &= ~(LPS25H_P_RES_MASK); + tmp1 |= LPS25H_P_RES_AVG_32; - /* Temperature Res selection */ - tmp1 &= ~(LPS25H_T_RES_MASK); - tmp1 |= LPS25H_T_RES_AVG_16; + /* Temperature Res selection */ + tmp1 &= ~(LPS25H_T_RES_MASK); + tmp1 |= LPS25H_T_RES_AVG_16; - //PRESSURE_IO_Write(&tmp1, LPS25H_SlaveAddress, LPS25H_RES_CONF_ADDR, 1); - ret = dev_i2c.i2c_write(&tmp1, LPS25H_ADDRESS_HIGH, LPS25H_RES_CONF_ADDR, 1); + //PRESSURE_IO_Write(&tmp1, LPS25H_SlaveAddress, LPS25H_RES_CONF_ADDR, 1); + ret = dev_i2c.i2c_write(&tmp1, LPS25H_ADDRESS_HIGH, LPS25H_RES_CONF_ADDR, 1); + } - if(ReadID() == I_AM_LPS25H) + if (ret == 0) { - Lps25hInitialized = 1; - //ret = HUM_TEMP_OK; + if(ReadID() == I_AM_LPS25H) + { + Lps25hInitialized = 1; + //ret = HUM_TEMP_OK; + } } return; @@ -187,14 +199,12 @@ int LPS25H::LPS25H_Calibration() { - int ret; + int ret = 0; if(Lps25hInitialized == 1) { return 1; //TODO: Error Codes definitions } - - return ret; }