HDC2010 is an integrated humidity and temperature sensor that provides high accuracy measurements with very low power consumption, in an ultra-compact WLCSP (Wafer Level Chip Scale Package). Below you will find a simple example to get temperature and humidity of this sensor by connecting it via I2C to an STM32 microcontroller. (I used the L4 series)
/*
* This example is tested on STM32L4 microcontroller directly connected with HDC2010 sensor via I2C
*/
void hdc2010_enable()
{
uint8_t value = 0;
HAL_I2C_Mem_Write(&hi2c1,(0b1000000 << 1), 0x0E, 1, &value, 1, 1000);
HAL_I2C_Mem_Write(&hi2c1,(0b1000000 << 1), 0x0F, 1, &value, 1, 1000);
osDelay(20);
}
void hdc2010_get_temperature(int *temperature)
{
uint8_t temp[2];
uint8_t command[2] = {0x01,0x00};
HAL_I2C_Mem_Write(&hi2c1,(0b1000000 << 1), 0x0F, 1, &command[0], 1, 1000);
osDelay(5);
HAL_I2C_Master_Transmit(&hi2c1,(0b1000000 << 1), &command[1], 1, 1000);
HAL_I2C_Master_Receive(&hi2c1, (0b1000000 << 1), &temp[0], 1, 1000);
HAL_I2C_Master_Transmit(&hi2c1,(0b1000000 << 1), &command[0], 1, 1000);
HAL_I2C_Master_Receive(&hi2c1, (0b1000000 << 1), &temp[1], 1, 1000);
*temperature = ((((int64_t)(((int)temp[1]) << 8 | temp[0])) * 165)/65536) - 40;
}
void hdc2010_get_humidity(int *humidity)
{
uint8_t temp[2];
uint8_t command = {0x01, 0x02 ,0x03};
HAL_I2C_Mem_Write(&hi2c1,(0b1000000 << 1), 0x0F, 1, &command[0], 1, 1000);
osDelay(5);
HAL_I2C_Master_Transmit(&hi2c1,(0b1000000 << 1), &command[1], 1, 1000);
HAL_I2C_Master_Receive(&hi2c1, (0b1000000 << 1), &temp[0], 1, 1000);
HAL_I2C_Master_Transmit(&hi2c1,(0b1000000 << 1), &command[2], 1, 1000);
HAL_I2C_Master_Receive(&hi2c1, (0b1000000 << 1), &temp[1], 1, 1000);
*humidity = ((((int64_t)(((int)temp[0]) << 8 | temp[1])) * 100)/65536);
}