HTS221
Arduino library for the HTS221 humidity and temperature sensor
Loading...
Searching...
No Matches
HTS221_Driver.h
Go to the documentation of this file.
1
38/* Define to prevent recursive inclusion -------------------------------------*/
39#ifndef __HTS221_DRIVER__H
40#define __HTS221_DRIVER__H
41
42#include <stdint.h>
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48/* Uncomment the line below to expanse the "assert_param" macro in the drivers code */
49#define USE_FULL_ASSERT_HTS221
50
51/* Exported macro ------------------------------------------------------------*/
52#ifdef USE_FULL_ASSERT_HTS221
53
61#define HTS221_assert_param(expr) ((expr) ? (void)0 : HTS221_assert_failed((uint8_t *)__FILE__, __LINE__))
62/* Exported functions ------------------------------------------------------- */
63void HTS221_assert_failed(uint8_t* file, uint32_t line);
64#else
65#define HTS221_assert_param(expr) ((void)0)
66#endif /* USE_FULL_ASSERT_HTS221 */
67
76/* Exported Types -------------------------------------------------------------*/
85typedef enum {HTS221_OK = (uint8_t)0, HTS221_ERROR = !HTS221_OK} HTS221_Error_et;
86
91#define IS_HTS221_State(MODE) ((MODE == HTS221_ENABLE) || (MODE == HTS221_DISABLE))
92
97#define IS_HTS221_BitStatus(MODE) ((MODE == HTS221_RESET) || (MODE == HTS221_SET))
98
102typedef enum
103{
104 HTS221_AVGH_4 = (uint8_t)0x00,
105 HTS221_AVGH_8 = (uint8_t)0x01,
106 HTS221_AVGH_16 = (uint8_t)0x02,
107 HTS221_AVGH_32 = (uint8_t)0x03,
108 HTS221_AVGH_64 = (uint8_t)0x04,
109 HTS221_AVGH_128 = (uint8_t)0x05,
110 HTS221_AVGH_256 = (uint8_t)0x06,
111 HTS221_AVGH_512 = (uint8_t)0x07
113#define IS_HTS221_AVGH(AVGH) ((AVGH == HTS221_AVGH_4) || (AVGH == HTS221_AVGH_8) || \
114 (AVGH == HTS221_AVGH_16) || (AVGH == HTS221_AVGH_32) || \
115 (AVGH == HTS221_AVGH_64) || (AVGH == HTS221_AVGH_128) || \
116 (AVGH == HTS221_AVGH_256) || (AVGH == HTS221_AVGH_512))
117
121typedef enum
122{
123 HTS221_AVGT_2 = (uint8_t)0x00,
124 HTS221_AVGT_4 = (uint8_t)0x08,
125 HTS221_AVGT_8 = (uint8_t)0x10,
126 HTS221_AVGT_16 = (uint8_t)0x18,
127 HTS221_AVGT_32 = (uint8_t)0x20,
128 HTS221_AVGT_64 = (uint8_t)0x28,
129 HTS221_AVGT_128 = (uint8_t)0x30,
130 HTS221_AVGT_256 = (uint8_t)0x38
132#define IS_HTS221_AVGT(AVGT) ((AVGT == HTS221_AVGT_2) || (AVGT == HTS221_AVGT_4) || \
133 (AVGT == HTS221_AVGT_8) || (AVGT == HTS221_AVGT_16) || \
134 (AVGT == HTS221_AVGT_32) || (AVGT == HTS221_AVGT_64) || \
135 (AVGT == HTS221_AVGT_128) || (AVGT == HTS221_AVGT_256))
136
140typedef enum
141{
142 HTS221_ODR_ONE_SHOT = (uint8_t)0x00,
143 HTS221_ODR_1HZ = (uint8_t)0x01,
144 HTS221_ODR_7HZ = (uint8_t)0x02,
145 HTS221_ODR_12_5HZ = (uint8_t)0x03,
147#define IS_HTS221_ODR(ODR) ((ODR == HTS221_ODR_ONE_SHOT) || (ODR == HTS221_ODR_1HZ) || \
148 (ODR == HTS221_ODR_7HZ) || (ODR == HTS221_ODR_12_5HZ))
149
150
154typedef enum
155{
156 HTS221_PUSHPULL = (uint8_t)0x00,
157 HTS221_OPENDRAIN = (uint8_t)0x40
159#define IS_HTS221_OutputType(MODE) ((MODE == HTS221_PUSHPULL) || (MODE == HTS221_OPENDRAIN))
160
164typedef enum
165{
166 HTS221_HIGH_LVL = (uint8_t)0x00,
167 HTS221_LOW_LVL = (uint8_t)0x80
169#define IS_HTS221_DrdyLevelType(MODE) ((MODE == HTS221_HIGH_LVL) || (MODE == HTS221_LOW_LVL))
170
174typedef struct
175{
176 uint8_t Major;
177 uint8_t Minor;
178 uint8_t Point;
180
181
197
203/* Exported Constants ---------------------------------------------------------*/
211#define HTS221_BIT(x) ((uint8_t)x)
212
216#define HTS221_I2C_ADDRESS (uint8_t)0xBE
217
221#define HTS221_DRIVER_VERSION_MAJOR (uint8_t)1
222#define HTS221_DRIVER_VERSION_MINOR (uint8_t)1
223#define HTS221_DRIVER_VERSION_POINT (uint8_t)0
224
239#define HTS221_WHO_AM_I_REG (uint8_t)0x0F
240
244#define HTS221_WHO_AM_I_VAL (uint8_t)0xBC
245
246
280#define HTS221_AV_CONF_REG (uint8_t)0x10
281
282#define HTS221_AVGT_BIT HTS221_BIT(3)
283#define HTS221_AVGH_BIT HTS221_BIT(0)
284
285#define HTS221_AVGH_MASK (uint8_t)0x07
286#define HTS221_AVGT_MASK (uint8_t)0x38
287
307#define HTS221_CTRL_REG1 (uint8_t)0x20
308
309#define HTS221_PD_BIT HTS221_BIT(7)
310#define HTS221_BDU_BIT HTS221_BIT(2)
311#define HTS221_ODR_BIT HTS221_BIT(0)
312
313#define HTS221_PD_MASK (uint8_t)0x80
314#define HTS221_BDU_MASK (uint8_t)0x04
315#define HTS221_ODR_MASK (uint8_t)0x03
316
328#define HTS221_CTRL_REG2 (uint8_t)0x21
329
330#define HTS221_BOOT_BIT HTS221_BIT(7)
331#define HTS221_HEATER_BIT HTS221_BIT(1)
332#define HTS221_ONESHOT_BIT HTS221_BIT(0)
333
334#define HTS221_BOOT_MASK (uint8_t)0x80
335#define HTS221_HEATER_MASK (uint8_t)0x02
336#define HTS221_ONE_SHOT_MASK (uint8_t)0x01
337
349#define HTS221_CTRL_REG3 (uint8_t)0x22
350
351#define HTS221_DRDY_H_L_BIT HTS221_BIT(7)
352#define HTS221_PP_OD_BIT HTS221_BIT(6)
353#define HTS221_DRDY_BIT HTS221_BIT(2)
354
355#define HTS221_DRDY_H_L_MASK (uint8_t)0x80
356#define HTS221_PP_OD_MASK (uint8_t)0x40
357#define HTS221_DRDY_MASK (uint8_t)0x04
358
369#define HTS221_STATUS_REG (uint8_t)0x27
370
371#define HTS221_H_DA_BIT HTS221_BIT(1)
372#define HTS221_T_DA_BIT HTS221_BIT(0)
373
374#define HTS221_HDA_MASK (uint8_t)0x02
375#define HTS221_TDA_MASK (uint8_t)0x01
376
385#define HTS221_HR_OUT_L_REG (uint8_t)0x28
386
395#define HTS221_HR_OUT_H_REG (uint8_t)0x29
396
397
406#define HTS221_TEMP_OUT_L_REG (uint8_t)0x2A
407
416#define HTS221_TEMP_OUT_H_REG (uint8_t)0x2B
417
424#define HTS221_H0_RH_X2 (uint8_t)0x30
425#define HTS221_H1_RH_X2 (uint8_t)0x31
426#define HTS221_T0_DEGC_X8 (uint8_t)0x32
427#define HTS221_T1_DEGC_X8 (uint8_t)0x33
428#define HTS221_T0_T1_DEGC_H2 (uint8_t)0x35
429#define HTS221_H0_T0_OUT_L (uint8_t)0x36
430#define HTS221_H0_T0_OUT_H (uint8_t)0x37
431#define HTS221_H1_T0_OUT_L (uint8_t)0x3A
432#define HTS221_H1_T0_OUT_H (uint8_t)0x3B
433#define HTS221_T0_OUT_L (uint8_t)0x3C
434#define HTS221_T0_OUT_H (uint8_t)0x3D
435#define HTS221_T1_OUT_L (uint8_t)0x3E
436#define HTS221_T1_OUT_H (uint8_t)0x3F
437
438
449/* Exported Functions -------------------------------------------------------------*/
454HTS221_Error_et HTS221_ReadReg( void *handle, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t *Data );
455HTS221_Error_et HTS221_WriteReg( void *handle, uint8_t RegAddr, uint16_t NumByteToWrite, uint8_t *Data );
456
458HTS221_Error_et HTS221_Get_DeviceID(void *handle, uint8_t* deviceid);
459
462HTS221_Error_et HTS221_DeInit(void *handle);
463HTS221_Error_et HTS221_IsMeasurementCompleted(void *handle, HTS221_BitStatus_et* Is_Measurement_Completed);
464
465HTS221_Error_et HTS221_Get_Measurement(void *handle, uint16_t* humidity, int16_t* temperature);
466HTS221_Error_et HTS221_Get_RawMeasurement(void *handle, int16_t* humidity, int16_t* temperature);
467HTS221_Error_et HTS221_Get_Humidity(void *handle, uint16_t* value);
468HTS221_Error_et HTS221_Get_HumidityRaw(void *handle, int16_t* value);
469HTS221_Error_et HTS221_Get_TemperatureRaw(void *handle, int16_t* value);
470HTS221_Error_et HTS221_Get_Temperature(void *handle, int16_t* value);
472HTS221_Error_et HTS221_Activate(void *handle);
474
495
508#ifdef __cplusplus
509}
510#endif
511
512#endif /* __HTS221_DRIVER__H */
513
514/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
HTS221_Error_et HTS221_Get_Measurement(void *handle, uint16_t *humidity, int16_t *temperature)
Read HTS221 output registers, and calculate humidity and temperature.
Definition HTS221_Driver.c:276
HTS221_Error_et HTS221_Set_IrqActiveLevel(void *handle, HTS221_DrdyLevel_et status)
Set level configuration of the interrupt pin DRDY.
Definition HTS221_Driver.c:824
HTS221_Error_et HTS221_MemoryBoot(void *handle)
Reboot Memory Content.
Definition HTS221_Driver.c:737
HTS221_Error_et HTS221_Set_Odr(void *handle, HTS221_Odr_et odr)
Set the output data rate mode.
Definition HTS221_Driver.c:695
HTS221_Error_et HTS221_StartOneShotMeasurement(void *handle)
Set ONE_SHOT bit to start a new conversion (ODR mode has to be 00). Once the measurement is done,...
Definition HTS221_Driver.c:801
HTS221_Error_et HTS221_Get_HumidityRaw(void *handle, int16_t *value)
Read HTS221 humidity output registers.
Definition HTS221_Driver.c:350
HTS221_Error_et HTS221_Get_Temperature(void *handle, int16_t *value)
Read the temperature output and convert it using the factory calibration.
Definition HTS221_Driver.c:368
HTS221_Error_et HTS221_Activate(void *handle)
Exit from power down mode.
Definition HTS221_Driver.c:448
HTS221_Error_et HTS221_Get_IrqEnable(void *handle, HTS221_State_et *status)
Get the interrupt mode.
Definition HTS221_Driver.c:934
HTS221_Error_et HTS221_Set_HeaterState(void *handle, HTS221_State_et status)
Configure the internal heater.
Definition HTS221_Driver.c:759
HTS221_Error_et HTS221_Set_BduMode(void *handle, HTS221_State_et status)
Set block data update mode.
Definition HTS221_Driver.c:609
HTS221_Error_et HTS221_Get_DeviceID(void *handle, uint8_t *deviceid)
Get device type ID.
Definition HTS221_Driver.c:149
HTS221_Error_et HTS221_Get_DriverVersion(HTS221_DriverVersion_st *version)
Get the version of this driver.
Definition HTS221_Driver.c:134
HTS221_Error_et HTS221_Get_IrqOutputType(void *handle, HTS221_OutputType_et *value)
Get the configuration for the interrupt pin DRDY.
Definition HTS221_Driver.c:891
HTS221_Error_et HTS221_DeActivate(void *handle)
Put the sensor in power down mode.
Definition HTS221_Driver.c:468
HTS221_Error_et HTS221_Set_AvgHT(void *handle, HTS221_Avgh_et avgh, HTS221_Avgt_et avgt)
Set_ humidity and temperature average mode.
Definition HTS221_Driver.c:514
HTS221_Error_et HTS221_Get_PowerDownMode(void *handle, HTS221_BitStatus_et *status)
Get if HTS221 is in active mode or in power down mode.
Definition HTS221_Driver.c:676
HTS221_Error_et HTS221_WriteReg(void *handle, uint8_t RegAddr, uint16_t NumByteToWrite, uint8_t *Data)
Definition HTS221_Driver.c:117
HTS221_Error_et HTS221_DeInit(void *handle)
De initialization function for HTS221. This function put the HTS221 in power down,...
Definition HTS221_Driver.c:246
HTS221_Error_et HTS221_Get_BduMode(void *handle, HTS221_State_et *status)
Get block data update mode.
Definition HTS221_Driver.c:633
HTS221_Error_et HTS221_Get_TemperatureRaw(void *handle, int16_t *value)
Read HTS221 temperature output registers.
Definition HTS221_Driver.c:410
HTS221_Error_et HTS221_Get_InitConfig(void *handle, HTS221_Init_st *pxInit)
Returns a HTS221_Init_st struct with the actual configuration.
Definition HTS221_Driver.c:216
HTS221_Error_et HTS221_Get_RawMeasurement(void *handle, int16_t *humidity, int16_t *temperature)
Read HTS221 output registers. Humidity and temperature.
Definition HTS221_Driver.c:291
HTS221_Error_et HTS221_Get_Odr(void *handle, HTS221_Odr_et *odr)
Get the output data rate mode.
Definition HTS221_Driver.c:719
HTS221_Error_et HTS221_Set_AvgH(void *handle, HTS221_Avgh_et avgh)
Set humidity average mode.
Definition HTS221_Driver.c:540
HTS221_Error_et HTS221_Get_AvgHT(void *handle, HTS221_Avgh_et *avgh, HTS221_Avgt_et *avgt)
Get humidity and temperature average mode.
Definition HTS221_Driver.c:589
HTS221_Error_et HTS221_IsMeasurementCompleted(void *handle, HTS221_BitStatus_et *Is_Measurement_Completed)
Check if the single measurement has completed.
Definition HTS221_Driver.c:491
HTS221_Error_et HTS221_Get_HeaterState(void *handle, HTS221_State_et *status)
Get the internal heater.
Definition HTS221_Driver.c:783
HTS221_Error_et HTS221_Get_Humidity(void *handle, uint16_t *value)
Read the humidity output and convert it using the factory calibration.
Definition HTS221_Driver.c:310
HTS221_Error_et HTS221_ReadReg(void *handle, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t *Data)
Definition HTS221_Driver.c:98
HTS221_Error_et HTS221_Get_DataStatus(void *handle, HTS221_BitStatus_et *humidity, HTS221_BitStatus_et *temperature)
Get the availability of new data for humidity and temperature.
Definition HTS221_Driver.c:430
HTS221_Error_et HTS221_Set_AvgT(void *handle, HTS221_Avgt_et avgt)
Set temperature average mode.
Definition HTS221_Driver.c:564
HTS221_Error_et HTS221_Set_IrqOutputType(void *handle, HTS221_OutputType_et value)
Set Push-pull/open drain configuration for the interrupt pin DRDY.
Definition HTS221_Driver.c:867
HTS221_Error_et HTS221_Set_PowerDownMode(void *handle, HTS221_BitStatus_et status)
Enter or exit from power down mode.
Definition HTS221_Driver.c:652
HTS221_Error_et HTS221_Get_IrqActiveLevel(void *handle, HTS221_DrdyLevel_et *status)
Get level configuration of the interrupt pin DRDY.
Definition HTS221_Driver.c:848
HTS221_Error_et HTS221_Set_IrqEnable(void *handle, HTS221_State_et status)
Enable/disable the interrupt mode.
Definition HTS221_Driver.c:910
HTS221_Error_et HTS221_Set_InitConfig(void *handle, HTS221_Init_st *pxInit)
Initializes the HTS221 with the specified parameters in HTS221_Init_st struct.
Definition HTS221_Driver.c:164
HTS221_BitStatus_et
Bit status type.
Definition HTS221_Driver.h:96
HTS221_State_et
State type.
Definition HTS221_Driver.h:90
HTS221_Odr_et
Output data rate configuration.
Definition HTS221_Driver.h:141
HTS221_OutputType_et
Push-pull/Open Drain selection on DRDY pin.
Definition HTS221_Driver.h:155
HTS221_Error_et
Error code type.
Definition HTS221_Driver.h:85
HTS221_Avgh_et
Humidity average.
Definition HTS221_Driver.h:103
HTS221_Avgt_et
Temperature average.
Definition HTS221_Driver.h:122
HTS221_DrdyLevel_et
Active level of DRDY pin.
Definition HTS221_Driver.h:165
@ HTS221_SET
Definition HTS221_Driver.h:96
@ HTS221_RESET
Definition HTS221_Driver.h:96
@ HTS221_DISABLE
Definition HTS221_Driver.h:90
@ HTS221_ENABLE
Definition HTS221_Driver.h:90
@ HTS221_ODR_ONE_SHOT
Definition HTS221_Driver.h:142
@ HTS221_ODR_1HZ
Definition HTS221_Driver.h:143
@ HTS221_ODR_12_5HZ
Definition HTS221_Driver.h:145
@ HTS221_ODR_7HZ
Definition HTS221_Driver.h:144
@ HTS221_PUSHPULL
Definition HTS221_Driver.h:156
@ HTS221_OPENDRAIN
Definition HTS221_Driver.h:157
@ HTS221_OK
Definition HTS221_Driver.h:85
@ HTS221_ERROR
Definition HTS221_Driver.h:85
@ HTS221_AVGH_16
Definition HTS221_Driver.h:106
@ HTS221_AVGH_64
Definition HTS221_Driver.h:108
@ HTS221_AVGH_32
Definition HTS221_Driver.h:107
@ HTS221_AVGH_256
Definition HTS221_Driver.h:110
@ HTS221_AVGH_8
Definition HTS221_Driver.h:105
@ HTS221_AVGH_128
Definition HTS221_Driver.h:109
@ HTS221_AVGH_4
Definition HTS221_Driver.h:104
@ HTS221_AVGH_512
Definition HTS221_Driver.h:111
@ HTS221_AVGT_8
Definition HTS221_Driver.h:125
@ HTS221_AVGT_64
Definition HTS221_Driver.h:128
@ HTS221_AVGT_16
Definition HTS221_Driver.h:126
@ HTS221_AVGT_2
Definition HTS221_Driver.h:123
@ HTS221_AVGT_128
Definition HTS221_Driver.h:129
@ HTS221_AVGT_32
Definition HTS221_Driver.h:127
@ HTS221_AVGT_4
Definition HTS221_Driver.h:124
@ HTS221_AVGT_256
Definition HTS221_Driver.h:130
@ HTS221_LOW_LVL
Definition HTS221_Driver.h:167
@ HTS221_HIGH_LVL
Definition HTS221_Driver.h:166
void HTS221_assert_failed(uint8_t *file, uint32_t line)
Reports the name of the source file and the source line number where the assert_param error has occur...
Definition HTS221_Driver.c:954
Driver Version Info structure definition.
Definition HTS221_Driver.h:175
uint8_t Major
Definition HTS221_Driver.h:176
uint8_t Minor
Definition HTS221_Driver.h:177
uint8_t Point
Definition HTS221_Driver.h:178
HTS221 Init structure definition.
Definition HTS221_Driver.h:186
HTS221_DrdyLevel_et irq_level
Definition HTS221_Driver.h:193
HTS221_Avgh_et avg_h
Definition HTS221_Driver.h:187
HTS221_Odr_et odr
Definition HTS221_Driver.h:189
HTS221_State_et heater_status
Definition HTS221_Driver.h:191
HTS221_State_et bdu_status
Definition HTS221_Driver.h:190
HTS221_Avgt_et avg_t
Definition HTS221_Driver.h:188
HTS221_OutputType_et irq_output_type
Definition HTS221_Driver.h:194
HTS221_State_et irq_enable
Definition HTS221_Driver.h:195