Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: KL25Z_Batt_Test WIGO_MPL3115A2 Multi-Sensor SPACEmk2 ... more
MPL3115A2.h
- Committer:
- clemente
- Date:
- 2013-08-22
- Revision:
- 6:03c24251e500
- Parent:
- 5:9edec5ee8bf4
- Child:
- 8:89ed6aeb5dbb
File content as of revision 6:03c24251e500:
#ifndef MPL3115A2_H
#define MPL3115A2_H
#include "mbed.h"
// Oversampling value and minimum time between sample
#define OVERSAMPLE_RATIO_1 0 // 6 ms
#define OVERSAMPLE_RATIO_2 1 // 10 ms
#define OVERSAMPLE_RATIO_4 2 // 18 ms
#define OVERSAMPLE_RATIO_8 3 // 34 ms
#define OVERSAMPLE_RATIO_16 4 // 66 ms
#define OVERSAMPLE_RATIO_32 5 // 130 ms
#define OVERSAMPLE_RATIO_64 6 // 258 ms
#define OVERSAMPLE_RATIO_128 7 // 512 ms
/* Mode */
#define ALTIMETER_MODE 1
#define BAROMETRIC_MODE 2
/**
* MPL3115A2 Altimeter example
*
* @code
* #include "mbed.h"
* #include "MPL3115A2.h"
*
* #define MPL3115A2_I2C_ADDRESS (0x60<<1)
* MPL3115A2 wigo_sensor1(PTE0, PTE1, MPL3115A2_I2C_ADDRESS);
* Serial pc(USBTX, USBRX);
*
* // pos [0] = altitude or pressure value
* // pos [1] = temperature value
* float sensor_data[2];
*
* int main(void) {
*
* pc.baud( 230400);
* pc.printf("MPL3115A2 Altimeter mode. [%d]\r\n", wigo_sensor1.getDeviceID());
*
* wigo_sensor1.Oversample_Ratio( OVERSAMPLE_RATIO_32);
*
* while(1) {
* //
* if ( wigo_sensor1.isDataAvailable()) {
* wigo_sensor1.getAllData( &sensor_data[0]);
* pc.printf("\tAltitude: %f\tTemperature: %f\r\n", sensor_data[0], sensor_data[1]);
* }
* //
* wait( 0.001);
* }
*
* }
* @endcode
*/
class MPL3115A2
{
public:
/**
* MPL3115A2 constructor
*
* @param sda SDA pin
* @param sdl SCL pin
* @param addr addr of the I2C peripheral
*/
MPL3115A2(PinName sda, PinName scl, int addr);
/**
* Get the value of the WHO_AM_I register
*
* @returns DEVICE_ID value == 0xC4
*/
uint8_t getDeviceID();
/**
* Return the STATUS register value
*
* @returns STATUS register value
*/
unsigned char getStatus( void);
/**
* Get the altimeter value
*
* @returns altimeter value as float
*/
float getAltimeter( void);
/**
* Get the altimeter value in raw mode
*
* @param dt pointer to unsigned char array
* @returns 1 if data are available, 0 if not.
*/
unsigned int getAltimeterRaw( unsigned char *dt);
/**
* Get the pressure value
*
* @returns pressure value as float
*/
float getPressure( void);
/**
* Get the pressure value in raw mode
*
* @param dt pointer to unsigned char array
* @returns 1 if data are available, 0 if not.
*/
unsigned int getPressureRaw( unsigned char *dt);
/**
* Get the temperature value
*
* @returns temperature value as float
*/
float getTemperature( void);
/**
* Get the temperature value in raw mode
*
* @param dt pointer to unsigned char array
* @returns 1 if data are available, 0 if not.
*/
unsigned int getTemperatureRaw( unsigned char *dt);
/**
* Set the Altimeter Mode
*
* @returns none
*/
void Altimeter_Mode( void);
/**
* Set the Barometric Mode
*
* @returns none
*/
void Barometric_Mode( void);
/**
* Get the altimeter or pressure and temperature values
*
* @param array of float f[2]
* @returns 0 no data available, 1 for data available
*/
unsigned int getAllData( float *f);
/**
* Get the altimeter or pressure, and temperature values in raw mode
*
* @param array of unsigned char[5]
* @returns 1 if data are available, 0 if not.
*/
unsigned int getAllDataRaw( unsigned char *dt);
/**
* Return if there are date available
*
* @return 0 for no data available, bit0 set for Temp data available, bit1 set for Press/Alti data available
* bit2 set for both Temp and Press/Alti data available
*/
unsigned int isDataAvailable( void);
/**
* Set the oversampling rate value
*
* @param oversampling values. See MPL3115A2.h
* @return none
*/
void Oversample_Ratio( unsigned int ratio);
/**
* Configure the sensor to streaming data using Interrupt
*
* @param user functin callback, oversampling values. See MPL3115A2.h
* @return none
*/
void DataReady( void(*fptr)(void), unsigned char OS);
/**
* Configure the sensor to generate an Interrupt crossing the center threshold
*
* @param user functin callback, level in meter
* @return none
*/
void AltitudeTrigger( void(*fptr)(void), unsigned short level);
/**
* Soft Reset
*
* @param none
* @return none
*/
void Reset( void);
private:
I2C m_i2c;
int m_addr;
unsigned char MPL3115A2_mode;
unsigned char MPL3115A2_oversampling;
void DataReady_IRQ( void);
void AltitudeTrg_IRQ( void);
/** Set the device in active mode
*/
void Active( void);
/** Set the device in standby mode
*/
void Standby( void);
void readRegs(int addr, uint8_t * data, int len);
void writeRegs(uint8_t * data, int len);
};
#endif
NXP MPL3115A2 Altimeter