Llibrary for the WiGo MPL3115A2, I2C Precision Altimeter sensor.

Dependents:   KL25Z_Batt_Test WIGO_MPL3115A2 Multi-Sensor SPACEmk2 ... more

30/05/2013 Added and tested the data acquisition using Interrupt. Added code for Altimeter trigger Interrupt but not yet tested.

Very basic library. Under development. Need to add in order: 1. IRQ configuration. 2. FIFO mode configuration.

MPL3115A2.h

Committer:
clemente
Date:
2013-05-23
Revision:
0:cfecfabc5e23
Child:
1:30a04f651efe

File content as of revision 0:cfecfabc5e23:

#ifndef MPL3115A2_H
#define MPL3115A2_H

#include "mbed.h"

/* Oversampling */
#define OVERSAMPLE_RATIO_1      0
#define OVERSAMPLE_RATIO_2      1
#define OVERSAMPLE_RATIO_4      2
#define OVERSAMPLE_RATIO_8      3
#define OVERSAMPLE_RATIO_16     4
#define OVERSAMPLE_RATIO_32     5
#define OVERSAMPLE_RATIO_64     6
#define OVERSAMPLE_RATIO_128    7

/* 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 altimeter(PTE0, PTE1, MPL3115A2_I2C_ADDRESS);
* Serial pc(USBTX, USBRX);
*
* 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("\Altitude: %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 pressure value
*
* @returns pressure value as float
*/
float getPressure( void);

/**
* Get the temperature value
*
* @returns temperature value as float
*/
float getTemperature( void);

/**
* Set the Altimeter Mode
*
* @returns none
*/
void Altimeter_Mode( void);

/**
* Set the Barometric Mode
*
* @returns none
*/
void Barometric_Mode( void);

/**
* Get the altimeter, pressure and temperature values
*
* @param array of float f[3]
* @returns none
*/
void getAllData( float *f);

/** Return is there are date available
* 
* @return 1 for data available, 0 for no 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);

private:
  I2C m_i2c;
  int m_addr;
  unsigned char MPL3115A2_mode;
  unsigned char MPL3115A2_oversampling;
  
  /** 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