VOC Optimation
[owSlave2.git] / common / I2C / SHT2x.h
index e734a9e..5f97f83 100644 (file)
-#ifndef SHT2x_H
-#define SHT2x_H
-//==============================================================================
-// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland
-//==============================================================================
-// Project : SHT2x Sample Code (V1.2)
-// File : SHT2x.h
-// Author : MST
-// Controller: NEC V850/SG3 (uPD70F3740)
-// Compiler : IAR compiler for V850 (3.50A)
-// Brief : Sensor layer. Definitions of commands and registers,
-// functions for sensor access
-//==============================================================================
-
-
-//---------- Defines -----------------------------------------------------------
-// CRC
-#define CHECKSUM_ERROR 1
-#define TIME_OUT_ERROR 2
-#define ACK_ERROR 4
-
-
-// sensor command
-typedef enum{
-       TRIG_T_MEASUREMENT_HM = 0xE3, // command trig. temp meas. hold master
-       TRIG_RH_MEASUREMENT_HM = 0xE5, // command trig. humidity meas. hold master
-       TRIG_T_MEASUREMENT_POLL = 0xF3, // command trig. temp meas. no hold master
-       TRIG_RH_MEASUREMENT_POLL = 0xF5, // command trig. humidity meas. no hold master
-       USER_REG_W = 0xE6, // command writing user register
-       USER_REG_R = 0xE7, // command reading user register
-       SOFT_RESET = 0xFE // command soft reset
-}etSHT2xCommand;
-typedef enum {
-       SHT2x_RES_12_14BIT = 0x00, // RH=12bit, T=14bit
-       SHT2x_RES_8_12BIT = 0x01, // RH= 8bit, T=12bit
-       SHT2x_RES_10_13BIT = 0x80, // RH=10bit, T=13bit
-       SHT2x_RES_11_11BIT = 0x81, // RH=11bit, T=11bit
-       SHT2x_RES_MASK = 0x81 // Mask for res. bits (7,0) in user reg.
-} etSHT2xResolution;
-typedef enum {
-       SHT2x_EOB_ON = 0x40, // end of battery
-       SHT2x_EOB_MASK = 0x40, // Mask for EOB bit(6) in user reg.
-} etSHT2xEob;
-typedef enum {
-       SHT2x_HEATER_ON = 0x04, // heater on
-       SHT2x_HEATER_OFF = 0x00, // heater off
-       SHT2x_HEATER_MASK = 0x04, // Mask for Heater bit(2) in user reg.
-} etSHT2xHeater;
-// measurement signal selection
-typedef enum{
-       HUMIDITY,
-       TEMP
-}etSHT2xMeasureType;
-typedef enum{
-       I2C_ADR_W = 128, // sensor I2C address + write bit
-       I2C_ADR_R = 129 // sensor I2C address + read bit
-}etI2cHeader;
-//==============================================================================
-uint8_t SHT2x_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum);
-//==============================================================================
-// calculates checksum for n bytes of data and compares it with expected
-// checksum
-// input: data[] checksum is built based on this data
-// nbrOfBytes checksum is built for n bytes of data
-// checksum expected checksum
-// return: error: CHECKSUM_ERROR = checksum does not match
-// 0 = checksum matches
-//==============================================================================
-uint8_t SHT2x_ReadUserRegister(uint8_t *pRegisterValue);
-//==============================================================================
-// reads the SHT2x user register (8bit)
-// input : -
-// output: *pRegisterValue
-// return: error
-//==============================================================================
-uint8_t SHT2x_WriteUserRegister(uint8_t *pRegisterValue);
-//==============================================================================
-//Sample Code SHT21
-//www.sensirion.com Version 1.2 \96 February 2010 4/14
-// writes the SHT2x user register (8bit)
-// input : *pRegisterValue
-// output: -
-// return: error
-//==============================================================================
-uint8_t SHT2x_MeasurePoll(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand);
-//==============================================================================
-// measures humidity or temperature. This function polls every 10ms until
-// measurement is ready.
-// input: eSHT2xMeasureType
-// output: *pMeasurand: humidity / temperature as raw value
-// return: error
-// note: timing for timeout may be changed
-//==============================================================================
-uint8_t SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand);
-//==============================================================================
-// measures humidity or temperature. This function waits for a hold master until
-// measurement is ready or a timeout occurred.
-// input: eSHT2xMeasureType
-// output: *pMeasurand: humidity / temperature as raw value
-// return: error
-// note: timing for timeout may be changed
-//==============================================================================
-uint8_t SHT2x_SoftReset();
-//==============================================================================
-// performs a reset
-// input: -
-// output: -
-// return: error
-//==============================================================================
-float SHT2x_CalcRH(uint16_t u16sRH);
-//==============================================================================
-// calculates the relative humidity
-// input: sRH: humidity raw value (16bit scaled)
-// return: pHumidity relative humidity [%RH]
-//==============================================================================
-float SHT2x_CalcTemperatureC(uint16_t u16sT);
-//==============================================================================
-// calculates temperature
-// input: sT: temperature raw value (16bit scaled)
-// return: temperature [°C]
-//==============================================================================
-uint8_t SHT2x_GetSerialNumber(uint8_t u8SerialNumber[]);
-//==============================================================================
-// gets serial number of SHT2x according application note "How To
-// Read-Out the Serial Number"
-// note: readout of this function is not CRC checked
-//
-// input: -
-// output: u8SerialNumber: Array of 8 bytes (64Bits)
-// MSB LSB
-// u8SerialNumber[7] u8SerialNumber[0]
-// SNA_1 SNA_0 SNB_3 SNB_2 SNB_1 SNB_0 SNC_1 SNC_0
-// return: error
-#endif
\ No newline at end of file
+#ifndef SHT2x_H\r
+#define SHT2x_H\r
+//==============================================================================\r
+// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland\r
+//==============================================================================\r
+// Project : SHT2x Sample Code (V1.2)\r
+// File : SHT2x.h\r
+// Author : MST\r
+// Controller: NEC V850/SG3 (uPD70F3740)\r
+// Compiler : IAR compiler for V850 (3.50A)\r
+// Brief : Sensor layer. Definitions of commands and registers,\r
+// functions for sensor access\r
+//==============================================================================\r
+\r
+\r
+//---------- Defines -----------------------------------------------------------\r
+// CRC\r
+#define CHECKSUM_ERROR 1\r
+#define TIME_OUT_ERROR 2\r
+#define ACK_ERROR 4\r
+\r
+\r
+// sensor command\r
+typedef enum{\r
+       TRIG_T_MEASUREMENT_HM = 0xE3, // command trig. temp meas. hold master\r
+       TRIG_RH_MEASUREMENT_HM = 0xE5, // command trig. humidity meas. hold master\r
+       TRIG_T_MEASUREMENT_POLL = 0xF3, // command trig. temp meas. no hold master\r
+       TRIG_RH_MEASUREMENT_POLL = 0xF5, // command trig. humidity meas. no hold master\r
+       USER_REG_W = 0xE6, // command writing user register\r
+       USER_REG_R = 0xE7, // command reading user register\r
+       SOFT_RESET = 0xFE // command soft reset\r
+}etSHT2xCommand;\r
+typedef enum {\r
+       SHT2x_RES_12_14BIT = 0x00, // RH=12bit, T=14bit\r
+       SHT2x_RES_8_12BIT = 0x01, // RH= 8bit, T=12bit\r
+       SHT2x_RES_10_13BIT = 0x80, // RH=10bit, T=13bit\r
+       SHT2x_RES_11_11BIT = 0x81, // RH=11bit, T=11bit\r
+       SHT2x_RES_MASK = 0x81 // Mask for res. bits (7,0) in user reg.\r
+} etSHT2xResolution;\r
+typedef enum {\r
+       SHT2x_EOB_ON = 0x40, // end of battery\r
+       SHT2x_EOB_MASK = 0x40, // Mask for EOB bit(6) in user reg.\r
+} etSHT2xEob;\r
+typedef enum {\r
+       SHT2x_HEATER_ON = 0x04, // heater on\r
+       SHT2x_HEATER_OFF = 0x00, // heater off\r
+       SHT2x_HEATER_MASK = 0x04, // Mask for Heater bit(2) in user reg.\r
+} etSHT2xHeater;\r
+// measurement signal selection\r
+typedef enum{\r
+       HUMIDITY,\r
+       TEMP\r
+}etSHT2xMeasureType;\r
+typedef enum{\r
+       I2C_ADR_W = 128, // sensor I2C address + write bit\r
+       I2C_ADR_R = 129 // sensor I2C address + read bit\r
+}etI2cHeader;\r
+//==============================================================================\r
+uint8_t SHT2x_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum);\r
+//==============================================================================\r
+// calculates checksum for n bytes of data and compares it with expected\r
+// checksum\r
+// input: data[] checksum is built based on this data\r
+// nbrOfBytes checksum is built for n bytes of data\r
+// checksum expected checksum\r
+// return: error: CHECKSUM_ERROR = checksum does not match\r
+// 0 = checksum matches\r
+//==============================================================================\r
+uint8_t SHT2x_ReadUserRegister(uint8_t *pRegisterValue);\r
+//==============================================================================\r
+// reads the SHT2x user register (8bit)\r
+// input : -\r
+// output: *pRegisterValue\r
+// return: error\r
+//==============================================================================\r
+uint8_t SHT2x_WriteUserRegister(uint8_t *pRegisterValue);\r
+//==============================================================================\r
+//Sample Code SHT21\r
+//www.sensirion.com Version 1.2 \96 February 2010 4/14\r
+// writes the SHT2x user register (8bit)\r
+// input : *pRegisterValue\r
+// output: -\r
+// return: error\r
+//==============================================================================\r
+uint8_t SHT2x_MeasurePoll(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand);\r
+//==============================================================================\r
+// measures humidity or temperature. This function polls every 10ms until\r
+// measurement is ready.\r
+// input: eSHT2xMeasureType\r
+// output: *pMeasurand: humidity / temperature as raw value\r
+// return: error\r
+// note: timing for timeout may be changed\r
+//==============================================================================\r
+uint8_t SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand);\r
+//==============================================================================\r
+// measures humidity or temperature. This function waits for a hold master until\r
+// measurement is ready or a timeout occurred.\r
+// input: eSHT2xMeasureType\r
+// output: *pMeasurand: humidity / temperature as raw value\r
+// return: error\r
+// note: timing for timeout may be changed\r
+//==============================================================================\r
+uint8_t SHT2x_SoftReset(void);\r
+//==============================================================================\r
+// performs a reset\r
+// input: -\r
+// output: -\r
+// return: error\r
+//==============================================================================\r
+float SHT2x_CalcRH(uint16_t u16sRH);\r
+//==============================================================================\r
+// calculates the relative humidity\r
+// input: sRH: humidity raw value (16bit scaled)\r
+// return: pHumidity relative humidity [%RH]\r
+//==============================================================================\r
+float SHT2x_CalcTemperatureC(uint16_t u16sT);\r
+//==============================================================================\r
+// calculates temperature\r
+// input: sT: temperature raw value (16bit scaled)\r
+// return: temperature [°C]\r
+//==============================================================================\r
+uint8_t SHT2x_GetSerialNumber(uint8_t u8SerialNumber[]);\r
+//==============================================================================\r
+// gets serial number of SHT2x according application note "How To\r
+// Read-Out the Serial Number"\r
+// note: readout of this function is not CRC checked\r
+//\r
+// input: -\r
+// output: u8SerialNumber: Array of 8 bytes (64Bits)\r
+// MSB LSB\r
+// u8SerialNumber[7] u8SerialNumber[0]\r
+// SNA_1 SNA_0 SNB_3 SNB_2 SNB_1 SNB_0 SNC_1 SNC_0\r
+// return: error\r
+#endif\r