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.
Diff: lab7.cpp
- Revision:
- 3:9f3053336250
- Parent:
- 2:7c190ac7f4d4
- Child:
- 4:1b449b5bbfe4
--- a/lab7.cpp Tue Feb 27 15:49:35 2018 +0000
+++ b/lab7.cpp Thu Mar 01 15:44:10 2018 +0000
@@ -1,28 +1,48 @@
#include "mbed.h"
#include <iostream>
-#include <MPL3115.h>
+#include "MPL3115A2.h"
-// Interface pulled from MPL3115.cpp
-// MPL3115::MPL3115(PinName sda, PinName scl) : MPL3115_i2c(sda,scl)
-MPL3115 mpl3115(PB_7, PB_6);
+Serial pc(SERIAL_TX, SERIAL_RX);
+DigitalOut myled(LED1);
+//Selects SDA as I2C1_SDA on pin PB_7
+//Selects SCL on I2C1_SCL on pin PB_6
+//the I2c address of the pressure sensor is fixed at 0x60
+MPL3115A2 pressure_sensor(PB_7, PB_6, 0x60);
+
int mpl3115_reg_print(int start, int length);
void register_map(int i, int value);
+
+
int main() {
- MPL3115 mpl3115_config();
+ uint8_t id;
+ printf("\n\rMPL3115A2 test\n\r");
+ while((id = pressure_sensor.getID()) != 0xC4) {
+ printf("Status read unsuccessful: Value = 0x%02x\n\r",id);
+ printf("Check wiring to the pressure sensor\n\r");
+ printf("Retesting for correct ID in 1 second...\n\r");
+ wait(1);
+
+ }
+ pc.printf("Status read successfully: Value = 0x%02x\n\r",id);
+ pc.printf("***1hz readings from the pressure sensor***\n\r");
+ while(1) {
+ pc.printf("%f hPA; %f m\n\r",pressure_sensor.getPressure(),pressure_sensor.getAltitude());
+ myled = !myled;
+ wait(1);
+ }
+
- printf("start\r\n");
+ /*printf("start\r\n");
mpl3115_reg_print(0, 0);
printf("finish\r\n");
- return(0);
+ return(0);*/
+
}
int mpl3115_reg_print(int start, int length) {
- //if(mpl3115.read_reg(MPL3115::WHO_AM_I) != 0xC4) {
- // printf("chip is not connected\r\n");
- // return -1;
- //}
+
printf("Success, chip is connected.\r\n");
int l = 0;
@@ -32,11 +52,7 @@
printf("illegal input exception\r\n");
return -1;
}
- /*
- for(int i = start; i < l; i++) {
- //printf();
- register_map());
- }*/
+
//printf("Reg Address %d: Register Name = %s", address, name)
return 0;