English | 简体中文 | 繁體中文 | 日本語 | Deutsch | 한국어
The HDC302x is an integrated, capacitive based relative humidity (RH) and temperature sensor . The device provides high accuracy measurements over a wide supply range (1.62V – 5.5V) and ultra low power consumption in a compact 2.5mm × 2.5mm × 0.8mm WSON 8-pin package. Both the temperature and humidity sensors are 100% tested and trimmed on a production setup that is NIST traceable and verified with equipment that is calibrated to ISO/IEC 17025 standards.Offset Error Correction reduces RH sensor offset due to aging, exposure to extreme operating conditions, and contaminants to return device to within accuracy specifications. For battery IoT applications, auto measurement mode and ALERT feature enable low system power by maximizing MCU sleep time. There are four different I2C addresses that support speeds up to 1MHz. A heater is available to dissipate condensation and moisture.The HDC3020 is an open cavity package without protective cover. Two device variants have a cover option to protect the open cavity RH sensor: HDC3021 and HDC3022. HDC3021 has removable protective tape to allow conformal coatings and PCB wash. HDC3022 has a permanent IP67 filter membrane to protect against dust and water condensation.
LibDriver HDC302X is a full-featured driver for HDC302X, launched by LibDriver.It provides temperature reading, relative humidity reading, interrupt and additional features. LibDriver is MISRA compliant.
/src includes LibDriver HDC302X source files.
/interface includes LibDriver HDC302X IIC platform independent template.
/test includes LibDriver HDC302X driver test code and this code can test the chip necessary function simply.
/example includes LibDriver HDC302X sample code.
/doc includes LibDriver HDC302X offline document.
/datasheet includes HDC302X datasheet.
/project includes the common Linux and MCU development board sample code. All projects use the shell script to debug the driver and the detail instruction can be found in each project's README.md.
/misra includes the LibDriver MISRA code scanning results.
Reference /interface IIC platform independent template and finish your platform IIC driver.
Add the /src directory, the interface driver for your platform, and your own drivers to your project, if you want to use the default example drivers, add the /example directory to your project.
You can refer to the examples in the /example directory to complete your own driver. If you want to use the default programming examples, here's how to use them.
#include "driver_hdc302x_basic.h"
uint8_t res;
uint8_t id[6];
uint32_t i;
float temperature;
float humidity;
/* basic init */
res = hdc302x_basic_init(HDC302X_ADDRESS_00);
if (res != 0)
{
return 1;
}
...
/* get nist id */
res = hdc302x_basic_get_nist_id(id);
if (res != 0)
{
(void)hdc302x_basic_deinit();
return 1;
}
/* output */
hdc302x_interface_debug_print("hdc302x: nist id is 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\n",
id[0], id[1], id[2], id[3], id[4], id[5]);
...
/* loop */
for (i = 0; i < 3; i++)
{
/* delay 1000ms */
hdc302x_interface_delay_ms(1000);
/* read data */
res = hdc302x_basic_read((float *)&temperature, (float *)&humidity);
if (res != 0)
{
(void)hdc302x_basic_deinit();
return 1;
}
/* output */
hdc302x_interface_debug_print("hdc302x: %d/%d.\n", (uint32_t)(i + 1), (uint32_t)3);
hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature);
hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity);
/* read humidity min */
res = hdc302x_basic_read_humidity_min(&humidity);
if (res != 0)
{
(void)hdc302x_basic_deinit();
return 1;
}
hdc302x_interface_debug_print("hdc302x: humidity min is %0.2f%%.\n", humidity);
/* read humidity max */
res = hdc302x_basic_read_humidity_max(&humidity);
if (res != 0)
{
(void)hdc302x_basic_deinit();
return 1;
}
hdc302x_interface_debug_print("hdc302x: humidity max is %0.2f%%.\n", humidity);
/* read temperature min */
res = hdc302x_basic_read_temperature_min(&temperature);
if (res != 0)
{
(void)hdc302x_basic_deinit();
return 1;
}
hdc302x_interface_debug_print("hdc302x: temperature min is %0.2fC.\n", temperature);
/* read temperature max */
res = hdc302x_basic_read_temperature_max(&temperature);
if (res != 0)
{
(void)hdc302x_basic_deinit();
return 1;
}
hdc302x_interface_debug_print("hdc302x: temperature max is %0.2fC.\n", temperature);
...
}
...
/* basic deinit */
(void)hdc302x_basic_deinit();
return 0;#include "driver_hdc302x_shot.h"
uint8_t res;
uint32_t i;
float temperature;
float humidity;
/* shot init */
res = hdc302x_shot_init(HDC302X_ADDRESS_00);
if (res != 0)
{
return 1;
}
...
/* read data */
res = hdc302x_shot_read((float *)&temperature, (float *)&humidity);
if (res != 0)
{
(void)hdc302x_shot_deinit();
return 1;
}
/* loop */
for (i = 0; i < 3; i++)
{
/* delay 1000ms */
hdc302x_interface_delay_ms(1000);
/* read data */
res = hdc302x_shot_read((float *)&temperature, (float *)&humidity);
if (res != 0)
{
(void)hdc302x_shot_deinit();
return 1;
}
/* output */
hdc302x_interface_debug_print("hdc302x: %d/%d.\n", (uint32_t)(i + 1), (uint32_t)3);
hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature);
hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity);
...
}
...
/* shot deinit */
(void)hdc302x_shot_deinit();
return 0;#include "driver_hdc302x_interrupt.h"
uint8_t res;
uint32_t i;
float humidity_high = 50.0f;
float humidity_low = 30.0f;
float temperature_high = 30.0f;
float temperature_low = 20.0f;
float temperature;
float humidity;
static void a_callback(uint16_t type)
{
switch (type)
{
case HDC302X_STATUS_OVERALL_ALERT :
{
hdc302x_interface_debug_print("hdc302x: irq overall alert.\n");
break;
}
case HDC302X_STATUS_HEATER :
{
hdc302x_interface_debug_print("hdc302x: irq heater.\n");
break;
}
case HDC302X_STATUS_RH_TRACKING_ALERT :
{
hdc302x_interface_debug_print("hdc302x: irq rh tracking alert.\n");
break;
}
case HDC302X_STATUS_T_TRACKING_ALERT :
{
hdc302x_interface_debug_print("hdc302x: irq t tracking alert.\n");
break;
}
case HDC302X_STATUS_RH_HIGH_TRACKING_ALERT :
{
hdc302x_interface_debug_print("hdc302x: irq rh high tracking alert.\n");
break;
}
case HDC302X_STATUS_RH_LOW_TRACKING_ALERT :
{
hdc302x_interface_debug_print("hdc302x: irq rh low tracking alert.\n");
break;
}
case HDC302X_STATUS_T_HIGH_TRACKING_ALERT :
{
hdc302x_interface_debug_print("hdc302x: irq t high tracking alert.\n");
break;
}
case HDC302X_STATUS_T_LOW_TRACKING_ALERT :
{
hdc302x_interface_debug_print("hdc302x: irq t low tracking alert.\n");
break;
}
case HDC302X_STATUS_DEVICE_RESET_DETECTED :
{
hdc302x_interface_debug_print("hdc302x: irq device reset detected.\n");
break;
}
case HDC302X_STATUS_CHECKSUM_VERY :
{
hdc302x_interface_debug_print("hdc302x: irq checksum.\n");
break;
}
default :
{
hdc302x_interface_debug_print("hdc302x: unknown code.\n");
break;
}
}
}
/* interrupt init */
res = hdc302x_interrupt_init(HDC302X_ADDRESS_00, temperature_low, temperature_high,
humidity_low, humidity_high, a_callback);
if (res != 0)
{
return 1;
}
...
/* loop */
for (i = 0; i < 3; i++)
{
/* delay 1000ms */
hdc302x_interface_delay_ms(1000);
/* read data */
res = hdc302x_interrupt_read((float *)&temperature, (float *)&humidity);
if (res != 0)
{
(void)hdc302x_interrupt_deinit();
return 1;
}
/* output */
hdc302x_interface_debug_print("hdc302x: %d/%d.\n", (uint32_t)(i + 1), (uint32_t)3);
hdc302x_interface_debug_print("hdc302x: temperature is %0.2fC.\n", temperature);
hdc302x_interface_debug_print("hdc302x: humidity is %0.2f%%.\n", humidity);
/* run irq */
hdc302x_interrupt_irq_handler();
...
}
...
/* interrupt deinit */
(void)hdc302x_interrupt_deinit();
return 0;Online documents: https://www.libdriver.com/docs/hdc302x/index.html.
Offline documents: /doc/html/index.html.
Please refer to CONTRIBUTING.md.
Copyright (c) 2015 - present LibDriver All rights reserved
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Please send an e-mail to lishifenging@outlook.com.