CPS_Lab*
/
AltTest2
Lab 7
Fork of AltTest2 by
main.cpp
- Committer:
- youngs2
- Date:
- 2018-03-02
- Revision:
- 3:93ba3e6cdaf3
- Parent:
- 2:126622942102
- Child:
- 4:eaaf67c5e1ca
File content as of revision 3:93ba3e6cdaf3:
#include "mbed.h" #include "MPL3115A2.h" #include <string.h> #include <stdlib.h> Serial pc(SERIAL_TX, SERIAL_RX); DigitalOut myled(LED1); MPL3115A2 pressure_sensor(PB_7,PB_6,0x60); /* char *int_array_to_string(uint8_t int_array[], int size_of_array) { char returnstring[size_of_array]; for (int temp = 0; temp < size_of_array; temp++) returnstring[temp] = itoa(int_array[temp]); return returnstring; } */ int MPL3115A2_reg_print(int start, int length) { if(length == 0) length = 45; int i = start, end = start + length; if(start > 0x2D || start < 0x00) return(-1); if(length < 0) return(-1); if (pressure_sensor.getID()!=0xC4) return(-1); if (end > 46) return(-1); printf("Hola\n\r"); uint8_t valArray[10]; //the array of register values we'll be returning for(int j = 0; j<10; j++) valArray[j] = 7; for( i = start; i <=end; i++) { char name[25]; switch (i) { case 0x00: strcpy(name,"MPL_STATUS"); break; case 0x01: strcpy(name,"MPL_OUT_P_MSB"); break; case 0x02: strcpy(name, "MPL_OUT_P_CSB"); break; case 0x03: strcpy(name,"MPL_OUT_P_LSB"); break; case 0x04: strcpy(name,"MPL_OUT_T_MSB"); break; case 0x05: strcpy(name,"MPL_OUT_T_LSB"); break; case 0x06: strcpy(name,"MPL_DR_STATUS"); break; case 0x07: strcpy(name,"MPL_OUT_P_DELTA_MSB"); break; case 0x08: strcpy(name,"MPL_OUT_P_DELTA_CSB"); break; case 0x09: strcpy(name,"MPL_OUT_P_DELTA_LSB"); break; case 0x0A: strcpy(name,"MPL_OUT_T_DELTA_MSB"); break; case 0x0B: strcpy(name,"MPL_OUT_T_DELTA_LSB"); break; case 0x0C: strcpy(name,"MPL_WHO_AM_I"); break; case 0x0D: strcpy(name,"MPL_F_STATUS"); break; case 0x0E: strcpy(name,"MPL_F_DATA"); break; case 0x0F: strcpy(name,"MPL_F_SETUP"); break; case 0x10: strcpy(name,"MPL_TIME_DLY"); break; case 0x11: strcpy(name,"MPL_SYSMOD"); break; case 0x12: strcpy(name,"MPL_INT_SOURCE"); break; case 0x13: strcpy(name,"MPL_PT_DATA_CFG"); break; case 0x14: strcpy(name,"MPL_BAR_IN_MSB"); break; case 0x15: strcpy(name,"MPL_BAR_IN_LSB"); break; case 0x16: strcpy(name,"MPL_P_TGT_MSB"); break; case 0x17: strcpy(name,"MPL_P_TGT_LSB"); break; case 0x18: strcpy(name,"MPL_T_TGT"); break; case 0x19: strcpy(name,"MPL_P_WND_MSB"); break; case 0x1A: strcpy(name,"MPL_P_WND_LSB"); break; case 0x1B: strcpy(name,"MPL_T_WND"); break; case 0x1C: strcpy(name,"MPL_P_MIN_MSB"); break; case 0x1D: strcpy(name,"MPL_P_MIN_CSB"); break; case 0x1E: strcpy(name,"MPL_P_MIN_LSB"); break; case 0x1F: strcpy(name,"MPL_T_MIN_MSB"); break; case 0x20: strcpy(name,"MPL_T_MIN_LSB"); break; case 0x21: strcpy(name,"MPL_P_MAX_MSB"); break; case 0x22: strcpy(name,"MPL_P_MAX_CSB"); break; case 0x23: strcpy(name,"MPL_P_MAX_LSB"); break; case 0x24: strcpy(name,"MPL_T_MAX_MSB"); break; case 0x25: strcpy(name,"MPL_T_MAX_LSB"); break; case 0x26: strcpy(name,"MPL_CTRL_REG1"); break; case 0x27: strcpy(name,"MPL_CTRL_REG2"); break; case 0x28: strcpy(name,"MPL_CTRL_REG3"); break; case 0x29: strcpy(name,"MPL_CTRL_REG4"); break; case 0x2A: strcpy(name,"MPL_CTRL_REG5"); break; case 0x2B: strcpy(name,"MPL_OFF_P"); break; case 0x2C: strcpy(name,"MPL_OFF_T"); break; case 0x2D: strcpy(name,"MPL_OFF_H"); break; default: printf("ERR\n\r"); } pressure_sensor.readRegs(i, valArray, 1); printf("0x%02X: %s = 0x%02x\n\r", i, name, valArray[0]); } return(0); } int main() { int start, length, return_val; uint8_t id; printf("Hola\n\r"); printf("Enter start: \n\r"); scanf("%d", &start); printf("Enter length: \n\r"); scanf("%d", &length); printf("Printing registers: \n\r"); return_val = MPL3115A2_reg_print(start, length); printf("%d\n\r", return_val); pc.printf("\n\r*** MPL3115A2 Pressure/Temperature Sensor Test *** \n\r"); while ((id=pressure_sensor.getID())!=0xC4) { pc.printf("Status read unsuccessful: Value = 0x%02x\n\r",id); pc.printf("Check wiring to the pressure sensor\n\r",id); pc.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); } //no return; while(1) never exited }