Unable to initialize/activate HTS221
Good Afternoon.
I have an NCD module that uses the HTS221 sensor. I have posted this question on their support forum as well, but they were not able to help me. Likewise, I have posted this question on the STM32duino support forum as well, since I am using their API to configure the HTS221 sensor.
I am, from what I can tell, able to communicate with the HTS221 -- I can successfully poll the sensor for its device ID (0xBC) and the configuration register without errors. However, when I try to update the configuration (set ODR to 1 hz) and activate the sensor (set PD bit to 1) nothing happens. The configuration does not appear to change and polling the temp/humidity gives me the same results every time. Here is an example of what is output (at 1 hz):
[17:30:46] Humidity: 61.5, Temp_C: 23.9, Temp_F: 75.02, DevId: 0xbc, Error: 0x0
[17:30:47] Humidity: 61.5, Temp_C: 23.9, Temp_F: 75.02, DevId: 0xbc, Error: 0x0
[17:30:48] Humidity: 61.5, Temp_C: 23.9, Temp_F: 75.02, DevId: 0xbc, Error: 0x0
[17:30:49] Humidity: 61.5, Temp_C: 23.9, Temp_F: 75.02, DevId: 0xbc, Error: 0x0
[17:30:50] Humidity: 61.5, Temp_C: 23.9, Temp_F: 75.02, DevId: 0xbc, Error: 0x0
[17:30:51] Humidity: 61.5, Temp_C: 23.9, Temp_F: 75.02, DevId: 0xbc, Error: 0x0
[17:30:52] Humidity: 61.5, Temp_C: 23.9, Temp_F: 75.02, DevId: 0xbc, Error: 0x0
[17:30:53] Humidity: 61.5, Temp_C: 23.9, Temp_F: 75.02, DevId: 0xbc, Error: 0x0
[17:30:54] Humidity: 61.5, Temp_C: 23.9, Temp_F: 75.02, DevId: 0xbc, Error: 0x0
[17:30:55] Humidity: 61.5, Temp_C: 23.9, Temp_F: 75.02, DevId: 0xbc, Error: 0x0Here is the code that I am using, specific to this sensor:
i2c device_hts;
SensorRing_st ring = {0};
HTS_Data_st hts_data = {0};
...
// initialize the sensor
ring.error |= HTS_Begin(&device_hts,&hts_data);
// collect data
while(1) {
ring.error |= HTS_Poll(&device_hts,&hts_data);
dealy_us(4000); // delay 4msec (I've tried 1 second delays, same result)
}
SensorRing_Error_et HTS_Begin(void *handle, HTS_Data_st *hts_data)
{
/* Power down the device */
if ( HTS_DeActivate( (void *)handle ) == HTS_ERROR )
return HTS_SENSOR_ERROR;
/* Enable BDU */
if ( HTS_Set_BduMode( (void *)handle, HTS_ENABLE ) == HTS_ERROR )
{
return HTS_SENSOR_ERROR;
}
if (HTS_Set_Odr((void *)handle, HTS_ODR_1HZ) == HTS_ERROR)
{
return HTS_SENSOR_ERROR;
}
// I also tried just using the Set_InitConfig() method, same result
// HTS_Init_st hts_init = {0};
// hts_init.avg_h = HTS_AVGH_4;
// hts_init.avg_t = HTS_AVGT_2;
// hts_init.odr = HTS_ODR_1HZ;
// hts_init.bdu_status = HTS_DISABLE;
// hts_init.heater_status = HTS_DISABLE;
// hts_init.irq_level = HTS_HIGH_LVL;
// hts_init.irq_output_type = HTS_PUSHPULL;
// hts_init.irq_enable = HTS_DISABLE;
// HTS_Set_InitConfig((void *)handle,&hts_init);
/* Enable sensor */
HTS_Activate((void *)handle);
/* Tag sensor */
HTS_Get_DeviceID((void *)handle,&hts_data->id);
return ALL_SENSOR_OK;
}I am using the ST32 HTS221 library found here: github.com/stm32duino/HTS221
