AN4159
Using the device step-by-step, from basic to advanced
Doc ID 023639 Rev 3
11/27
5
Using the device step-by-step, from basic to
advanced
5.1
First time bring-up
1.
Start by using the same supply for VDD_IO and VDD to check the device functionality.
2.
Make sure of the supply impedances and check all the pins voltages in static condition.
3.
The device is a simple slave with 1 byte sub-address which bit 7 should always be '1'
(bit 7 = 1 enables I2C sub-address multi-byte auto-increment = use it always!)
Use an oscilloscope to check that the device acknowledge its slave address.
Use a normal I2C bus speed (<400 kHz)
Make sure there are no other slaves with same address on the I2C bus lines.
The maximum I2C speed is driven by the slowest slave on the same I2C bus.
4.
Read the Chip ID (sub address 0x8F [=0x0F]) byte: 0xBB should be read
5.1.1
One shot mode measurement sequence
5.
Power down the device (clean start)
–
LPS331AP_WriteByte(LPS331AP_CTRL_REG1_ADDR,0x00); // @0x20=0x00
6.
Set the pressure sensor to higher-precision
–
LPS331AP_WriteByte(LPS331AP_RES_ADDR,0x7A);// @0x10=0x7A
–
Please note that 0x7A is forbidden in auto-mode (25Hz,25Hz): use 0x79 instead.
7.
Turn on the pressure sensor analog front end in single shot mode
–
LPS331AP_WriteByte(LPS331AP_CTRL_REG1_ADDR,0x84); // @0x20=0x84
8.
Run one shot measurement (Temperature and Pressure), self clearing bit when done.
–
LPS331AP_WriteByte(LPS331AP_CTRL_REG2_ADDR,0x01); // @0x21=0x01
9.
Wait until the measurement is completed: Wait that reading (@0x21=0x00)
10. Read the Temperature measurement (2 bytes to read)
–
LPS331AP_Read((u8*)pu8, LPS331AP_TEMP_OUT_ADDR, 2); // @0x2B~2C
–
Temp_Reg_s16 = ((u16) pu8[1]<<8) | pu8[0]; // make a SIGNED 16 bit variable
–
Temperature_DegC = 42.5 + Temp_Ref_s16 / (120*4); // scale and offset
●
Read the Temperature-compensated Pressure measurement
–
LPS331AP_Read((u8*) pu8, LPS331AP_PRESS_OUT_ADDR, 3); // reading
auto-incremented @0x28/29/2A
–
LPS331AP_pressure_hw_reg_u32 = ((u32)pu8[2]<<16)|((u32)pu8[1]<<8)|pu8[0];
// make a unsigned 32 bit variable
–
LPS331AP_pressure_mb = LPS331AP_pressure_hw_reg_u32 / 4096; // scale
11. Check the temperature and pressure values make sense
–
Reading fixed 760 mb, means the sensing element is damaged.
Example of register measurements and conversion:
P = 0x3FF58D means 1023.347 mb
T = 0xE07C means 42.5 + (-8068/120) = -25.7 °C