Software
AN4159
24/27
Doc ID 023639 Rev 3
Case 12:
“How is the pressure variation threshold interrupt activated?”
●
We assume in the explanation that the registers in RIF_PAS (@3C, 3D, 3E) are not
used in the application.
Mechanism:
First, differential mode must be activated (DIFF_EN=1)
Second, program the reference pressure in REF_P register (for example, copy the
current P_OUT value to REF_P registers).
Caution
: P_OUT is the measured ADC pressure minus the REF_P, so at this point all
the future P_OUT measurements should be near 0 mb. To keep track of the absolute
pressure, the SW in the host should remember REF_P and add it back to P_OUT.
Third, program the threshold THS register (1 LSB = 1/16 mb step). This defines the
pressure band: When P_OUT absolute difference exceed THS value, and interrupt will
be generated.
Fourth: Configure the INT pin and the type of interrupt needed.
Source code example:
u8 LPS331AP_ActivatePressureBand(u16 Threshold_mb_x16)
{
u8 reg;
u8 regs[4];
// Warning: this can only be done if the 1 point calibration HW feature is
unused
reg = LPS331AP_ReadByte(LPS331AP_CTRL_REG1_ADDR);
if(reg & 0x02)
return FALSE;
// if DIFF_EN bit is set, to clear it, and increase
LPS331AP_Adjust_Value_Pressure_Reg by the DELTA_PRESS value.
LPS331AP_WriteByte(LPS331AP_CTRL_REG1_ADDR, reg | 0x08); // activate the
delta pressure logic
LPS331AP_Read(regs,LPS331AP_PRESS_OUT_ADDR,3);// no reading back of REF_P
required.
LPS331AP_Write(regs,LPS331AP_REF_P_ADDR,3);
LPS331AP_Adjust_Value_Pressure_Reg = ((u32)regs[2])<<16;
LPS331AP_Adjust_Value_Pressure_Reg |= ((u32)regs[1])<<8;
LPS331AP_Adjust_Value_Pressure_Reg |= regs[0];
LPS331AP_Adjust_Value_Pressure_Reg =~LPS331AP_Adjust_Value_Pressure_Reg;
// now activate the delta pressure logic
LPS331AP_WriteByte(LPS331AP_THS_P_ADDR,Threshold_mb_x16); // LSB Threshold
LPS331AP_WriteByte(LPS331AP_THS1,Threshold_mb_x16>>8); // MSB
Threshold
LPS331AP_WriteByte(LPS331AP_INTERRUPT_CONFIG_ADDR,0x03); // write 0x07 if
you want the interrupt output to stop by reading INT_SOURCE Reg