This is one of the demo programs for the MAX30003WING. This program records ECG data and prints the status register, calculated BPM, samples recorded and ETAG register value.

Dependencies:   MAX30003 max32630fthr

Fork of MAX30003_Demo_Debug by John Greene

Revision:
4:828118be72d0
Parent:
3:420d5efbd967
Child:
5:202ed7222217
--- a/main.cpp	Tue Aug 22 21:40:49 2017 +0000
+++ b/main.cpp	Mon Aug 28 20:55:47 2017 +0000
@@ -1,3 +1,37 @@
+/*******************************************************************************
+ * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Maxim Integrated
+ * Products, Inc. shall not be used except as stated in the Maxim Integrated
+ * Products, Inc. Branding Policy.
+ *
+ * The mere transfer of this software does not imply any licenses
+ * of trade secrets, proprietary technology, copyrights, patents,
+ * trademarks, maskwork rights, or any other form of intellectual
+ * property whatsoever. Maxim Integrated Products, Inc. retains all
+ * ownership rights.
+ *******************************************************************************
+ */
+ 
+
 #include "mbed.h"
 #include "max32630fthr.h"
 #include "MAX30003.h"
@@ -16,8 +50,8 @@
 
 int main()
 {   
-    const int RTOR_STATUS_MASK = ( 1<<10 );
-    const int EINT_STATUS_MASK = ( 1<<23 );
+
+    const int EINT_STATUS_MASK =  1 << 23;
     
     Serial pc(USBTX, USBRX);            // Use USB debug probe for serial link
     pc.baud(115200);                    // Baud rate = 115200
@@ -32,55 +66,41 @@
     SPI spiBus(SPI2_MOSI, SPI2_MISO, SPI2_SCK);     // SPI bus, P5_1 = MOSI, 
                                                     // P5_2 = MISO, P5_0 = SCK
     
-    MAX30003 * ecgAFE;
-    ecgAFE = new MAX30003(spiBus, P5_3);    // New MAX30003 on spiBus, CS = P5_3 
-    ecg_config(*ecgAFE);                    // Config ECG 
+    MAX30003 ecgAFE(spiBus, P5_3);          // New MAX30003 on spiBus, CS = P5_3 
+    ecg_config( ecgAFE );                   // Config ECG 
      
     
-    ecgAFE->writeRegister( MAX30003::SYNCH , 0);
+    ecgAFE.writeRegister( MAX30003::SYNCH , 0);
     
-    uint32_t ecgFIFO, readSamples, idx, ETAG[32], status, RtoR;
+    uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status;
     int16_t ecgSample[32];
-    float BPM;
     
     while(1) {
         
         /* Read back ECG samples from the FIFO */
         if( ecgFIFOIntFlag ) {
+            ecgFIFOIntFlag = 0;
             pc.printf("Interrupt received....\r\n");
-            status = ecgAFE->readRegister( MAX30003::STATUS );      // Read the STATUS register
-            pc.printf("Status : 0x%x\r\n"
-                      "Current BPM is %3.2f\r\n\r\n", status, BPM);
-            
-            // Check if R-to-R interrupt asserted
-            if( ( status & RTOR_STATUS_MASK ) == RTOR_STATUS_MASK ){              // Check if RtoR update
-            
-                ecgFIFOIntFlag = 0;
-                pc.printf("R-to-R Interrupt \r\n");
-                RtoR = ecgAFE->readRegister( MAX30003::RTOR );  // Read RtoR register
-                BPM = 60.0*RtoR/32768.0;                        // Convert to BPM
-                pc.printf("RtoR : %d\r\n\r\n", RtoR);           // Print BPM/RtoR
-                
-            } 
+            status = ecgAFE.readRegister( MAX30003::STATUS );      // Read the STATUS register
+            pc.printf("Status : 0x%x\r\n\r\n", status);
              
             // Check if EINT interrupt asserted
             if ( ( status & EINT_STATUS_MASK ) == EINT_STATUS_MASK ) {     
             
-                ecgFIFOIntFlag = 0; 
                 pc.printf("FIFO Interrupt \r\n");
-                readSamples = 0;                        // Reset sample counter
+                readECGSamples = 0;                        // Reset sample counter
                 
                 do {
-                    ecgFIFO = ecgAFE->readRegister( MAX30003::ECG_FIFO );   // Read FIFO
-                    ecgSample[readSamples] = ecgFIFO >> 8;                  // Isolate voltage data
-                    ETAG[readSamples] = ( ecgFIFO >> 3 ) & 0b111;           // Isolate ETAG
-                    readSamples++;                                          // Increment sample counter
+                    ecgFIFO = ecgAFE.readRegister( MAX30003::ECG_FIFO );   // Read FIFO
+                    ecgSample[readECGSamples] = ecgFIFO >> 8;                  // Isolate voltage data
+                    ETAG[readECGSamples] = ( ecgFIFO >> 3 ) & 0b111;           // Isolate ETAG
+                    readECGSamples++;                                          // Increment sample counter
                 
                 // Check that sample is not last sample in FIFO                                              
-                } while ( ETAG[readSamples-1] == 0x0 || 
-                          ETAG[readSamples-1] == 0x1 ); 
+                } while ( ETAG[readECGSamples-1] == 0x0 || 
+                          ETAG[readECGSamples-1] == 0x1 ); 
             
-                pc.printf("%d samples read from FIFO \r\n", readSamples);
+                pc.printf("%d samples read from FIFO \r\n", readECGSamples);
                 
                 // Check if FIFO has overflowed
                 if( ETAG[readECGSamples - 1] == 0x7 ){                  
@@ -88,12 +108,11 @@
                 }
                 
                 /* Print results */
-                for( idx = 0; idx < readSamples; idx++ ) {
+                for( idx = 0; idx < readECGSamples; idx++ ) {
                     pc.printf("Sample : %6d, \tETAG : 0x%x\r\n", ecgSample[idx], ETAG[idx]);           
                 }
                 pc.printf("\r\n\r\n\r\n");                          
             }
-        
         }
     }
 }
@@ -112,23 +131,24 @@
     CNFG_GEN_r.bits.rbiasn = 1;     // Enable resistive bias on negative input
     CNFG_GEN_r.bits.rbiasp = 1;     // Enable resistive bias on positive input
     CNFG_GEN_r.bits.en_rbias = 1;   // Enable resistive bias
-    CNFG_GEN_r.bits.imag = 2;       // Current magnitude = 10nA
     CNFG_GEN_r.bits.en_dcloff = 1;  // Enable DC lead-off detection   
+    CNFG_GEN_r.bits.imag = 0b010;   // Current magnitude = 10nA
+    CNFG_GEN_r.bits.rbiasv = 0b00;  // Resistive bias = 50MOhm
     ecgAFE.writeRegister( MAX30003::CNFG_GEN , CNFG_GEN_r.all);
         
     
     // ECG Config register setting
     MAX30003::ECGConfiguration_u CNFG_ECG_r;
-    CNFG_ECG_r.bits.dlpf = 1;       // Digital LPF cutoff = 40Hz
-    CNFG_ECG_r.bits.dhpf = 1;       // Digital HPF cutoff = 0.5Hz
-    CNFG_ECG_r.bits.gain = 3;       // ECG gain = 160V/V
-    CNFG_ECG_r.bits.rate = 2;       // Sample rate = 128 sps
+    CNFG_ECG_r.bits.dlpf = 0b01;       // Digital LPF cutoff = 40Hz
+    CNFG_ECG_r.bits.dhpf = 1;          // Digital HPF cutoff = 0.5Hz
+    CNFG_ECG_r.bits.gain = 0b11;       // ECG gain = 160V/V
+    CNFG_ECG_r.bits.rate = 0b10;       // Sample rate = 128 sps
     ecgAFE.writeRegister( MAX30003::CNFG_ECG , CNFG_ECG_r.all);
       
     
     //R-to-R configuration
     MAX30003::RtoR1Configuration_u CNFG_RTOR_r;
-    CNFG_RTOR_r.bits.en_rtor = 1;           // Enable R-to-R detection
+    CNFG_RTOR_r.bits.en_rtor = 0;           // Disable R-to-R detection
     ecgAFE.writeRegister( MAX30003::CNFG_RTOR1 , CNFG_RTOR_r.all);
        
         
@@ -142,8 +162,8 @@
     //Enable interrupts register setting
     MAX30003::EnableInterrupts_u EN_INT_r;
     EN_INT_r.bits.en_eint = 1;              // Enable EINT interrupt
-    EN_INT_r.bits.en_rrint = 1;             // Enable R-to-R interrupt
-    EN_INT_r.bits.intb_type = 3;            // Open-drain NMOS with internal pullup
+    EN_INT_r.bits.en_rrint = 0;             // Disable R-to-R interrupt
+    EN_INT_r.bits.intb_type = 0b11;         // Open-drain NMOS with internal pullup
     ecgAFE.writeRegister( MAX30003::EN_INT , EN_INT_r.all);
        
        
@@ -151,6 +171,13 @@
     MAX30003::ManageDynamicModes_u MNG_DYN_r;
     MNG_DYN_r.bits.fast = 0;                // Fast recovery mode disabled
     ecgAFE.writeRegister( MAX30003::MNGR_DYN , MNG_DYN_r.all);
+    
+    // MUX Config
+    MAX30003::MuxConfiguration_u CNFG_MUX_r;
+    CNFG_MUX_r.bits.openn = 0;          // Connect ECGN to AFE channel
+    CNFG_MUX_r.bits.openp = 0;          // Connect ECGP to AFE channel
+    ecgAFE.writeRegister( MAX30003::CNFG_EMUX , CNFG_MUX_r.all);
+       
        
     
     return;