-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSi7021.h
More file actions
72 lines (56 loc) · 1.66 KB
/
Si7021.h
File metadata and controls
72 lines (56 loc) · 1.66 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
#ifndef SI7021_H
#define SI7021_H
#include "mbed.h"
/** Si7012 Read Temperature Command */
#define READ_TEMP 0xE0 /* Read previous T data from RH measurement command*/
/** Si7012 Read RH Command */
#define READ_RH 0xE5 /* Perform RH (and T) measurement. */
/** Si7012 Read ID */
#define READ_ID1_1 0xFA
#define READ_ID1_2 0x0F
#define READ_ID2_1 0xFC
#define READ_ID2_2 0xC9
/** Si7012 Read Firmware Revision */
#define READ_FWREV_1 0x84
#define READ_FWREV_2 0xB8
/** I2C device address for Si7021 */
#define ADDR 0x80
/** I2C device frequency for Si7021 */
#define FREQ 100000
/** Device ID value for Si7021 */
#define DEVICE_ID 0x15
class Si7021
{
public:
Si7021(PinName sda, PinName scl);
~Si7021();
/*
* Get last measured temperature data
* return: int32_t = temperature in millidegrees centigrade
*/
int32_t get_temperature();
/*
* Get last measured relative humidity data
* return: uint32_t = relative humidity value in milli-percent
*/
uint32_t get_humidity();
/*
* Perform measurement.
* Asynchronous callback can be provided (type void (*)(void)).
* return: 0 if successful, else one of the defined error codes.
*/
bool measure();
/*
* Check if the sensor is active and responding. This will update the get_active value.
* Asynchronous callback can be provided (type void (*)(void)).
* return: 0 if successful, else one of the defined error codes.
*/
bool check();
private:
I2C i2c;
uint8_t rx_buff[8];
uint8_t tx_buff[2];
uint32_t rhData;
int32_t tData;
};
#endif