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