#include <rtthread.h>
#include <rtdevice.h>
#define AHT10_I2C_BUS_NAME "i2c1"
#define AHT10_ADDR 0x38
#define AHT10_CALIBRATION_CMD 0xE1
#define AHT10_NORMAL_CMD 0xA8
#define AHT10_GET_DATA 0xAC
{
buf[0] = reg;
buf[1] = data[0];
buf[2] = data[1];
{
}
else
{
}
}
{
{
}
else
{
}
}
static void read_temp_humi(float *cur_temp, float *cur_humi)
{
write_reg(i2c_bus, AHT10_GET_DATA, 0);
read_regs(i2c_bus, 6, temp);
*cur_humi = (temp[1] << 12 | temp[2] << 4 | (temp[3] & 0xf0) >> 4) * 100.0 / (1 << 20);
*cur_temp = ((temp[3] & 0xf) << 16 | temp[4] << 8 | temp[5]) * 200.0 / (1 << 20) - 50;
}
static void aht10_init(const char *name)
{
{
}
else
{
write_reg(i2c_bus, AHT10_NORMAL_CMD, temp);
temp[0] = 0x08;
temp[1] = 0x00;
write_reg(i2c_bus, AHT10_CALIBRATION_CMD, temp);
}
}
static void i2c_aht10_sample(int argc, char *argv[])
{
float humidity, temperature;
char name[RT_NAME_MAX];
humidity = 0.0;
temperature = 0.0;
if (argc == 2)
{
}
else
{
rt_strncpy(name, AHT10_I2C_BUS_NAME, RT_NAME_MAX);
}
if (!initialized)
{
aht10_init(name);
}
if (initialized)
{
read_temp_humi(&temperature, &humidity);
rt_kprintf(
"read aht10 sensor humidity : %d.%d %%\n", (
int)humidity, (
int)(humidity * 10) % 10);
rt_kprintf(
"read aht10 sensor temperature: %d.%d \n", (
int)temperature, (
int)(temperature * 10) % 10);
}
else
{
}
}