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.
Fork of MPL3115A2 by
Diff: MPL3115A2.cpp
- Revision:
- 3:a2f1752add9a
- Parent:
- 2:a2fcfb7ff611
- Child:
- 4:fdf14a259af8
--- a/MPL3115A2.cpp Wed May 29 05:57:15 2013 +0000 +++ b/MPL3115A2.cpp Wed May 29 11:56:52 2013 +0000 @@ -9,9 +9,23 @@ #define REG_ALTIMETER_MSB 0x01 // 3 byte altimeter data #define REG_TEMP_MSB 0x04 // 2 byte temperature data #define REG_PT_DATA_CFG 0x13 +#define REG_P_TGT_MSB 0x16 +#define REG_P_WND_MSB 0x19 #define UINT14_MAX 16383 +/** Interrupt schema +* +* :: The Altitude Trigger use the IRQ1. +* +* Altitude Trigger -- MPL3115A2_Int1.fall --- AltitudeTrg_IRQ --- user1_fptr +* +* +* :: The Data ready use the IRQ2. +* +* Data Ready -- MPL3115A2_Int2.fall --- DataReady_IRQ --- user2_fptr +* +*/ void (*user2_fptr)(void); // Pointers to user function called after void (*user1_fptr)(void); // IRQ assertion. @@ -60,15 +74,14 @@ data[0] = REG_CTRL_REG_4; data[1] = 0x80; writeRegs(data, 2); - // Configure Interrupt route to INT2 + // Configure Interrupt to route to INT2 data[0] = REG_CTRL_REG_5; data[1] = 0x00; writeRegs(data, 2); /* - ** Write a 1 to the ALT and SBYB bits to go into Active Altimeter mode + ** Configure the OverSampling rate, Altimeter mode and set the sensor Active */ - // Configure the OverSampling rate, Altimeter mode and set the sensor Active data[0] = REG_CTRL_REG_1; data[1] = 0x81 | (OS<<3); writeRegs(data, 2); @@ -86,6 +99,56 @@ user2_fptr(); } +void MPL3115A2::AltitudeTrigger( void(*fptr)(void), unsigned short level) +{ + unsigned char dt[5]; + unsigned char data[2]; + + // Soft Reset + Reset(); + + // The device is on standby + Standby(); + + // Clear all interrupts by reading the output registers. + readRegs( REG_ALTIMETER_MSB, &dt[0], 5); + getStatus(); + + // Write Target and Window Values + data[0] = (level<<8); + data[1] = (level&0xFF); + writeRegs( data, 2); + + // Window values are zero + data[0] = 0; + data[1] = 0; + writeRegs( data, 2); + + // Enable Pressure Threshold interrupt + data[0] = REG_CTRL_REG_4; + data[1] = 0x08; + writeRegs( data, 2); + // Interrupt is routed to INT1 + data[0] = REG_CTRL_REG_5; + data[1] = 0x08; + writeRegs( data, 2); + + Active(); + + user1_fptr = fptr; + MPL3115A2_Int1.fall( this, &MPL3115A2::AltitudeTrg_IRQ); + +} + +void MPL3115A2::AltitudeTrg_IRQ( void) +{ + // Clear the IRQ flag + getStatus(); + // Run the user supplied function + user1_fptr(); + +} + void MPL3115A2::Barometric_Mode( void) { unsigned char t;