| BlueNRG-1 SDK drivers APIs

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

LPS25HB.c
Go to the documentation of this file.
1
37 /* Includes ------------------------------------------------------------------*/
38 #include "LPS25HB.h"
39 #include "LPS25HB_hal.h"
40
41
56 static PRESSURE_StatusTypeDef LPS25HB_Init(PRESSURE_InitTypeDef *LPS25HB_Init);
57 static PRESSURE_StatusTypeDef LPS25HB_ReadID(uint8_t *p_id);
58 static PRESSURE_StatusTypeDef LPS25HB_RebootCmd(void);
59 static PRESSURE_StatusTypeDef LPS25HB_GetPressure(float* pfData);
60 static PRESSURE_StatusTypeDef LPS25HB_GetTemperature(float* pfData);
61 static PRESSURE_StatusTypeDef LPS25HB_PowerOff(void);
62 static void LPS25HB_SlaveAddrRemap(uint8_t SA0_Bit_Status);
63
67 PRESSURE_DrvTypeDef LPS25HBDrv =
68 {
69 LPS25HB_Init,
70 LPS25HB_PowerOff,
71 LPS25HB_ReadID,
72 LPS25HB_RebootCmd,
73 0,
74 0,
75 0,
76 0,
77 0,
78 LPS25HB_GetPressure,
79 LPS25HB_GetTemperature,
80 LPS25HB_SlaveAddrRemap,
81 NULL
82 };
83
84 /* ------------------------------------------------------- */
85 /* Here you should declare the variable that implements */
86 /* the internal struct of extended features of LPS25HB. */
87 /* Then you must update the NULL pointer in the variable */
88 /* of the extended features below. */
89 /* See the example of LSM6DS3 in lsm6ds3.c */
90 /* ------------------------------------------------------- */
91
92
93 uint8_t LPS25HB_SlaveAddress = LPS25HB_ADDRESS_LOW;
94
99 static PRESSURE_StatusTypeDef LPS25HB_PowerOn(void);
100 static PRESSURE_StatusTypeDef LPS25HB_I2C_ReadRawPressure(int32_t *raw_press);
101 static PRESSURE_StatusTypeDef LPS25HB_I2C_ReadRawTemperature(int16_t *raw_data);
102
112 static PRESSURE_StatusTypeDef LPS25HB_Init(PRESSURE_InitTypeDef *LPS25HB_Init)
113 {
114 uint8_t tmp1 = 0x00;
115
116 /* Configure the low level interface ---------------------------------------*/
117 if(LPS25HB_IO_Init() != PRESSURE_OK)
118 {
119 return PRESSURE_ERROR;
120 }
121
122 if(LPS25HB_PowerOn() != PRESSURE_OK)
123 {
124 return PRESSURE_ERROR;
125 }
126
127 if(LPS25HB_IO_Read(&tmp1, LPS25HB_SlaveAddress, LPS25HB_CTRL_REG1_ADDR, 1) != PRESSURE_OK)
128 {
129 return PRESSURE_ERROR;
130 }
131
132 /* Output Data Rate selection */
133 tmp1 &= ~(LPS25HB_ODR_MASK);
134 tmp1 |= LPS25HB_Init->OutputDataRate;
135
136 /* Interrupt circuit selection */
137 tmp1 &= ~(LPS25HB_DIFF_EN_MASK);
138 tmp1 |= LPS25HB_Init->DiffEnable;
139
140 /* Block Data Update selection */
141 tmp1 &= ~(LPS25HB_BDU_MASK);
142 tmp1 |= LPS25HB_Init->BlockDataUpdate;
143
144 /* Serial Interface Mode selection */
145 tmp1 &= ~(LPS25HB_SPI_SIM_MASK);
146 tmp1 |= LPS25HB_Init->SPIMode;
147
148 if(LPS25HB_IO_Write(&tmp1, LPS25HB_SlaveAddress, LPS25HB_CTRL_REG1_ADDR, 1) != PRESSURE_OK)
149 {
150 return PRESSURE_ERROR;
151 }
152
153 if(LPS25HB_IO_Read(&tmp1, LPS25HB_SlaveAddress, LPS25HB_RES_CONF_ADDR, 1) != PRESSURE_OK)
154 {
155 return PRESSURE_ERROR;
156 }
157
158 /* Serial Interface Mode selection */
159 tmp1 &= ~(LPS25HB_P_RES_MASK);
160 tmp1 |= LPS25HB_Init->PressureResolution;
161
162 /* Serial Interface Mode selection */
163 tmp1 &= ~(LPS25HB_T_RES_MASK);
164 tmp1 |= LPS25HB_Init->TemperatureResolution;
165
166 if(LPS25HB_IO_Write(&tmp1, LPS25HB_SlaveAddress, LPS25HB_RES_CONF_ADDR, 1) != PRESSURE_OK)
167 {
168 return PRESSURE_ERROR;
169 }
170
171 LPS25HB_IO_ITConfig();
172
173 return PRESSURE_OK;
174 }
175
181 static PRESSURE_StatusTypeDef LPS25HB_ReadID(uint8_t *p_id)
182 {
183 if(!p_id)
184 {
185 return PRESSURE_ERROR;
186 }
187
188 return LPS25HB_IO_Read(p_id, LPS25HB_SlaveAddress, LPS25HB_WHO_AM_I_ADDR, 1);
189 }
190
196 static PRESSURE_StatusTypeDef LPS25HB_RebootCmd(void)
197 {
198 uint8_t tmpreg;
199
200 /* Read CTRL_REG5 register */
201 if(LPS25HB_IO_Read(&tmpreg, LPS25HB_SlaveAddress, LPS25HB_CTRL_REG2_ADDR, 1) != PRESSURE_OK)
202 {
203 return PRESSURE_ERROR;
204 }
205
206 /* Enable or Disable the reboot memory */
207 tmpreg |= LPS25HB_RESET_MEMORY;
208
209 /* Write value to MEMS CTRL_REG5 regsister */
210 if(LPS25HB_IO_Write(&tmpreg, LPS25HB_SlaveAddress, LPS25HB_CTRL_REG2_ADDR, 1) != PRESSURE_OK)
211 {
212 return PRESSURE_ERROR;
213 }
214
215 return PRESSURE_OK;
216 }
217
218
224 static PRESSURE_StatusTypeDef LPS25HB_I2C_ReadRawPressure(int32_t *raw_press)
225 {
226 uint8_t buffer[3], i;
227 uint32_t tempVal=0;
228
229 /* Read the register content */
230
231 if(LPS25HB_IO_Read(buffer, LPS25HB_SlaveAddress, (LPS25HB_PRESS_POUT_XL_ADDR | LPS25HB_I2C_MULTIPLEBYTE_CMD), 3) != PRESSURE_OK)
232 {
233 return PRESSURE_ERROR;
234 }
235
236 /* Build the raw data */
237 for (i = 0 ; i < 3 ; i++)
238 tempVal |= (((uint32_t) buffer[i]) << (8 * i));
239
240 /* convert the 2's complement 24 bit to 2's complement 32 bit */
241 if (tempVal & 0x00800000)
242 tempVal |= 0xFF000000;
243
244 /* return the built value */
245 *raw_press = ((int32_t) tempVal);
246
247 return PRESSURE_OK;
248 }
249
255 static PRESSURE_StatusTypeDef LPS25HB_GetPressure(float* pfData)
256 {
257 int32_t raw_press = 0;
258
259 if(LPS25HB_I2C_ReadRawPressure(&raw_press) != PRESSURE_OK)
260 {
261 return PRESSURE_ERROR;
262 }
263
264 *pfData = (float)raw_press /4096.0f;
265
266 return PRESSURE_OK;
267 }
268
274 static PRESSURE_StatusTypeDef LPS25HB_I2C_ReadRawTemperature(int16_t *raw_data)
275 {
276 uint8_t buffer[2];
277 uint16_t tempVal=0;
278
279 /* Read the register content */
280 if(LPS25HB_IO_Read(buffer, LPS25HB_SlaveAddress, (LPS25HB_TEMP_OUT_L_ADDR | LPS25HB_I2C_MULTIPLEBYTE_CMD), 2) != PRESSURE_OK)
281 {
282 return PRESSURE_ERROR;
283 }
284
285 /* Build the raw value */
286 tempVal = (((uint16_t)buffer[1]) << 8)+(uint16_t)buffer[0];
287
288 /* Return it */
289 *raw_data = ((int16_t)tempVal);
290
291 return PRESSURE_OK;
292 }
293
299 static PRESSURE_StatusTypeDef LPS25HB_GetTemperature(float *pfData)
300 {
301 int16_t raw_data;
302
303 if(LPS25HB_I2C_ReadRawTemperature(&raw_data) != PRESSURE_OK)
304 {
305 return PRESSURE_ERROR;
306 }
307
308 *pfData = (float)((((float)raw_data/480.0f) + 42.5f));
309
310 return PRESSURE_OK;
311 }
317 static PRESSURE_StatusTypeDef LPS25HB_PowerOn(void)
318 {
319 uint8_t tmpreg;
320
321 /* Read the register content */
322 if(LPS25HB_IO_Read(&tmpreg, LPS25HB_SlaveAddress, LPS25HB_CTRL_REG1_ADDR, 1) != PRESSURE_OK)
323 {
324 return PRESSURE_ERROR;
325 }
326
327 /* Set the power down bit */
328 tmpreg |= LPS25HB_MODE_ACTIVE;
329
330 /* Write register */
331 if(LPS25HB_IO_Write(&tmpreg, LPS25HB_SlaveAddress, LPS25HB_CTRL_REG1_ADDR, 1) != PRESSURE_OK)
332 {
333 return PRESSURE_ERROR;
334 }
335
336 return PRESSURE_OK;
337 }
338
339
345 static PRESSURE_StatusTypeDef LPS25HB_PowerOff(void)
346 {
347 uint8_t tmpreg;
348
349 /* Read the register content */
350 if(LPS25HB_IO_Read(&tmpreg, LPS25HB_SlaveAddress, LPS25HB_CTRL_REG1_ADDR, 1) != PRESSURE_OK)
351 {
352 return PRESSURE_ERROR;
353 }
354
355 /* Reset the power down bit */
356 tmpreg &= ~(LPS25HB_MODE_ACTIVE);
357
358 /* Write register */
359 if(LPS25HB_IO_Write(&tmpreg, LPS25HB_SlaveAddress, LPS25HB_CTRL_REG1_ADDR, 1) != PRESSURE_OK)
360 {
361 return PRESSURE_ERROR;
362 }
363
364 return PRESSURE_OK;
365 }
366
372 static void LPS25HB_SlaveAddrRemap(uint8_t SA0_Bit_Status)
373 {
374 LPS25HB_SlaveAddress = (SA0_Bit_Status==LPS25HB_SA0_LOW?LPS25HB_ADDRESS_LOW:LPS25HB_ADDRESS_HIGH);
375 }
376
396 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
LPS25HB_SA0_LOW
#define LPS25HB_SA0_LOW
Definition: LPS25HB.h:519
PRESSURE_ERROR
Definition: LPS25HB.h:548
LPS25HB_ADDRESS_HIGH
#define LPS25HB_ADDRESS_HIGH
Definition: LPS25HB.h:416
LPS25HB_RESET_MEMORY
#define LPS25HB_RESET_MEMORY
Definition: LPS25HB.h:486
PRESSURE_InitTypeDef::BlockDataUpdate
uint8_t BlockDataUpdate
Definition: LPS25HB.h:539
PRESSURE_InitTypeDef::OutputDataRate
uint8_t OutputDataRate
Definition: LPS25HB.h:535
LPS25HB_BDU_MASK
#define LPS25HB_BDU_MASK
Definition: LPS25HB.h:466
NULL
#define NULL
Definition: LPS25HB.h:68
LPS25HB_IO_Init
PRESSURE_StatusTypeDef LPS25HB_IO_Init(void)
LPS25HB_IO_ITConfig
PRESSURE_StatusTypeDef LPS25HB_IO_ITConfig(void)
LPS25HB_ADDRESS_LOW
#define LPS25HB_ADDRESS_LOW
Device Address.
Definition: LPS25HB.h:415
PRESSURE_InitTypeDef
PRESSURE init structure definition.
Definition: LPS25HB.h:533
LPS25HB_WHO_AM_I_ADDR
#define LPS25HB_WHO_AM_I_ADDR
Device identifier register.
Definition: LPS25HB.h:119
LPS25HB_SlaveAddress
uint8_t LPS25HB_SlaveAddress
Definition: LPS25HB.c:93
PRESSURE_DrvTypeDef
PRESSURE driver structure definition.
Definition: LPS25HB.h:573
LPS25HB_DIFF_EN_MASK
#define LPS25HB_DIFF_EN_MASK
Definition: LPS25HB.h:455
PRESSURE_OK
Definition: LPS25HB.h:547
LPS25HB_CTRL_REG2_ADDR
#define LPS25HB_CTRL_REG2_ADDR
Pressure sensor control register 2.
Definition: LPS25HB.h:174
LPS25HB_TEMP_OUT_L_ADDR
#define LPS25HB_TEMP_OUT_L_ADDR
Temperature data (LSB).
Definition: LPS25HB.h:325
LPS25HB.h
This file contains definitions for the lps25hb.c firmware driver.
PRESSURE_InitTypeDef::DiffEnable
uint8_t DiffEnable
Definition: LPS25HB.h:538
LPS25HB_ODR_MASK
#define LPS25HB_ODR_MASK
Definition: LPS25HB.h:444
PRESSURE_StatusTypeDef
PRESSURE_StatusTypeDef
PRESSURE status enumerator definition.
Definition: LPS25HB.h:546
PRESSURE_InitTypeDef::TemperatureResolution
uint8_t TemperatureResolution
Definition: LPS25HB.h:537
LPS25HB_hal.h
This file provides all the low level API to manage LPS25HB pressure sensor of eval board...
LPS25HBDrv
PRESSURE_DrvTypeDef LPS25HBDrv
Definition: LPS25HB.c:67
LPS25HB_SPI_SIM_MASK
#define LPS25HB_SPI_SIM_MASK
Definition: LPS25HB.h:477
LPS25HB_IO_Read
PRESSURE_StatusTypeDef LPS25HB_IO_Read(uint8_t *pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead)
LPS25HB_MODE_ACTIVE
#define LPS25HB_MODE_ACTIVE
Definition: LPS25HB.h:428
LPS25HB_PRESS_POUT_XL_ADDR
#define LPS25HB_PRESS_POUT_XL_ADDR
Pressure data (LSB).
Definition: LPS25HB.h:290
LPS25HB_CTRL_REG1_ADDR
#define LPS25HB_CTRL_REG1_ADDR
Pressure sensor control register 1.
Definition: LPS25HB.h:158
LPS25HB_T_RES_MASK
#define LPS25HB_T_RES_MASK
Definition: LPS25HB.h:514
PRESSURE_InitTypeDef::SPIMode
uint8_t SPIMode
Definition: LPS25HB.h:540
LPS25HB_P_RES_MASK
#define LPS25HB_P_RES_MASK
Definition: LPS25HB.h:501
PRESSURE_InitTypeDef::PressureResolution
uint8_t PressureResolution
Definition: LPS25HB.h:536
LPS25HB_I2C_MULTIPLEBYTE_CMD
#define LPS25HB_I2C_MULTIPLEBYTE_CMD
Multiple Byte. Mask for enabling multiple byte read/write command.
Definition: LPS25HB.h:408
LPS25HB_IO_Write
PRESSURE_StatusTypeDef LPS25HB_IO_Write(uint8_t *pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToWrite)
LPS25HB_RES_CONF_ADDR
#define LPS25HB_RES_CONF_ADDR
Pressure and temperature resolution mode register.
Definition: LPS25HB.h:131