BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sht21.h
Go to the documentation of this file.
1 /* Copyright 2013-2014, Peter A. Bigot
2  *
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the software nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef BSP430_SENSORS_SHT21_H
33 #define BSP430_SENSORS_SHT21_H
34 
70 #include <bsp430/serial.h>
71 #include <bsp430/periph/timer.h>
72 
75 #define BSP430_SENSORS_SHT21_I2C_ADDRESS 0x40
76 
79 #define BSP430_SENSORS_SHT21_RESET_DELAY_MS 15
80 
84 #define BSP430_SENSORS_SHT21_CONFIG_H12T14 0x00
85 
89 #define BSP430_SENSORS_SHT21_CONFIG_H8T12 0x01
90 
94 #define BSP430_SENSORS_SHT21_CONFIG_H10T13 0x80
95 
99 #define BSP430_SENSORS_SHT21_CONFIG_H11T11 0x81
100 
103 #define BSP430_SENSORS_SHT21_CONFIG_RESOLUTION_MASK 0x81
104 
107 #define BSP430_SENSORS_SHT21_CONFIG_EOB_MASK 0x40
108 
111 #define BSP430_SENSORS_SHT21_CONFIG_HEATER_MASK 0x04
112 
114 #define BSP430_SENSORS_SHT21_EIC_LENGTH 8
115 
117 #define BSP430_SENSORS_SHT21_EIC_IS_SHT21(eic_) ((0x00 == (eic_)[0]) && (0x80 == (eic_)[1]))
118 
120 #define BSP430_SENSORS_SHT21_EIC_IS_HTU21D(eic_) ((0x48 == (eic_)[0]) && (0x54 == (eic_)[1]))
121 
124 /* RH_pph = -6 + 125 * S / 2^16 */
125 #define BSP430_SENSORS_SHT21_HUMIDITY_RAW_TO_ppth(raw_) (unsigned int)(((1250UL * (raw_)) >> 16) - 60)
126 
129 /* T_dC = -46.85 + 175.72 * S / 2^16
130  * T_cK = 27315 - 4685 + 17572 * S / 2^16
131  * = 22630 + 17572 * S / 2^16
132  */
133 #define BSP430_SENSORS_SHT21_TEMPERATURE_RAW_TO_cK(raw_) (22630U + (unsigned int)((17572UL * (raw_)) >> 16))
134 
137 #define BSP430_SENSORS_SHT21_TEMPERATURE_RAW_TO_dK(raw_) ((unsigned int)((5 + BSP430_SENSORS_SHT21_TEMPERATURE_RAW_TO_cK(raw_)) / 10))
138 
139 #ifndef BSP430_SENSORS_SHT21_IS_HTU21D
140 
152 #define BSP430_SENSORS_SHT21_IS_HTU21D 1
153 #endif /* BSP430_SENSORS_SHT21_IS_HTU21D */
154 
158  unsigned int temperature_raw;
159 
161  unsigned int humidity_raw;
162 
167 
173 
176 
190 int iBSP430sensorsSHT21crc (const uint8_t * data,
191  int len);
192 
209  uint8_t * eic);
210 
245  int resolution,
246  int heater);
247 
260 
268 
284  int hold_master,
286 
308  int hold_master,
309  uint16_t * rawp);
310 
325 
326 #endif /* BSP430_SENSORS_SHT21_H */
int iBSP430sensorsSHT21getMeasurement(hBSP430halSERIAL i2c, int hold_master, uint16_t *rawp)
unsigned int temperature_raw
Definition: sht21.h:158
struct sBSP430sensorsSHT21sample sBSP430sensorsSHT21sample
eBSP430sensorsSHT21measurement
Definition: sht21.h:264
unsigned int humidity_raw
Definition: sht21.h:161
int iBSP430sensorsSHT21configuration(hBSP430halSERIAL i2c, int resolution, int heater)
int iBSP430sensorsSHT21eic(hBSP430halSERIAL i2c, uint8_t *eic)
int iBSP430sensorsSHT21getSample(hBSP430halSERIAL i2c, hBSP430sensorsSHT21sample sample)
Definition: serial_.h:193
Hardware presentation/abstraction for generic timers (Timer_A/Timer_B)
int humidity_ppth
Definition: sht21.h:171
int temperature_dK
Definition: sht21.h:166
Declarations for abstracted serial interface.
int iBSP430sensorsSHT21initiateMeasurement(hBSP430halSERIAL i2c, int hold_master, eBSP430sensorsSHT21measurement type)
sBSP430sensorsSHT21sample * hBSP430sensorsSHT21sample
Definition: sht21.h:175
Definition: sht21.h:156
int iBSP430sensorsSHT21reset(hBSP430halSERIAL i2c)
int iBSP430sensorsSHT21crc(const uint8_t *data, int len)