John Greene / Mbed OS MAX30101_HR_SPO2

Dependencies:   MAX30101 max32630fthr

Fork of MAX30101_Demo_Plot_Algorithm by John Greene

Revision:
2:54182d6a168f
Parent:
1:471e2b722d24
Child:
3:a580414c44ce
--- a/main.cpp	Mon Aug 21 15:43:51 2017 +0000
+++ b/main.cpp	Mon Aug 21 21:41:14 2017 +0000
@@ -34,10 +34,12 @@
     MAX30101::InterruptBitField_u ints;
     uint8_t fifoData[MAX30101::MAX_FIFO_BYTES];
     uint16_t idx, readBytes;
+    int16_t opSample;
+    uint32_t sample;
     while(1) {
-        
+
         if( rc == 0 ) {
-            
+
             if(op_sensorIntFlag) {
                 pc.printf("Interrupt seen...\r\n");
                 op_sensorIntFlag = 0;                       // Lower interrupt flag
@@ -47,17 +49,19 @@
                     rc = op_sensor->readFIFO(MAX30101::OneLedChannel, fifoData, readBytes);     // Read FIFO 
                     
                     if(rc == 0) {
-                        pc.printf("FIFO Read, received %d bytes\r\n", readBytes);
+                        pc.printf("FIFO Read, received %d samples\r\n\r\n", readBytes/3);
                         
-                        for(idx = 0; idx < readBytes; idx++) {
-                            pc.printf("fifoData[0x%04x] = 0x%02x\r\n", idx, fifoData[idx]);     // Print results
+                        for(idx = 0; idx < readBytes; idx+=3) {
+                            sample = (fifoData[idx]<<16) | (fifoData[idx+1]<<8) | (fifoData[idx+2]);
+                            opSample = sample >> 8;
+                            pc.printf("Op. Sample : %i\r\n", opSample);     // Print results
                         }
-                        pc.printf("\r\n");
+                        pc.printf("\r\n\r\n");
+                        
                     }
                 }
             }
                     
-        } else {
             
             pc.printf("Something went wrong, check the I2C bus or power connections... \r\n");
             bLed = LED_OFF;
@@ -101,7 +105,7 @@
     {
         fifoConfig.all = 0;
         fifoConfig.bits.fifo_a_full = 15; // Max level of 15 samples 
-        fifoConfig.bits.sample_average = MAX30101::AveragedSamples_4; // Average 4 samples
+        fifoConfig.bits.sample_average = MAX30101::AveragedSamples_8; // Average 4 samples
         rc = op_sensor.setFIFOConfiguration(fifoConfig);
     }
     
@@ -110,6 +114,7 @@
     {
         spo2Config.all = 0;
         spo2Config.bits.spo2_sr = MAX30101::SR_400_Hz;      // SpO2 SR = 400Hz
+        spo2Config.bits.led_pw = 1;
         rc = op_sensor.setSpO2Configuration(spo2Config);
     }
     
@@ -117,7 +122,7 @@
     if(rc == 0)
     {
         //Heart Rate only
-        rc = op_sensor.setLEDPulseAmplitude(MAX30101::LED1_PA, 0x1F); // LED1 = 6.4mA
+        rc = op_sensor.setLEDPulseAmplitude(MAX30101::LED1_PA, 0x1F);
     }
        
     //Set operating mode