e734a9e2e40f3a57f2fb92cd6035528572b97eea
[owSlave2.git] / common / I2C / SHT2x.h
1 #ifndef SHT2x_H
2 #define SHT2x_H
3 //==============================================================================
4 // S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland
5 //==============================================================================
6 // Project : SHT2x Sample Code (V1.2)
7 // File : SHT2x.h
8 // Author : MST
9 // Controller: NEC V850/SG3 (uPD70F3740)
10 // Compiler : IAR compiler for V850 (3.50A)
11 // Brief : Sensor layer. Definitions of commands and registers,
12 // functions for sensor access
13 //==============================================================================
14
15
16 //---------- Defines -----------------------------------------------------------
17 // CRC
18 #define CHECKSUM_ERROR 1
19 #define TIME_OUT_ERROR 2
20 #define ACK_ERROR 4
21
22
23 // sensor command
24 typedef enum{
25         TRIG_T_MEASUREMENT_HM = 0xE3, // command trig. temp meas. hold master
26         TRIG_RH_MEASUREMENT_HM = 0xE5, // command trig. humidity meas. hold master
27         TRIG_T_MEASUREMENT_POLL = 0xF3, // command trig. temp meas. no hold master
28         TRIG_RH_MEASUREMENT_POLL = 0xF5, // command trig. humidity meas. no hold master
29         USER_REG_W = 0xE6, // command writing user register
30         USER_REG_R = 0xE7, // command reading user register
31         SOFT_RESET = 0xFE // command soft reset
32 }etSHT2xCommand;
33 typedef enum {
34         SHT2x_RES_12_14BIT = 0x00, // RH=12bit, T=14bit
35         SHT2x_RES_8_12BIT = 0x01, // RH= 8bit, T=12bit
36         SHT2x_RES_10_13BIT = 0x80, // RH=10bit, T=13bit
37         SHT2x_RES_11_11BIT = 0x81, // RH=11bit, T=11bit
38         SHT2x_RES_MASK = 0x81 // Mask for res. bits (7,0) in user reg.
39 } etSHT2xResolution;
40 typedef enum {
41         SHT2x_EOB_ON = 0x40, // end of battery
42         SHT2x_EOB_MASK = 0x40, // Mask for EOB bit(6) in user reg.
43 } etSHT2xEob;
44 typedef enum {
45         SHT2x_HEATER_ON = 0x04, // heater on
46         SHT2x_HEATER_OFF = 0x00, // heater off
47         SHT2x_HEATER_MASK = 0x04, // Mask for Heater bit(2) in user reg.
48 } etSHT2xHeater;
49 // measurement signal selection
50 typedef enum{
51         HUMIDITY,
52         TEMP
53 }etSHT2xMeasureType;
54 typedef enum{
55         I2C_ADR_W = 128, // sensor I2C address + write bit
56         I2C_ADR_R = 129 // sensor I2C address + read bit
57 }etI2cHeader;
58 //==============================================================================
59 uint8_t SHT2x_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum);
60 //==============================================================================
61 // calculates checksum for n bytes of data and compares it with expected
62 // checksum
63 // input: data[] checksum is built based on this data
64 // nbrOfBytes checksum is built for n bytes of data
65 // checksum expected checksum
66 // return: error: CHECKSUM_ERROR = checksum does not match
67 // 0 = checksum matches
68 //==============================================================================
69 uint8_t SHT2x_ReadUserRegister(uint8_t *pRegisterValue);
70 //==============================================================================
71 // reads the SHT2x user register (8bit)
72 // input : -
73 // output: *pRegisterValue
74 // return: error
75 //==============================================================================
76 uint8_t SHT2x_WriteUserRegister(uint8_t *pRegisterValue);
77 //==============================================================================
78 //Sample Code SHT21
79 //www.sensirion.com Version 1.2 \96 February 2010 4/14
80 // writes the SHT2x user register (8bit)
81 // input : *pRegisterValue
82 // output: -
83 // return: error
84 //==============================================================================
85 uint8_t SHT2x_MeasurePoll(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand);
86 //==============================================================================
87 // measures humidity or temperature. This function polls every 10ms until
88 // measurement is ready.
89 // input: eSHT2xMeasureType
90 // output: *pMeasurand: humidity / temperature as raw value
91 // return: error
92 // note: timing for timeout may be changed
93 //==============================================================================
94 uint8_t SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand);
95 //==============================================================================
96 // measures humidity or temperature. This function waits for a hold master until
97 // measurement is ready or a timeout occurred.
98 // input: eSHT2xMeasureType
99 // output: *pMeasurand: humidity / temperature as raw value
100 // return: error
101 // note: timing for timeout may be changed
102 //==============================================================================
103 uint8_t SHT2x_SoftReset();
104 //==============================================================================
105 // performs a reset
106 // input: -
107 // output: -
108 // return: error
109 //==============================================================================
110 float SHT2x_CalcRH(uint16_t u16sRH);
111 //==============================================================================
112 // calculates the relative humidity
113 // input: sRH: humidity raw value (16bit scaled)
114 // return: pHumidity relative humidity [%RH]
115 //==============================================================================
116 float SHT2x_CalcTemperatureC(uint16_t u16sT);
117 //==============================================================================
118 // calculates temperature
119 // input: sT: temperature raw value (16bit scaled)
120 // return: temperature [°C]
121 //==============================================================================
122 uint8_t SHT2x_GetSerialNumber(uint8_t u8SerialNumber[]);
123 //==============================================================================
124 // gets serial number of SHT2x according application note "How To
125 // Read-Out the Serial Number"
126 // note: readout of this function is not CRC checked
127 //
128 // input: -
129 // output: u8SerialNumber: Array of 8 bytes (64Bits)
130 // MSB LSB
131 // u8SerialNumber[7] u8SerialNumber[0]
132 // SNA_1 SNA_0 SNB_3 SNB_2 SNB_1 SNB_0 SNC_1 SNC_0
133 // return: error
134 #endif