dht222  2.0.0.0
dht222.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef DHT222_H
36 #define DHT222_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define DHT222_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
54 
60 #define DHT222_OK 0
61 #define DHT222_ERROR -1
62 
68 #define DHT222_I2C_ADDRESS_WRITE 0xB8
69 #define DHT222_I2C_ADDRESS_READ 0xB9
70 
76 #define DHT222_REG_HUMIDITY_MSB 0x00
77 #define DHT222_REG_HUMIDITY_LSB 0x01
78 #define DHT222_REG_TEMPERATURE_MSB 0x02
79 #define DHT222_REG_TEMPERATURE_LSB 0x03
80 #define DHT222_REG_MODEL_MSB 0x08
81 #define DHT222_REG_MODEL_LSB 0x09
82 #define DHT222_REG_VERSION 0x0A
83 #define DHT222_REG_DEVICE_ID_3 0x0B
84 #define DHT222_REG_DEVICE_ID_2 0x0C
85 #define DHT222_REG_DEVICE_ID_1 0x0D
86 #define DHT222_REG_DEVICE_ID_0 0x0E
87 #define DHT222_REG_STATE 0x0F
88 #define DHT222_REG_USER_REG_1_MSB 0x10
89 #define DHT222_REG_USER_REG_1_LSB 0x11
90 #define DHT222_REG_USER_REG_2_MSB 0x12
91 #define DHT222_REG_USER_REG_2_LSB 0x13
92 
98 #define DHT222_CMD_READ 0x03
99 #define DHT222_CMD_WRITE 0x10
100 
106 #define DHT222_TIMEOUT 100000ul
107  // End group macro
110 // --------------------------------------------------------------- PUBLIC TYPES
119 typedef struct
120 {
121  pin_name_t scl;
122  pin_name_t sda;
123 
124  uint8_t i2c_started;
125 
126 } dht222_t;
127 
131 typedef struct
132 {
133  pin_name_t scl;
134  pin_name_t sda;
135 
136 } dht222_cfg_t;
137  // End types group
139 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
140 
146 #ifdef __cplusplus
147 extern "C"{
148 #endif
149 
159 
171 err_t dht222_init ( dht222_t *ctx, dht222_cfg_t *cfg );
172 
186 err_t dht222_read_reg ( dht222_t *ctx, uint8_t address, uint8_t *data_out, uint8_t len );
187 
201 err_t dht222_write_reg ( dht222_t *ctx, uint8_t address, uint8_t *data_in, uint8_t len );
202 
217 err_t dht222_get_temperature ( dht222_t *ctx, uint16_t *temperature );
218 
233 err_t dht222_get_humidity ( dht222_t *ctx, uint16_t *humidity );
234 
250 err_t dht222_get_temp_hum ( dht222_t *ctx, uint16_t *temperature, uint16_t *humidity );
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 #endif // _DHT222_H_
256  // End public_function group
259 
260 // ------------------------------------------------------------------------- END
dht222_cfg_t::sda
pin_name_t sda
Definition: dht222.h:134
dht222_t
Click ctx object definition.
Definition: dht222.h:120
dht222_get_temperature
err_t dht222_get_temperature(dht222_t *ctx, uint16_t *temperature)
Reads temperature from AM2322 sensor.
dht222_get_humidity
err_t dht222_get_humidity(dht222_t *ctx, uint16_t *humidity)
Reads humidity from AM2322 sensor.
dht222_read_reg
err_t dht222_read_reg(dht222_t *ctx, uint8_t address, uint8_t *data_out, uint8_t len)
Generic read function.
dht222_cfg_t
Click configuration structure definition.
Definition: dht222.h:132
dht222_write_reg
err_t dht222_write_reg(dht222_t *ctx, uint8_t address, uint8_t *data_in, uint8_t len)
Generic write function.
dht222_t::i2c_started
uint8_t i2c_started
Definition: dht222.h:124
dht222_cfg_setup
void dht222_cfg_setup(dht222_cfg_t *cfg)
Config Object Initialization function.
dht222_get_temp_hum
err_t dht222_get_temp_hum(dht222_t *ctx, uint16_t *temperature, uint16_t *humidity)
Reads temperature and humidity from AM2322 sensor.
dht222_init
err_t dht222_init(dht222_t *ctx, dht222_cfg_t *cfg)
Initialization function.
dht222_t::sda
pin_name_t sda
Definition: dht222.h:122
dht222_cfg_t::scl
pin_name_t scl
Definition: dht222.h:133
dht222_t::scl
pin_name_t scl
Definition: dht222.h:121