Lucas Lim / Mbed 2 deprecated HSP_Temperature_Barometer_CS3237

Dependencies:   mbed

Committer:
lucaslwl
Date:
Fri Aug 23 16:18:23 2019 +0000
Revision:
20:652f0bf256bd
Parent:
18:b64938c813dc
Child:
21:de62f413b500
.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dan 0:7dec7e9ac085 1 #include "mbed.h"
switches 14:4c4094890fde 2 #include "MAX14720.h"
lucaslwl 20:652f0bf256bd 3 #include "MAX30205.h"
lucaslwl 20:652f0bf256bd 4 #include "MAX30101.h"
lucaslwl 20:652f0bf256bd 5 #include "BMP280.h"
lucaslwl 20:652f0bf256bd 6 #include "MAX30001.h"
lucaslwl 20:652f0bf256bd 7 #include "QuadSpiInterface.h"
lucaslwl 20:652f0bf256bd 8 #include "S25FS512.h"
switches 14:4c4094890fde 9
lucaslwl 20:652f0bf256bd 10 //Define all I2C addresses
lucaslwl 20:652f0bf256bd 11 #define MAX30205_I2C_SLAVE_ADDR_TOP (0x92)
lucaslwl 20:652f0bf256bd 12 #define MAX30205_I2C_SLAVE_ADDR_BOTTOM (0x90)
lucaslwl 20:652f0bf256bd 13 #define MAX14720_I2C_SLAVE_ADDR (0x54)
lucaslwl 20:652f0bf256bd 14 #define MAX30101_I2C_SLAVE_ADDR (0xAE)
lucaslwl 20:652f0bf256bd 15 #define BMP280_I2C_SLAVE_ADDR (0xEC)
lucaslwl 20:652f0bf256bd 16 #define MAX30001_
lucaslwl 20:652f0bf256bd 17
lucaslwl 20:652f0bf256bd 18 #define HVOUT_VOLTAGE 4500 // set to 4500 mV
lucaslwl 20:652f0bf256bd 19
lucaslwl 20:652f0bf256bd 20 // I2C Masters
lucaslwl 20:652f0bf256bd 21 I2C i2c1(I2C1_SDA, I2C1_SCL);
switches 14:4c4094890fde 22 I2C i2c2(I2C2_SDA, I2C2_SCL);
dan 0:7dec7e9ac085 23
lucaslwl 20:652f0bf256bd 24 /// SPI Master 0 with SPI0_SS for use with MAX30001
lucaslwl 20:652f0bf256bd 25 SPI spi(SPI0_MOSI, SPI0_MISO, SPI0_SCK, SPI0_SS); // used by MAX30001
lucaslwl 20:652f0bf256bd 26 /// SPI Master 1
lucaslwl 20:652f0bf256bd 27 QuadSpiInterface quadSpiInterface(SPI1_MOSI, SPI1_MISO, SPI1_SCK,
lucaslwl 20:652f0bf256bd 28 SPI1_SS); // used by S25FS512
lucaslwl 20:652f0bf256bd 29
lucaslwl 20:652f0bf256bd 30
lucaslwl 20:652f0bf256bd 31 // Top local Temperature Sensor
lucaslwl 20:652f0bf256bd 32 MAX30205 MAX30205_top(&i2c1, MAX30205_I2C_SLAVE_ADDR_TOP);
lucaslwl 20:652f0bf256bd 33
lucaslwl 20:652f0bf256bd 34 // Botttom local Temperature Sensor
lucaslwl 20:652f0bf256bd 35 MAX30205 MAX30205_bottom(&i2c1, MAX30205_I2C_SLAVE_ADDR_BOTTOM);
lucaslwl 20:652f0bf256bd 36
lucaslwl 20:652f0bf256bd 37 // Barometric Pressure Sensor
lucaslwl 20:652f0bf256bd 38 BMP280 bmp280_pres(&i2c1, BMP280_I2C_SLAVE_ADDR);
lucaslwl 20:652f0bf256bd 39
lucaslwl 20:652f0bf256bd 40 //PMIC
lucaslwl 20:652f0bf256bd 41 MAX14720 max14720(&i2c2,MAX14720_I2C_SLAVE_ADDR);
lucaslwl 20:652f0bf256bd 42
lucaslwl 20:652f0bf256bd 43 // Optical Oximeter
lucaslwl 20:652f0bf256bd 44 MAX30101 max30101(&i2c2, MAX30101_I2C_SLAVE_ADDR);
lucaslwl 20:652f0bf256bd 45
lucaslwl 20:652f0bf256bd 46 /// External Flash
lucaslwl 20:652f0bf256bd 47 S25FS512 s25fs512(&quadSpiInterface);
lucaslwl 20:652f0bf256bd 48
lucaslwl 20:652f0bf256bd 49 /// ECG device
lucaslwl 20:652f0bf256bd 50 MAX30001 max30001(&spi);
lucaslwl 20:652f0bf256bd 51 InterruptIn max30001_InterruptB(P3_6);
lucaslwl 20:652f0bf256bd 52 InterruptIn max30001_Interrupt2B(P4_5);
lucaslwl 20:652f0bf256bd 53
lucaslwl 20:652f0bf256bd 54 /// PWM used as fclk for the MAX30001
lucaslwl 20:652f0bf256bd 55 PwmOut pwmout(P1_7);
lucaslwl 20:652f0bf256bd 56
switches 14:4c4094890fde 57
switches 14:4c4094890fde 58 DigitalOut led(LED1);
lucaslwl 20:652f0bf256bd 59
lucaslwl 20:652f0bf256bd 60 //Serial
lucaslwl 20:652f0bf256bd 61 Serial pc(USBTX, USBRX);
lucaslwl 20:652f0bf256bd 62 InterruptIn Button(SW1);
switches 14:4c4094890fde 63
switches 14:4c4094890fde 64 void turnOff()
switches 14:4c4094890fde 65 {
lucaslwl 20:652f0bf256bd 66 //write the power down command to PMIC
lucaslwl 20:652f0bf256bd 67 max14720.shutdown();
switches 14:4c4094890fde 68 }
switches 14:4c4094890fde 69 int main()
switches 14:4c4094890fde 70 {
lucaslwl 20:652f0bf256bd 71
switches 17:9a467f9a0579 72 // Override the default value of boostEn to BOOST_ENABLED
switches 14:4c4094890fde 73 max14720.boostEn = MAX14720::BOOST_ENABLED;
switches 17:9a467f9a0579 74 // Note that writing the local value does directly affect the part
switches 17:9a467f9a0579 75 // The buck-boost regulator will remain off until init is called
lucaslwl 20:652f0bf256bd 76 max14720.init();
lucaslwl 20:652f0bf256bd 77 // Turn LED signal on to make buck-boost output visible
lucaslwl 20:652f0bf256bd 78 max14720.boostSetVoltage(HVOUT_VOLTAGE);
lucaslwl 20:652f0bf256bd 79 led = 0;
lucaslwl 20:652f0bf256bd 80
lucaslwl 20:652f0bf256bd 81 // Initialise the BMP280
lucaslwl 20:652f0bf256bd 82 bmp280_pres.init(BMP280::OVERSAMPLING_X16_P, BMP280::OVERSAMPLING_X2_T, BMP280::FILT_4, BMP280::NORMAL_MODE, BMP280::T_62_5);
switches 17:9a467f9a0579 83
lucaslwl 20:652f0bf256bd 84 // MAX30001
lucaslwl 20:652f0bf256bd 85 printf("Init MAX30001 callbacks, interrupts...\n");
lucaslwl 20:652f0bf256bd 86 fflush(stdout);
lucaslwl 20:652f0bf256bd 87 max30001_InterruptB.disable_irq();
lucaslwl 20:652f0bf256bd 88 max30001_Interrupt2B.disable_irq();
lucaslwl 20:652f0bf256bd 89 max30001_InterruptB.mode(PullUp);
lucaslwl 20:652f0bf256bd 90 max30001_InterruptB.fall(&MAX30001::Mid_IntB_Handler);
lucaslwl 20:652f0bf256bd 91 max30001_Interrupt2B.mode(PullUp);
lucaslwl 20:652f0bf256bd 92 max30001_Interrupt2B.fall(&MAX30001::Mid_Int2B_Handler);
lucaslwl 20:652f0bf256bd 93 max30001_InterruptB.enable_irq();
lucaslwl 20:652f0bf256bd 94 max30001_Interrupt2B.enable_irq();
lucaslwl 20:652f0bf256bd 95 max30001.AllowInterrupts(1);
lucaslwl 20:652f0bf256bd 96 // Configuring the FCLK for the ECG, set to 32.768KHZ
lucaslwl 20:652f0bf256bd 97 printf("Init MAX30001 PWM...\n");
lucaslwl 20:652f0bf256bd 98 fflush(stdout);
lucaslwl 20:652f0bf256bd 99 //pwmout.period_us(31);
lucaslwl 20:652f0bf256bd 100 //pwmout.write(0.5); // 0-1 is 0-100%, 0.5 = 50% duty cycle.
lucaslwl 20:652f0bf256bd 101 max30001.FCLK_MaximOnly(); // mbed does not provide the resolution necessary, so for now we have a specific solution...
lucaslwl 20:652f0bf256bd 102 max30001.sw_rst(); // Do a software reset of the MAX30001
lucaslwl 20:652f0bf256bd 103 max30001.INT_assignment(MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, MAX30001::MAX30001_NO_INT, // en_enint_loc, en_eovf_loc, en_fstint_loc,
lucaslwl 20:652f0bf256bd 104 MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_NO_INT, // en_dcloffint_loc, en_bint_loc, en_bovf_loc,
lucaslwl 20:652f0bf256bd 105 MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_NO_INT, // en_bover_loc, en_bundr_loc, en_bcgmon_loc,
lucaslwl 20:652f0bf256bd 106 MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, MAX30001::MAX30001_NO_INT, // en_pint_loc, en_povf_loc, en_pedge_loc,
lucaslwl 20:652f0bf256bd 107 MAX30001::MAX30001_INT_2B, MAX30001::MAX30001_INT_B, MAX30001::MAX30001_NO_INT, // en_lonint_loc, en_rrint_loc, en_samp_loc,
lucaslwl 20:652f0bf256bd 108 MAX30001::MAX30001_INT_ODNR, MAX30001::MAX30001_INT_ODNR); // intb_Type, int2b_Type)
lucaslwl 20:652f0bf256bd 109 max30001.onDataAvailable(&StreamPacketUint32);
switches 17:9a467f9a0579 110
lucaslwl 20:652f0bf256bd 111
switches 17:9a467f9a0579 112
lucaslwl 20:652f0bf256bd 113 // Use the POR configuration register values
lucaslwl 20:652f0bf256bd 114
lucaslwl 20:652f0bf256bd 115 //Temperature sensor variables
lucaslwl 20:652f0bf256bd 116 uint16_t rawTemp_top;
lucaslwl 20:652f0bf256bd 117 uint16_t rawTemp_bottom ;
lucaslwl 20:652f0bf256bd 118 float celsius_top, celsius_bottom;
lucaslwl 20:652f0bf256bd 119 float fahrenheit_top, fahrenheit_bottom;
lucaslwl 20:652f0bf256bd 120
lucaslwl 20:652f0bf256bd 121 //barometric sensor variables
lucaslwl 20:652f0bf256bd 122 char bmp280_rawData = 0;
lucaslwl 20:652f0bf256bd 123 float Temp_degC, Press_Pa, Press_Bar;
lucaslwl 20:652f0bf256bd 124
lucaslwl 20:652f0bf256bd 125 //optical sensor variables
lucaslwl 20:652f0bf256bd 126 uint8_t fifo_waterlevel_mark;
lucaslwl 20:652f0bf256bd 127 uint8_t sample_avg;
lucaslwl 20:652f0bf256bd 128 uint8_t sample_rate;
lucaslwl 20:652f0bf256bd 129 uint8_t pulse_width;
lucaslwl 20:652f0bf256bd 130 uint8_t fifo_waterlevel_mark1;
lucaslwl 20:652f0bf256bd 131 uint8_t sample_avg1;
lucaslwl 20:652f0bf256bd 132 uint8_t sample_rate1;
lucaslwl 20:652f0bf256bd 133 uint8_t pulse_width1;
lucaslwl 20:652f0bf256bd 134 uint8_t fifo_waterlevel_mark2;
lucaslwl 20:652f0bf256bd 135 uint8_t sample_avg2;
lucaslwl 20:652f0bf256bd 136 uint8_t sample_rate2;
lucaslwl 20:652f0bf256bd 137 uint8_t pulse_width2;
lucaslwl 20:652f0bf256bd 138 uint8_t red_led_current, green_led_current;
lucaslwl 20:652f0bf256bd 139 uint8_t ir_led_current;
lucaslwl 20:652f0bf256bd 140 uint8_t slot_1, slot_2, slot_3, slot_4;
lucaslwl 20:652f0bf256bd 141
lucaslwl 20:652f0bf256bd 142 wait(2);
lucaslwl 20:652f0bf256bd 143
lucaslwl 20:652f0bf256bd 144 //Endless loop
lucaslwl 20:652f0bf256bd 145 while(1)
lucaslwl 20:652f0bf256bd 146 {
lucaslwl 20:652f0bf256bd 147 /* Temperature Sensor Settings */
lucaslwl 20:652f0bf256bd 148
lucaslwl 20:652f0bf256bd 149 //Read Temperature
lucaslwl 20:652f0bf256bd 150 MAX30205_top.readTemperature(&rawTemp_top);
lucaslwl 20:652f0bf256bd 151 MAX30205_bottom.readTemperature(&rawTemp_bottom);
lucaslwl 20:652f0bf256bd 152 // Read BMP280 Temp. and Pressure
lucaslwl 20:652f0bf256bd 153 bmp280_pres.ReadCompDataRaw(&bmp280_rawData);
lucaslwl 20:652f0bf256bd 154 bmp280_pres.ToFloat(&bmp280_rawData, &Temp_degC, &Press_Pa);
lucaslwl 20:652f0bf256bd 155 // Convert to Celsius
lucaslwl 20:652f0bf256bd 156 celsius_top = MAX30205_top.toCelsius(rawTemp_top);
lucaslwl 20:652f0bf256bd 157 celsius_bottom = MAX30205_bottom.toCelsius(rawTemp_bottom);
lucaslwl 20:652f0bf256bd 158
lucaslwl 20:652f0bf256bd 159 // Convert to Fahrenheit
lucaslwl 20:652f0bf256bd 160 fahrenheit_top = MAX30205_top.toFahrenheit(celsius_top);
lucaslwl 20:652f0bf256bd 161 fahrenheit_bottom = MAX30205_bottom.toFahrenheit(celsius_bottom);
lucaslwl 20:652f0bf256bd 162
lucaslwl 20:652f0bf256bd 163
lucaslwl 20:652f0bf256bd 164 /* Barometric Sensor Settings */
lucaslwl 20:652f0bf256bd 165
lucaslwl 20:652f0bf256bd 166 Press_Bar = Press_Pa / 100000;
lucaslwl 20:652f0bf256bd 167
lucaslwl 20:652f0bf256bd 168 /* Optical Sensor settings */
lucaslwl 20:652f0bf256bd 169
lucaslwl 20:652f0bf256bd 170
switches 17:9a467f9a0579 171
lucaslwl 20:652f0bf256bd 172 /* Printing various sensor values */
lucaslwl 20:652f0bf256bd 173 pc.printf("***** MAX30205 Temperature Sensor Reading *****\n\r");
lucaslwl 20:652f0bf256bd 174 pc.printf("Top Temperature: %.2f\370 C\n\rBottom Temperature: %.2f\370 C \n\rTop Temperature in Farenheit: %.2f\370 F\n\rBottom Temperature in Farenheit %.2f\370 F\n\n\r", celsius_top, celsius_bottom, fahrenheit_top, fahrenheit_bottom);
lucaslwl 20:652f0bf256bd 175
lucaslwl 20:652f0bf256bd 176 pc.printf("***** BMP280 Barometric Sensor Reading *****\n\r");
lucaslwl 20:652f0bf256bd 177 pc.printf("Temp_degC : %.2f , Press_Bar is %.2f , Press_pa is %.2f\n\n\r",Temp_degC, Press_Bar, Press_Pa);
lucaslwl 20:652f0bf256bd 178
lucaslwl 20:652f0bf256bd 179 max30101.HRmode_init(fifo_waterlevel_mark1,sample_avg1,sample_rate1,pulse_width1,red_led_current);
lucaslwl 20:652f0bf256bd 180 pc.printf("***** MAX30101 Optical Sensor Reading [HR mode]*****\n\r");
lucaslwl 20:652f0bf256bd 181 pc.printf("Optical Sensor Value [fifo_waterlevel_mark: %d]\n\rOptical Sensor Value[sample_avg: %d]\n\rOptical Sensor Value[pulse_width: %d]\n\n\r", fifo_waterlevel_mark,sample_avg,pulse_width);
lucaslwl 20:652f0bf256bd 182 max30101.HRmode_stop();
lucaslwl 20:652f0bf256bd 183
lucaslwl 20:652f0bf256bd 184 max30101.SpO2mode_init(fifo_waterlevel_mark, sample_avg, sample_rate, pulse_width, red_led_current, ir_led_current);
lucaslwl 20:652f0bf256bd 185 pc.printf("***** MAX30101 Optical Sensor Reading [SpO2 mode]*****\n\r");
lucaslwl 20:652f0bf256bd 186 pc.printf("Optical Sensor Value [fifo_waterlevel_mark: %d]\n\rOptical Sensor Value[sample_avg: %d]\n\rOptical Sensor Value[pulse_width: %d]\n\n\r", fifo_waterlevel_mark,sample_avg,pulse_width);
lucaslwl 20:652f0bf256bd 187 max30101.SpO2mode_stop();
lucaslwl 20:652f0bf256bd 188
lucaslwl 20:652f0bf256bd 189 // max30101.Multimode_init(fifo_waterlevel_mark2,sample_avg2,sample_rate2,pulse_width2,red_led_current, ir_led_current,green_led_current,slot_1,slot_2,slot_3,slot_4);
lucaslwl 20:652f0bf256bd 190 // wait(0.5);
lucaslwl 20:652f0bf256bd 191 //
lucaslwl 20:652f0bf256bd 192 // pc.printf("***** MAX30101 Optical Sensor Reading [Multi mode]*****\n\r");
lucaslwl 20:652f0bf256bd 193 // pc.printf("Optical Sensor Value [fifo_waterlevel_mark: %d]\n\rOptical Sensor Value[sample_avg: %d]\n\rOptical Sensor Value[pulse_width: %d]\n\rslot1: %d, slot2: %d, slot3: %d, slot4: %d\n\n\r", fifo_waterlevel_mark,sample_avg,pulse_width, slot_1, slot_2, slot_3, slot_4);
lucaslwl 20:652f0bf256bd 194 //
lucaslwl 20:652f0bf256bd 195
lucaslwl 20:652f0bf256bd 196 //pc.printf("***** ECG Sensor Reading *****\n\r");
lucaslwl 20:652f0bf256bd 197
lucaslwl 20:652f0bf256bd 198 pc.printf("-------------------------------------------------\n\n\n\r");
switches 17:9a467f9a0579 199
lucaslwl 20:652f0bf256bd 200 wait(0.2);
lucaslwl 20:652f0bf256bd 201
lucaslwl 20:652f0bf256bd 202
lucaslwl 20:652f0bf256bd 203
stevep 4:81cea7a352b0 204 }
dan 0:7dec7e9ac085 205 }