AN4519&
AN4519&
AN4519&
1 Introduction
It is important to understand how to program the
MPL3115A2 to extract pressure and temperature data. Contents
The MPL3115A2 has many different features which 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 MPL3115A2 I2C Precision Altimeter . . . . . . . . . . . . . . . . 3
include 8 different sample rates, 16 different acquisition 3 Modes of Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
time steps (1 second to 9 hours), compensated direct 4 Setting the Data Rate . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
reading of Pressure (20 bit in Pascals) or Altitude (20 bit 5 Data Streaming and Data Conversions . . . . . . . . . . . . . . 8
6 Polling Data Versus Interrupts. . . . . . . . . . . . . . . . . . . . 16
in meters), compensated direct reading of temperature 7 Pressure/Altitude Alarms Interrupts. . . . . . . . . . . . . . . . 19
(12 bit in degrees Celsius) and programmable events. It 8 Temperature Alarm Interrupts . . . . . . . . . . . . . . . . . . . . 24
9 Using the 32-sample FIFO . . . . . . . . . . . . . . . . . . . . . . 28
also contains a 32-sample FIFO for collecting and 10 Command Line Interface User Guide . . . . . . . . . . . . . . 34
storing data, which gives it the ability to log data for up
to 12 days. The FIFO is the most efficient means of
accessing the data since it minimizes I2C transactions.
This application note accompanies the MPL3115A2
Command Line Interface Driver Code and will explain
how to change the following:
• Modes of operation: Standby, Active Altitude,
and Active Barometer
• Sample Rate (OSR)
• Data Acquisition Rate (ST)
• Data Formats (hex to decimal)
• Streaming Pressure/Altitude and Temperature
(PT) data polling versus Streaming PT Data with
interrupts
1.2 Summary
• There are three modes: Standby Mode, Active Altimeter Mode and Active Barometer Mode.
• An example of how to set the data rate (OSR) and the time step (ST) is shown. There are eight
OSRs and the time step can be set from 1 second to 9 hours in steps of powers of two.
• Examples of how to setup the sensor to poll data or use an Interrupt Service Routine (ISR) to
retrieve data.
• Use of the FIFO in either Overflow or Watermark mode.
• Setup the programmable alarms for Pressure/Altitude with and without specifying a window.
• Setup the programmable alarms for Temperature with and without specifying a window.
• Read and write registers.
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
VDD 1 8 SCL
CAP 2 7 SDA
GND 3 6 INT1
VDDIO 4 5 INT2
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
7 6 5 4 3 2 1 0
R 0
ALT RAW OS2 OS1 OS0 OST SBYB
W RST
Reset 0 0 0 0 0 0 0 0
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
/*
** Write a 0 to the ALT and a 1 SBYB bits to go into Active Barometer mode
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, (CTRL_REG_1_DATA | BAR_MASK | ACTIVE_MASK));
NOTE
In Barometer mode, the 20-bit value stored in OUT_P_MSB, OUT_P_CSB
and OUT_P_LSB is in Pascals represented as an unsigned 18-bit value in
OUT_P_MSB, OUT_P_CSB and bits 7-6 of OUT_P_LSB with the
fractional value in bits 5-4 of OUT_P_LSB. Bits 3-0 of OUT_P_LSB are
unused in this mode.
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
7 6 5 4 3 2 1 0
R 0
ALT RAW OS2 OS1 OS0 OST SBYB
W RST
Reset 0 0 0 0 0 0 0 0
Example 4.
/*
** Read contents of CTRL_REG_1
** Clear SBYB mask while holding all other values of CTRL_REG_1.
** To put part into Standby mode
*/
CTRL_REG_1_DATA = IIC_RegRead(SlaveAddressIIC, CTRL_REG1);
IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, CTRL_REG_1_DATA & STANDBY_SBYB_MASK);
/**
** The OSR_Value is set to 0 - 7 corresponding with Ratios 1 - 128
*/
if (OSR_Value < 8) {
OSR_Value <<= 3;
IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, (CTRL_REG_1_DATA |OSR_Value));
}
CTRL_REG_2
7 6 5 4 3 2 1 0
R 0 0
LOAD_OUTPUT ALARM_SEL ST[3] ST[2] ST[1] ST[0]
W
Reset 0 0 0 0 0 0 0 0
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
Time Step
ST[3] ST[2] ST[1] ST[0]
(seconds)
0 0 0 0 1
0 0 0 1 2
0 0 1 0 4
0 0 1 1 8
0 1 0 0 16
0 1 0 1 32
0 1 1 0 64
0 1 1 1 128
1 0 0 0 256
1 0 0 1 512
1 0 1 0 1024
1 0 1 1 2048
1 1 0 0 4096
1 1 0 1 8192
1 1 1 0 16384
1 1 1 1 32768
Example 5.
/*
** Read contents of CTRL_REG_1
** Clear SBYB mask while holding all other values of CTRL_REG_1.
** To put part into Standby mode
*/
CTRL_REG_1_DATA = IIC_RegRead(SlaveAddressIIC, CTRL_REG1);
IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, CTRL_REG_1_DATA & STANDBY_SBYB_MASK);
/**
** The ST_Value is set from 0x1 - 0xF corresponding steps 1 - 32,768
*/
if (ST_Value <= 0xF) {
CTRL_REG_2_DATA = IIC_RegRead(SlaveAddressIIC, CTRL_REG2);
IIC_RegWrite(SlaveAddressIIC, CTRL_REG2, (CTRL_REG_2_DATA|ST_Value));
}
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
PT_DATA_CFG
7 6 5 4 3 2 1 0
R
DREM PDEFE TDEFE
W
Reset 0 0 0 0 0 0 0 0
The following line of code illustrates how to set the event flag to be generated when a new pressure/altitude
reading is available to be read:
IIC_RegWrite(SlaveAddressIIC, PT_DATA_CFG_REG, PDEFE_MASK );
Once configured, the event flag can be monitored by reading the STATUS register at address 0x00/0x06.
This can be done by using either a polling or interrupt technique, which is discussed later in Section 6,
“Polling Data Versus Interrupts” of this document. Regardless of the technique used, the STATUS register
needs to be read and the appropriate flag monitored.
DR_STATUS
7 6 5 4 3 2 1 0
Reset 0 0 0 0 0 0 0 0
The PDR flag is set whenever there is new pressure data available. The following code example monitors
this flag and upon detection of new data, reads the 20-bit Pressure data into three separate 8-bit variables
for further processing.
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
if (RegisterFlag.PDR_BIT == 1)
{
/*
** Read 20 bit Pressure Data Results
** and store in 8 bit registers
*/
pressure_value_raw.Byte.tp_msb = IIC_RegRead(SlaveAddressIIC, OUT_P_MSB_REG);
pressure_value_raw.Byte.tp_csb = IIC_RegRead(SlaveAddressIIC, OUT_P_CSB_REG);
pressure_value_raw.Byte.tp_lsb = IIC_RegRead(SlaveAddressIIC, OUT_P_LSB_REG);
}
NOTE
In RAW mode the pressure value is stored in all 24 bits that comprise
OUT_P_MSB, OUT_P_CSB and OUT_P_LSB; and for the temperature
value all 16 bits of OUT_T_MSB and OUT_T_LSB are utilized.
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
We can then add these values together for each bit that is a 1 and we get the fractional component of the
altitude value in fractions of a meter. For example, the value of 0.75 meters will be represented by the
following 4-bit value: 1100. So using the table above, you would add 0.5 to 0.25 to get 0.75 meters.
Example 8.
void SCI_s4fracun_Out (tword data)
{
BIT_FIELD value;
word result;
byte a, b, c, d;
word r;
SCI_CharOut ('.');
/*
** Determine mantissa value
*/
result = 0;
value.Byte = data.Byte.hi;
if (value.Bit._7 == 1)
result += FRAC_2d1;
if (value.Bit._6 == 1)
result += FRAC_2d2;
if (value.Bit._5 == 1)
result += FRAC_2d3;
if (value.Bit._4 == 1)
result += FRAC_2d4;
//
/*
** Convert mantissa value to 4 decimal places
*/
r = result % 1000;
a = (byte)(result / 1000);
b = (byte)(r / 100);
r %= 100;
c = (byte)(r / 10);
d = (byte)(r % 10);
/*
** Output mantissa
*/
SCI_NibbOut (a);
SCI_NibbOut (b);
SCI_NibbOut (c);
SCI_NibbOut (d);
}
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
r = (data.LWord>>6) % 10000000;
b = (byte)(r / 1000000);
r %= 1000000;
c = (byte)(r / 100000);
r %= 100000;
d = (byte)(r / 10000);
r %= 10000;
e = (byte)(r / 1000);
r %= 1000;
f = (byte)(r / 100);
r %= 100;
g = (byte)(r / 10);
h = (byte)(r % 10);
/*
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
To convert the fractional component contained in bits 5-4 of OUT_P_LSB we use the upper byte of the
value and shift it to the left by two places. The resolution is in 0.25 Pascals we can compute the fractional
value by using the following table:
0 1 0.5
1 0 0.25
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
SCI_CharOut ('.');
/*
** Determine mantissa value
*/
result = 0;
value.Byte = data.Byte.hi;
if (value.Bit._5 == 1)
result += FRAC_2d1;
if (value.Bit._4 == 1)
result += FRAC_2d2;
/*
** Convert mantissa value to 2 decimal places
*/
r = result % 1000;
a = (byte)(result / 1000);
b = (byte)(r / 100);
r %= 100;
c = (byte)(r / 10);
d = (byte)(r % 10);
/*
** Output mantissa
*/
SCI_NibbOut (a);
SCI_NibbOut (b);
}
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
The conversion of the fractional component is done using the same methodology as in converting fractions
of a meter illustrated in Section 5.1, “Converting a 20-bit Altitude reading to a signed decimal number”.
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
/*
** Using a basic control loop, continously poll the sensor
*/
for (;;) {
/**
** Poll the
*/
RegisterFlag.Byte = IIC_RegRead(SlaveAddressIIC, DR_STATUS_00_REG);
if (RegisterFlag.PDR_BIT == 1)
if (RegisterFlag.TDR_BIT == 1) {
SCISendString(" Hex ");
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_MSB_REG);
a_mcsb_value.Byte.hi = temp;
SCI_ByteOut(temp);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_CSB_REG);
a_mcsb_value.Byte.lo = temp;
SCI_ByteOut(temp);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_LSB_REG);
a_dec_value.Byte.lo = 0x0;
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
/*
** Clear all interrupts by reading the output registers.
** Enable the Data Ready Interrupt and route to INT 1
** Activate sensor in Altimeter mode.
*/
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_CSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, F_STATUS);
/*
** Configure the INT pins for Open Drain and Active Low.
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG3, (PP_OD1_MASK | PP_OD2_MASK));
/*
** Write a 1 to the ALT and SBYB bits to go into Active Altimeter mode
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, (CTRL_REG_1_DATA | ALT _MASK |
ACTIVE_MASK));
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
CTRL_REG4
7 6 5 4 3 2 1 0
R
INT_EN_DRDY INT_EN_FIFO INT_EN_PW INTE_EN_TW INT_EN_PTH INT_EN_TTH INT_EN_PCHG INT_EN_TCHG
W
Reset 0 0 0 0 0 0 0 0
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
7 6 5 4 3 2 1 0
R
INT_CFG_DRDY INT_CFG_FIFO INT_CFG_PW INTE_CFG_TW INT_CFG_PTH INT_CFG_TTH INT_CFG_PCHG INT_CFG_TCHG
W
Reset 0 0 0 0 0 0 0 0
Example 14.
** Clear SBYB mask while holding all other values of CTRL_REG_1.
** To put part into Standby mode
*/
CTRL_REG_1_DATA = IIC_RegRead(SlaveAddressIIC, CTRL_REG1);
IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, CTRL_REG_1_DATA & STANDBY_SBYB_MASK);
/*
** Clear all interrupts by reading the output registers.
** Enable the Data Ready Interrupt and route to INT 1
** Activate sensor in Altimeter mode.
*/
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_CSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, F_STATUS);
/*
** Write Target and Window Values
** value[3] and value[4] are set to 0
*/
IIC_RegWrite(SlaveAddressIIC, P_TGT_MSB, value[1]);
IIC_RegWrite(SlaveAddressIIC, P_TGT_LSB, value[2]);
IIC_RegWrite(SlaveAddressIIC, P_TGT_WND_MSB, value[3]);
IIC_RegWrite(SlaveAddressIIC, P_TGT_WND_LSB, value[4]);
/*
** Enable Interrupt and Map to Interrupt Pin
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG4, INT_EN_PTH_MASK);
IIC_RegWrite(SlaveAddressIIC, CTRL_REG5, INT_CFG_PTH_MASK);
/*
** Write a 1 to the ALT and SBYB bits to go into Active Altimeter mode
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG1,(CTRL_REG_1_DATA | ALT_MASK | ACTIVE MASK));
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
/*
** Clear all interrupts by reading the output registers.
** Enable the Data Ready Interrupt and route to INT 1
** Activate sensor in Altimeter mode.
*/
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_CSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, F_STATUS);
/*
** Write Target and Window Values
** value[3] and value[4] are set to the offset
*/
IIC_RegWrite(SlaveAddressIIC, P_TGT_MSB, value[1]);
IIC_RegWrite(SlaveAddressIIC, P_TGT_LSB, value[2]);
IIC_RegWrite(SlaveAddressIIC, P_TGT_WND_MSB, value[3]);
IIC_RegWrite(SlaveAddressIIC, P_TGT_WND_LSB, value[4]);
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
/*
** Clear all interrupts by reading the output registers.
** Enable the Data Ready Interrupt and route to INT 1
** Activate sensor in Altimeter mode.
*/
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_CSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, F_STATUS);
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
/*
** Enable Interrupt and Map to Interrupt Pin
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG4, INT_EN_PW_MASK);
IIC_RegWrite(SlaveAddressIIC, CTRL_REG5, INT_CFG_PW_MASK);
/*
** Write a 1 to the ALT and SBYB bits to go into Active Altimeter mode
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG1,(CTRL_REG_1_DATA | ALT_MASK | ACTIVE_MASK));
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
/*
** Clear all interrupts by reading the output registers.
** Enable the Data Ready Interrupt and route to INT 1
** Activate sensor in Altimeter mode.
*/
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_CSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, F_STATUS);
/*
** Write Target and Window Values
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
/*
** Enable Interrupt and Map to Interrupt Pin
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG4, INT_EN_TTH_MASK);
IIC_RegWrite(SlaveAddressIIC, CTRL_REG5, INT_CFG_TTH_MASK);
/*
** Write a 1 to the SBYB bits to go into Active mode
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, (CTRL_REG_1_DATA | ACTIVE_MASK));
/*
** Clear all interrupts by reading the output registers.
** Enable the Data Ready Interrupt and route to INT 1
** Activate sensor in Altimeter mode.
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
/*
** Write Target and Window Values
** value[2] are set to the offset
*/
IIC_RegWrite(SlaveAddressIIC, T_TGT, value[1]);
IIC_RegWrite(SlaveAddressIIC, T_WND, value[2]);
/*
** Enable Interrupt and Map to Interrupt Pin
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG4, INT_EN_TTH_MASK);
IIC_RegWrite(SlaveAddressIIC, CTRL_REG5, INT_CFG_TTH_MASK);
/*
** Write a 1 to the SBYB bits to go into Active mode
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, (CTRL_REG_1_DATA | ACTIVE_MASK));
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
/*
** Clear all interrupts by reading the output registers.
** Enable the Data Ready Interrupt and route to INT 1
** Activate sensor in Altimeter mode.
*/
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_CSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, F_STATUS);
/*
** Write Target and Window Values
** value[1] and value[2] are set to the offset
*/
IIC_RegWrite(SlaveAddressIIC, T_TGT, value[1]);
IIC_RegWrite(SlaveAddressIIC, T_WND, value[2]);
/*
** Enable Interrupt and Map to Interrupt Pin
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG4, INT_EN_TW_MASK);
IIC_RegWrite(SlaveAddressIIC, CTRL_REG5, INT_CFG_TW_MASK);
/*
** Write a 1 to the SBYB bits to go into Active mode
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, (CTRL_REG_1_DATA | ACTIVE_MASK));
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
9.2 Summary
• The embedded FIFO is highly beneficial for system power savings and minimizing traffic across
the I2C bus.
• The FIFO allows for remarkable power savings of the system by allowing the host processor/MCU
to go into a sleep mode while the pressure sensor independently stores the data, up to 32 samples.
• The FIFO can be configured to be in a circular buffer mode or a fill buffer mode.
• The FIFO allows you to log data for up to 12 days using the highest ST setting of 9 hours.
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
F_SETUP
7 6 5 4 3 2 1 0
R
F_MODE1 F_MODE0 F_WMRK5 F_WMRK4 F_WMRK3 F_WMRK2 F_WMRK1 F_WMRK0
W
Reset 0 0 0 0 0 0 0 0
F_STATUS
7 6 5 4 3 2 1 0
Reset 0 0 0 0 0 0 0 0
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
7 6 5 4 3 2 1 0
R F_DATA
Reset 0 0 0 0 0 0 0 0
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
/*
** Clear all interrupts by reading the output registers.
** Enable the Data Ready Interrupt and route to INT 1
** Activate sensor in Altimeter mode.
*/
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_CSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_P_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_MSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, OUT_T_LSB_REG);
temp = IIC_RegRead(SlaveAddressIIC, F_STATUS);
/*
** Clear FIFO MODE by writing a 00 to F_MODE[1:0]
*/
IIC_RegWrite(SlaveAddressIIC, F_SETUP_REG, F_CLEAR_MASK);
/*
** Setup the FIFO to Overflow Mode
** Route to INT2
** Open Drain Active Low Interrupts
*/
/*
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
/******************************************************/
/* MPL3115A2 Interrupt Service Routine for the FIFO /
/******************************************************/
interrupt void isr_MPL3115A2 (void)
{
/*
** Clear the MCUs interrupt flag
*/
CLEAR_MPL3155A2_INTERRUPT;
/*
** Go read interrupt source register
*/
RegisterFlag.Byte = IIC_RegRead(SlaveAddressIIC, INT_SOURCE_REG);
if(RegisterFlag.SRC_FIFO_BIT == 1)
{
RegisterFlag.Byte = IIC_RegRead(SlaveAddressIIC, F_STATUS_REG);
/*
** Go read FIFO with a single multi-byte IIC access
*/
value[4] = (RegisterFlag.Byte & F_CNT_MASK) * 5;
IIC_RegReadN(SlaveAddressIIC, OUT_P_MSB_REG, value[4],
&fifo_data[0].Sample.BT.b_msb);
}
The interrupt routine dumps the FIFO into an array for further processing. This method is not ideal and is
used only to illustrate the multibyte read. The ideal method is to set a flag in the interrupt service routine
and then use a task or function to handle the flag.
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
/*
** Clear FIFO MODE by writing a 00 to F_MODE[1:0]
*/
IIC_RegWrite(SlaveAddressIIC, F_SETUP_REG, F_CLEAR_MASK);
/*
** Setup the FIFO to Watermark Mode
** Write a watermark value
** Route to INT2
** Open Drain Active Low Interrupts
*/
IIC_RegWrite(SlaveAddressIIC, CTRL_REG3, (PP_OD1_MASK | PP_OD2_MASK));
value[1] =0x05;
/*
** Put part into Active mode
*/
We use the same interrupt routine as the Overflow mode to dump the FIFO.
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
10.1 Modes
• M0 - Standby
• M1 - Active
• M2 - Altimeter
• M3 - Barometer
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
Time in
Power
Seconds
20 0
21 2
22 4
23 8
24 16
25 32
26 64
27 128
28 256
9
2 512
2A 1024
2B 2048
2C 4096
2D 8192
2E 16384
2F 32768
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
Data Manipulation and Basic Settings of the MPL3115A2 Command Line Interface Driver Code, Rev 0.1
Freescale, the Freescale logo, CodeWarrior and the Energy Efficient Solutions logo are
trademarks of Freescale Semiconductor, Inc., Reg. U.S. Pat. & Tm. Off. Xtrinsic is a
trademark of Freescale Semiconductor, Inc.
All other product or service names are the property of their respective owners.
AN4519
Rev 0.1
08/2012