final
Dependencies: MAX30003 max32630fthr DS1307
Diff: main.cpp
- Revision:
- 6:86ac850c718d
- Parent:
- 5:f8d1f651bef5
- Child:
- 7:cf0855a0450a
--- a/main.cpp Mon Aug 28 20:57:10 2017 +0000 +++ b/main.cpp Tue Aug 29 20:27:26 2017 +0000 @@ -1,3 +1,38 @@ +/******************************************************************************* + * 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 +51,15 @@ int main() { + + // Constants const int EINT_STATUS_MASK = 1 << 23; + const int FIFO_OVF_MASK = 0x7; + const int FIFO_VALID_SAMPLE_MASK = 0x0; + const int FIFO_FAST_SAMPLE_MASK = 0x1; + const int ETAG_BITS_MASK = 0x7; + // Ports and serial connections Serial pc(USBTX, USBRX); // Use USB debug probe for serial link pc.baud(115200); // Baud rate = 115200 @@ -54,24 +96,25 @@ readECGSamples = 0; // Reset sample counter do { - ecgFIFO = ecgAFE.readRegister( MAX30003::ECG_FIFO ); // Read FIFO + ecgFIFO = ecgAFE.readRegister( MAX30003::ECG_FIFO ); // Read FIFO ecgSample[readECGSamples] = ecgFIFO >> 8; // Isolate voltage data - ETAG[readECGSamples] = ( ecgFIFO >> 3 ) & 0b111; // Isolate ETAG + ETAG[readECGSamples] = ( ecgFIFO >> 3 ) & ETAG_BITS_MASK; // Isolate ETAG readECGSamples++; // Increment sample counter // Check that sample is not last sample in FIFO - } while ( ETAG[readECGSamples-1] == 0x0 || - ETAG[readECGSamples-1] == 0x1 ); + } while ( ETAG[readECGSamples-1] == FIFO_VALID_SAMPLE_MASK || + ETAG[readECGSamples-1] == FIFO_FAST_SAMPLE_MASK ); // Check if FIFO has overflowed - if( ETAG[readECGSamples - 1] == 0x7 ){ + if( ETAG[readECGSamples - 1] == FIFO_OVF_MASK ){ ecgAFE.writeRegister( MAX30003::FIFO_RST , 0); // Reset FIFO } // Print results for( idx = 0; idx < readECGSamples; idx++ ) { - pc.printf("Sample : %6d\r\n", ecgSample[idx]); - } + pc.printf("%6d\r\n", ecgSample[idx]); + } + } } }