si70xx.h
4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* Copyright (C) 2016 Bas Stottelaar <basstottelaar@gmail.com>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup drivers_si70xx Si7006/13/20/21 temperature and humidity sensors
* @ingroup drivers_sensors
* @brief Driver for the Si7006/13/20/21 temperature and humidity sensor.
* @{
*
* @file
* @brief Interface definition of the Si70xx driver.
*
* @author Bas Stottelaar <basstottelaar@gmail.com>
*/
#ifndef SI70XX_H
#define SI70XX_H
#include "periph/i2c.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @name Si70xx chip addresses.
* @{
*/
#define SI70XX_ADDRESS_SI7006 (0x80)
#define SI70XX_ADDRESS_SI7013 (0x80)
#define SI70XX_ADDRESS_SI7013_ALT (0x81)
#define SI70XX_ADDRESS_SI7020 (0x80)
#define SI70XX_ADDRESS_SI7021 (0x80)
/** @} */
/**
* @name Si70xx device commands.
* @{
*/
#define SI70XX_MEASURE_RH_HOLD (0xE5)
#define SI70XX_MEASURE_RH (0xF5)
#define SI70XX_MEASURE_TEMP_HOLD (0xE3)
#define SI70XX_MEASURE_TEMP (0xF3)
#define SI70XX_MEASURE_TEMP_PREV (0xE0)
#define SI70XX_RESET (0xFE)
#define SI70XX_WRITE_USER_REG (0xE6)
#define SI70XX_READ_USER_REG (0xE7)
#define SI70XX_WRITE_HEATER_REG (0x51)
#define SI70XX_READ_HEATER_REG (0x11)
#define SI70XX_READ_ID_FIRST_A (0xFA)
#define SI70XX_READ_ID_FIRST_B (0x0F)
#define SI70XX_READ_ID_SECOND_A (0xFC)
#define SI70XX_READ_ID_SECOND_B (0xC9)
#define SI70XX_READ_REVISION_A (0x84)
#define SI70XX_READ_REVISION_B (0xB8)
/** @} */
/**
* @name Si70xx register values.
* @{
*/
#define SI70XX_ID_SI7006 (0x06)
#define SI70XX_ID_SI7013 (0x0D)
#define SI70XX_ID_SI7020 (0x14)
#define SI70XX_ID_SI7021 (0x15)
#define SI70XX_REVISION_1 (0xFF)
#define SI70XX_REVISION_2 (0x20)
/** @} */
/**
* @brief Si70xx device descriptor.
*/
typedef struct {
i2c_t i2c_dev; /**< I2C bus the sensors is connected to */
uint8_t address; /**< sensor address */
} si70xx_t;
/**
* @brief Device initialization parameters.
*/
typedef struct {
i2c_t i2c_dev; /**< I2C bus the sensor is connected to */
uint8_t address; /**< sensor address */
} si70xx_params_t;
/**
* @brief Test if the device id and revision number are as expected.
*
* @param[in] dev device descriptor
* @return zero on succesful test
* @return non-zero on unsuccesfull test.
*/
int si70xx_test(const si70xx_t *dev);
/**
* @brief Initialize and reset the sensor.
*
* @param[in] dev device descriptor
* @param[in] i2c_dev i2c device to use
* @param[in] address device address (depends on the chip)
* @return zero on succesful initialization.
* @return non-zero on error
*/
int si70xx_init(si70xx_t *dev, i2c_t i2c_dev, uint8_t address);
/**
* @brief Read the relative humidity from the sensor. Uses clock streching.
*
* @param[in] dev device descriptor
* @return relative humidity in centi-percent (times 100)
*/
uint16_t si70xx_get_relative_humidity(const si70xx_t *dev);
/**
* @brief Read the current temperature from the sensor. Uses clock streching.
*
* @param[in] dev device descriptor
* @return current temperature in centi-degrees Celsius
* (times 100)
*/
int16_t si70xx_get_temperature(const si70xx_t *dev);
/**
* @brief Read the relative humidity and temperature from the sensor. Uses
* clock stretching.
*
* @param[in] dev device descriptor
* @param[out] humidity pointer to relative humidity (in centi-percent)
* @param[out] temperature pointer to temperature (in centi-degrees Celsius)
*/
void si70xx_get_both(const si70xx_t *dev, uint16_t *humidity, int16_t *temperature);
/**
* @brief Read the sensor serial number.
*
* @param[in] dev device descriptor
* @return sensor serial number
*/
uint64_t si70xx_get_serial(const si70xx_t *dev);
/**
* @brief Read the sensor id, to identifier the sensor variant.
*
* @param[in] dev device descriptor
* @return device id
*/
uint8_t si70xx_get_id(const si70xx_t *dev);
/**
* @brief Read the firmware revision of the sensor.
*
* @param[in] dev device descriptor
* @return sensor firmware revision number
*/
uint8_t si70xx_get_revision(const si70xx_t *dev);
#ifdef __cplusplus
}
#endif
#endif /* SI70XX_H */
/** @} */