cancel
Showing results for 
Search instead for 
Did you mean: 

LPS25HB usage with Cube HAL Library

David Brooks_2
Associate II
Posted on April 30, 2017 at 06:36

I am having significant difficulty in getting an LPS25HB to work. Temperature and pressure values returned by the sensor are incorrect. And although the sensor is sending the MSByte first, as expected, it is sending the LSbit first. Tht is quite a surprise. But even that data is wrong. Can anyone point me to an example project using the LPS25HB and the Cube HAL library? I am using the STM32L152, but any example will do.

5 REPLIES 5
Posted on May 01, 2017 at 01:44

although the sensor is sending the MSByte first, as expected, it is sending the LSbit first.

Eh?

JW

David Brooks_2
Associate II
Posted on May 01, 2017 at 17:07

I am using the STMEVAL-MKI165V1 board to simulate real hardware. I forgot to tie Vdd_IO to VDD. The MSB/LSB issue is resolved. However, I am still not calculating correct pressures and temperatures. I am unable to find the problem with my code because I've found no information on what values the sensor is supposed to return, for example, at nominal ambient conditions. I've seen conflicting formulas used to convert sensor values to real pressure and temperature. A simple division by 4096 seems to be the correct method for converting pressure, but I do not get the right answer. Since the pressure MSB is sent first and winds up in RxBuffer[0], my code does swap the 24-bit contents of the buffer. As it stands now, data returned by the sensor is incorrect. I'm not convinced that I am using HAL_SPI_Transmit(), HAL_SPI_Receive() or HAL_SPI_TransmitReceive() correctly. Any examples of using the HAL to talk to this sensor? Does anyone know what pressure and temperature values the sensor returns under ambient conditions?

S.Ma
Principal
Posted on May 01, 2017 at 18:07

Remember that the sensor boots in spi bi directional mode. Use 4 wire mode by writing into the sensor control register to activate it. Then you should be able to read data properly. For environmental sensor, i2c bus makes more sense. Bitbang i2c on gpio can be tried out by simply rising nss, disabling spi af pins and checking which slave address the sensor responds to SA0 pin level dependent.

Posted on May 01, 2017 at 18:21

Interesting, according to the datasheet the I2C_DIS bit in CTRL_REG2 (21h) says I2C is Enabled by default??? I do not see where SPI is otherwise enabled on power up.

I am using 4-wire SPI and pulling CS low to initiate data transfers.

Posted on May 01, 2017 at 22:59

When nss is high, the sensor switch to i2c bus mode. The register i2c disable is probably for very specific case condition.