64 return (status & 0x01) ? 1 : 0;
109 char altpbyte[3] = {0x00};
111 int m_altitude = altpbyte[0];
112 int c_altitude = altpbyte[1];
113 int l_altitude = altpbyte[2];
114 uint32_t al = (m_altitude << 24)|(c_altitude < 16)| (l_altitude);
115 return (
float)(al/65536);
125 if((H_Offset > -128) || (H_Offset < 128))
152 if((P_Offset > -128) || (P_Offset < 128))
164 char minPressure[3] = {0x00};
167 unsigned char m_altitude = minPressure[0];
168 unsigned char c_altitude = minPressure[1];
169 float l_altitude = (float)(minPressure[2]>>4)/4;
170 return((
float)(m_altitude<<10 | c_altitude<<2)+l_altitude);
180 char maxPressure[3] = {0x00};
183 unsigned char m_altitude = maxPressure[0];
184 unsigned char c_altitude = maxPressure[1];
185 float l_altitude = (float)(maxPressure[2]>>4)/4;
186 return((
float)(m_altitude<<10 | c_altitude<<2)+l_altitude);
198 return ((barMSB << 8) | barLSB);
208 char pbyte[3] = {0x00};
211 if((status & (1<<
PDR)) == 0)
219 unsigned long m_altitude = pbyte[0];
220 unsigned long c_altitude = pbyte[1];
221 float l_altitude = (float)(pbyte[2]>>4)/4;
222 return((
float)(m_altitude<<10 | c_altitude<<2)+l_altitude);
237 return pressure * 0.000145037738;
239 return pressure * 0.00029529983071;
241 return pressure * 0.007500615613;
253 unsigned char threshMSB = (
unsigned char) (thresh << 8);
254 unsigned char threshLSB = (
unsigned char) thresh;
267 unsigned char tmpMSB = (
unsigned char) (window << 8);
268 unsigned char tmpLSB = (
unsigned char) (window);
272 tmpMSB = (
unsigned char) (target << 8);
273 tmpLSB = (
unsigned char) (target);
284 char temperature[2] = {0x00};
287 float templsb = (temperature[1]>>4) / 16.0;
288 float unpacked = (float)(temperature[0] + templsb);
299 char temperature[2] = {0x00};
302 float templsb = (temperature[1]>>4) / 16.0;
303 float minTemp = (float)(temperature[0] + templsb);
314 char temperature[2] = {0x00};
317 float templsb = (temperature[1]>>4) / 16.0;
318 float maxTemp = (float)(temperature[0] + templsb);
364 ctrl_reg &= ~(1 <<
SBYB);
367 if(sampleRate > 7) sampleRate = 7;
371 ctrl_reg |= sampleRate;
383 ctrl_reg &= ~(1 <<
SBYB);
410 tempSetting &= ~(1<<1);
413 tempSetting |= (1<<1);
float MPL3115A2_ReadPressure(unitsType units)
Get a barometric pressure reading.
void MPL3115A2_SetPressureAlarmThreshold(unsigned int thresh)
Configure alarm threshold.
unsigned char buffer[256]
unsigned char MPL3115A2_ID(void)
Returns the Factory Chip ID.
void MPL3115A2_SetTempTargetWindow(unsigned int target, unsigned int window)
Configures the temperature target and window for the interrupts.
void MPL3115A2_WriteByteArray(char reg, char *buffer, unsigned int length)
Writes an array of bytes to the sensor.
float MPL3115A2_ReadTemperature(void)
Get a temperature reading from the sensor.
void MPL3115A2_WriteByte(char reg, char value)
Write a single byte to the register.
float MPL3115A2_ReadAltitude(void)
Returns the number of meters above sea level,Returns -1 if no new data is available.
void MPL3115A2_BarometerMode(void)
Configure the sensor in Barometer mode.
void MPL3115A2_ConfigurePressureInterrupt(void)
Configure Pressure Interrupt.
void MPL3115A2_ClearInterrupts(void)
Clear any existing interrupts.
void MPL3115A2_ToggleOneShot(void)
Causes the sensor to immediately take another reading , needed to sample faster than 1Hz...
void I2C_WriteByteArray(char reg, char *data, unsigned int length)
Writes a buffer array to the registers.
void MPL3115A2_SetPressureOffset(unsigned char P_Offset)
Set the pressure offset correction.
void MPL3115A2_SetAcquisitionTimeStep(unsigned char ST_Value)
Set the acquisition time step in seconds.
float MPL3115A2_GetMinimumPressure(void)
Get minimum stored pressure.
void I2C_WriteByteRegister(unsigned char reg, unsigned char data)
Writes a byte value to a register address.
float MPL3115A2_GetMinimumTemperature(void)
Get minimum recorded temperature reading.
unsigned char MPL3115A2_GetMode(void)
Return a bool value indicating wheather the sensor is in Active or Standby mode.
float MPL3115A2_ReadBarometricPressure(void)
Reads the current pressure in Pa.
void MPL3115A2_SetTempOffset(char T_Offset)
Used to correct the measured sensor temeperature by a particular offset.
void MPL3115A2_ConfigureInterruptPin(unsigned char intrrpt, unsigned char pin)
Configure Interrupt pins.
void MPL3115A2_Initialize(void)
Initialize the sensor and enable interrupts.
void MPL3115A2_SetTemperatureThreshold(unsigned char thresh)
Configure the temeperature threshold.
void MPL3115A2_EnableEventFlags(void)
Enables the pressure and temp measurement event flags so that we can test against them...
void MPL3115A2_ReadByteArray(char reg, char *buffer, unsigned int length)
Read byte value from register.
void MPL3115A2_AltimeterMode(void)
Sets the mode to Altimeter.
void MPL3115A2_SetAltimeterOffset(unsigned char H_Offset)
Set the altimeter offset correction.
float MPL3115A2_GetMaximumTemperature(void)
Get maximum recorded temperature reading.
unsigned char I2C_ReadByteRegister(char reg)
Reads a byte from a register.
void MPL3115A2_ActiveMode(void)
Puts the sensor in active mode, needed is the sensor is in standby mode.
void MPL3115A2_StandbyMode(void)
Puts the sensor in standby mode, the user must do this in order to modify the major control registers...
void MPL3115A2_SetPressureTargetWindow(unsigned int target, unsigned int window)
Configure alarm target and window.
void MPL3115A2_OutputSampleRate(unsigned char sampleRate)
Configures the output sample rate.The higher the oversample rate the greater the time between data sa...
unsigned char MPL3115A2_ReadByte(char reg)
Read byte value from register.
unsigned int MPL3115A2_ReadBarometicPressureInput(void)
Returns barometric pressure input used for calculating altitude.
void I2C_ReadByteArray(char reg, char *buffer, unsigned int length)
Initializes the I2C peripheral.
float MPL3115A2_GetMaximumPressure(void)
Get maximum stored pressure.
void MPL3115A2_ConfigureAltitudeInterrupt(void)
Configure altitude interrupt pin.