2019-03-12 03:06 AM
In CubeMX the HTS221 driver was chosen.
While looking to use the sensor within the code, i can't find any documentation how to initialize the sensor.
In the HTS221 headerfile i can find: HTS221_Init(HTS221_Object_t *pObj)
This function uses a HTS221_Object_t*!
Though to fill in the structs no documentation is been given.
Perhaps I'm looking in the wrong place but in the X-CUBE-MEMS1 repository I can't find the documentation.
Is there documentation or an example how to use the HTS221 driver?
I've used the Bosch BME280 sensor before and that driver is very well documentated.
I am new to STM32 and i've chosen to work with STM32 and the HTS221 for 100 CAN nodes with a HTS221 sensor.
Help appreciated.
2019-03-12 07:26 AM
hi, are you facing an initialization issue or are you asking how to initialize the HTS221? To initialize the sensor you could simply set 80h to CTRL_REG1 (20h) (from PD to Normal mode), according to the datasheet, and read the outputs according to it.
Here you can find a basic example for the sensor output reading, if the CubeExpansion_MEMS drivers are not clearly understandable:
https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/hts221_STdC
2019-03-12 09:34 AM
The timing here is remarkable I am having the same issue, I have downloaded the X-nucleo example project that uses a gui to show the readings and it all works : found here: https://www.st.com/content/st_com/en/products/ecosystems/stm32-open-development-environment/stm32-nucleo-expansion-boards/stm32-ode-sense-hw/x-nucleo-iks01a2.html
but I want to interface the sensor without using BSP just the regular C drivers linked in the first answer, but when I use their example code my program gets stuck on line 153 because the Device ID does not match, I am printing the result and it is 0 so my guess is I am not even communicating with the chip.
Basing myself off the schematic of the Xnucleo I am using (shown below) I am pretty sure the sensor is powered on and on i2c1 ... the proper jumpers are set ... i guess i should probe the sensor later when I get home to see it is indeed powered on, but the (very bloated abstracted) HAL code from the xnucleo files works just fine.. I cannot compile it because it exceeds my linker code size limit.. but I can upload the binary thats how i saw it working... My best guess is that maybe I have not set up i2c exactly how the sensor wants? I am using fast mode 400khz , and everything else default.
2019-03-12 07:16 PM
I figured out my issue, turns out the the nucelo expansion board I am using routes the pins labeled i2c1 to the i2c1 alternate pin pair. as for the original poster, use the example file given in the github link above, it doesnt use the extra hts221 c and H files it just uses the hts221_reg c and h file. so no need for that obj structure either
2019-03-20 03:32 AM
Hi,
I have trouble initializing the HTS221 with the driver provided by CubeMX. The example you provided uses perhaps a previous version of the driver. As one sets in CubeMX I2C1 as the I2C to use, i suppose the MEMS driver inializes I2C1. That initialization is no longer named "MX_I2C1_Init(); but "MX_MEMS_Init();". But that Init function is empty?
Can i suppose the HTS221 driver is provided with an I2C1 read and write function?
As mentioned above i suppose the HTS221 sensor needs to be initialized with the the function "HTS221_Init(HTS221_Object_t *pObj)".
But the two structs that are needed for the object "HTS221_IO_t" and "HTS221_Object_t" lack any default values?
I hope you can enlighten me, without any documentation i'm truly in the dark.
Thx in advance.