MUX

Dependencies:   MAX30003 max32630fthr

Committer:
kidecha_rahul
Date:
Sat May 22 19:19:45 2021 +0000
Revision:
8:67ba6d185fe0
Parent:
7:cf0855a0450a
MUX

Who changed what in which revision?

UserRevisionLine numberNew contents of line
coreyharris 6:86ac850c718d 1 /*******************************************************************************
coreyharris 6:86ac850c718d 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
coreyharris 6:86ac850c718d 3 *
coreyharris 6:86ac850c718d 4 * Permission is hereby granted, free of charge, to any person obtaining a
coreyharris 6:86ac850c718d 5 * copy of this software and associated documentation files (the "Software"),
coreyharris 6:86ac850c718d 6 * to deal in the Software without restriction, including without limitation
coreyharris 6:86ac850c718d 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
coreyharris 6:86ac850c718d 8 * and/or sell copies of the Software, and to permit persons to whom the
coreyharris 6:86ac850c718d 9 * Software is furnished to do so, subject to the following conditions:
coreyharris 6:86ac850c718d 10 *
coreyharris 6:86ac850c718d 11 * The above copyright notice and this permission notice shall be included
coreyharris 6:86ac850c718d 12 * in all copies or substantial portions of the Software.
coreyharris 6:86ac850c718d 13 *
coreyharris 6:86ac850c718d 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
coreyharris 6:86ac850c718d 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
coreyharris 6:86ac850c718d 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
coreyharris 6:86ac850c718d 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
coreyharris 6:86ac850c718d 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
coreyharris 6:86ac850c718d 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
coreyharris 6:86ac850c718d 20 * OTHER DEALINGS IN THE SOFTWARE.
coreyharris 6:86ac850c718d 21 *
coreyharris 6:86ac850c718d 22 * Except as contained in this notice, the name of Maxim Integrated
coreyharris 6:86ac850c718d 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
coreyharris 6:86ac850c718d 24 * Products, Inc. Branding Policy.
coreyharris 6:86ac850c718d 25 *
coreyharris 6:86ac850c718d 26 * The mere transfer of this software does not imply any licenses
coreyharris 6:86ac850c718d 27 * of trade secrets, proprietary technology, copyrights, patents,
coreyharris 6:86ac850c718d 28 * trademarks, maskwork rights, or any other form of intellectual
coreyharris 6:86ac850c718d 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
coreyharris 6:86ac850c718d 30 * ownership rights.
coreyharris 6:86ac850c718d 31 *******************************************************************************
coreyharris 6:86ac850c718d 32 */
coreyharris 6:86ac850c718d 33
coreyharris 0:38c49bc37c7c 34 #include "mbed.h"
coreyharris 0:38c49bc37c7c 35 #include "max32630fthr.h"
coreyharris 0:38c49bc37c7c 36 #include "MAX30003.h"
coreyharris 0:38c49bc37c7c 37
coreyharris 0:38c49bc37c7c 38 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
coreyharris 0:38c49bc37c7c 39
coreyharris 0:38c49bc37c7c 40 void ecg_config(MAX30003 &ecgAFE);
kidecha_rahul 8:67ba6d185fe0 41 void ecg_config_off(MAX30003& ecgAFE);
kidecha_rahul 8:67ba6d185fe0 42
kidecha_rahul 8:67ba6d185fe0 43 DigitalOut EN(P1_7);
kidecha_rahul 8:67ba6d185fe0 44 DigitalOut A0(P1_4);
kidecha_rahul 8:67ba6d185fe0 45 DigitalOut A1(P7_2);
kidecha_rahul 8:67ba6d185fe0 46
coreyharris 0:38c49bc37c7c 47
coreyharris 0:38c49bc37c7c 48 /* ECG FIFO nearly full callback */
coreyharris 0:38c49bc37c7c 49 volatile bool ecgFIFOIntFlag = 0;
kidecha_rahul 8:67ba6d185fe0 50 bool flag = 1;
kidecha_rahul 8:67ba6d185fe0 51 void ecgFIFO_callback()
kidecha_rahul 8:67ba6d185fe0 52 {
coreyharris 0:38c49bc37c7c 53 ecgFIFOIntFlag = 1;
coreyharris 0:38c49bc37c7c 54 }
coreyharris 0:38c49bc37c7c 55
coreyharris 0:38c49bc37c7c 56 int main()
coreyharris 3:420d5efbd967 57 {
coreyharris 6:86ac850c718d 58 // Constants
coreyharris 4:06e258ff0b97 59 const int EINT_STATUS_MASK = 1 << 23;
coreyharris 6:86ac850c718d 60 const int FIFO_OVF_MASK = 0x7;
coreyharris 6:86ac850c718d 61 const int FIFO_VALID_SAMPLE_MASK = 0x0;
coreyharris 6:86ac850c718d 62 const int FIFO_FAST_SAMPLE_MASK = 0x1;
coreyharris 6:86ac850c718d 63 const int ETAG_BITS_MASK = 0x7;
coreyharris 3:420d5efbd967 64
coreyharris 6:86ac850c718d 65 // Ports and serial connections
kidecha_rahul 8:67ba6d185fe0 66 Serial pc(P3_0,P3_1); // Use USB debug probe for serial link
kidecha_rahul 8:67ba6d185fe0 67 pc.baud(230400); // Baud rate = 115200
coreyharris 1:86843c27cc81 68
kidecha_rahul 8:67ba6d185fe0 69 DigitalOut bLed(LED3); // Debug LEDs
coreyharris 0:38c49bc37c7c 70
kidecha_rahul 8:67ba6d185fe0 71 InterruptIn ecgFIFO_1_int(P5_4); // Config P5_4 as int. in for the
kidecha_rahul 8:67ba6d185fe0 72 ecgFIFO_1_int.fall(&ecgFIFO_callback); // ecg FIFO almost full interrupt
coreyharris 0:38c49bc37c7c 73
kidecha_rahul 8:67ba6d185fe0 74 SPI spiBus(P5_1,P5_2,P5_0); // SPI bus, P5_1 = MOSI,
coreyharris 1:86843c27cc81 75 // P5_2 = MISO, P5_0 = SCK
coreyharris 0:38c49bc37c7c 76
kidecha_rahul 8:67ba6d185fe0 77 MAX30003 ecgAFE_1(spiBus, P5_3); // New MAX30003 on spiBus, CS = P5_3
kidecha_rahul 8:67ba6d185fe0 78 ecg_config(ecgAFE_1); // Config ECG
coreyharris 1:86843c27cc81 79
coreyharris 0:38c49bc37c7c 80
kidecha_rahul 8:67ba6d185fe0 81 ecgAFE_1.writeRegister( MAX30003::SYNCH , 0);
coreyharris 0:38c49bc37c7c 82
coreyharris 4:06e258ff0b97 83 uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status;
kidecha_rahul 8:67ba6d185fe0 84 int16_t ecgSample[32], x = 0;
kidecha_rahul 8:67ba6d185fe0 85
kidecha_rahul 8:67ba6d185fe0 86
coreyharris 2:812d40f1853d 87
kidecha_rahul 8:67ba6d185fe0 88 while(1)
kidecha_rahul 8:67ba6d185fe0 89 {
kidecha_rahul 8:67ba6d185fe0 90 EN = 1;
kidecha_rahul 8:67ba6d185fe0 91 A0 = 0;
kidecha_rahul 8:67ba6d185fe0 92 A1 = 0;
kidecha_rahul 8:67ba6d185fe0 93
kidecha_rahul 8:67ba6d185fe0 94 do
kidecha_rahul 8:67ba6d185fe0 95 {
coreyharris 4:06e258ff0b97 96 // Read back ECG samples from the FIFO
coreyharris 0:38c49bc37c7c 97 if( ecgFIFOIntFlag ) {
coreyharris 2:812d40f1853d 98
kidecha_rahul 8:67ba6d185fe0 99 //ecgFIFOIntFlag = 0;
kidecha_rahul 8:67ba6d185fe0 100 status = ecgAFE_1.readRegister( MAX30003::STATUS ); // Read the STATUS register
coreyharris 2:812d40f1853d 101
coreyharris 3:420d5efbd967 102 // Check if EINT interrupt asserted
coreyharris 3:420d5efbd967 103 if ( ( status & EINT_STATUS_MASK ) == EINT_STATUS_MASK ) {
coreyharris 3:420d5efbd967 104
kidecha_rahul 8:67ba6d185fe0 105 readECGSamples = 0; // Reset sample counter
coreyharris 3:420d5efbd967 106
coreyharris 2:812d40f1853d 107 do {
kidecha_rahul 8:67ba6d185fe0 108 ecgFIFO = ecgAFE_1.readRegister( MAX30003::ECG_FIFO ); // Read FIFO
kidecha_rahul 8:67ba6d185fe0 109 pc.printf("%d samples read from FIFO \r\n", readECGSamples);
kidecha_rahul 8:67ba6d185fe0 110 // pc.printf("%d samples read from FIFO \r\n", readECGSamples);
coreyharris 4:06e258ff0b97 111 ecgSample[readECGSamples] = ecgFIFO >> 8; // Isolate voltage data
coreyharris 6:86ac850c718d 112 ETAG[readECGSamples] = ( ecgFIFO >> 3 ) & ETAG_BITS_MASK; // Isolate ETAG
kidecha_rahul 8:67ba6d185fe0 113 readECGSamples++;
kidecha_rahul 8:67ba6d185fe0 114 // Increment sample counter
coreyharris 3:420d5efbd967 115
coreyharris 3:420d5efbd967 116 // Check that sample is not last sample in FIFO
coreyharris 6:86ac850c718d 117 } while ( ETAG[readECGSamples-1] == FIFO_VALID_SAMPLE_MASK ||
coreyharris 6:86ac850c718d 118 ETAG[readECGSamples-1] == FIFO_FAST_SAMPLE_MASK );
coreyharris 2:812d40f1853d 119
coreyharris 3:420d5efbd967 120 // Check if FIFO has overflowed
coreyharris 6:86ac850c718d 121 if( ETAG[readECGSamples - 1] == FIFO_OVF_MASK ){
kidecha_rahul 8:67ba6d185fe0 122 ecgAFE_1.writeRegister( MAX30003::FIFO_RST , 0); // Reset FIFO
kidecha_rahul 8:67ba6d185fe0 123 bLed = 1;//notifies the user that an over flow occured
kidecha_rahul 8:67ba6d185fe0 124 }
kidecha_rahul 8:67ba6d185fe0 125
kidecha_rahul 8:67ba6d185fe0 126 // Print results
kidecha_rahul 8:67ba6d185fe0 127 for( idx = 0; idx < readECGSamples; idx++ ) {
kidecha_rahul 8:67ba6d185fe0 128 pc.printf("%6d\r\n", ecgSample[idx]);
kidecha_rahul 8:67ba6d185fe0 129 }
kidecha_rahul 8:67ba6d185fe0 130 //rLed = 1;
kidecha_rahul 8:67ba6d185fe0 131 bLed = ! bLed;
kidecha_rahul 8:67ba6d185fe0 132 x++;
kidecha_rahul 8:67ba6d185fe0 133 }
kidecha_rahul 8:67ba6d185fe0 134 }
kidecha_rahul 8:67ba6d185fe0 135 }while(x<20);
kidecha_rahul 8:67ba6d185fe0 136 //ecg_config_off(ecgAFE_1);
kidecha_rahul 8:67ba6d185fe0 137 bLed = ~bLed;
kidecha_rahul 8:67ba6d185fe0 138 x=0;
kidecha_rahul 8:67ba6d185fe0 139
kidecha_rahul 8:67ba6d185fe0 140
kidecha_rahul 8:67ba6d185fe0 141
kidecha_rahul 8:67ba6d185fe0 142
kidecha_rahul 8:67ba6d185fe0 143 DigitalOut gLed(LED2);
kidecha_rahul 8:67ba6d185fe0 144 A0 = 1;
kidecha_rahul 8:67ba6d185fe0 145 do
kidecha_rahul 8:67ba6d185fe0 146 {
kidecha_rahul 8:67ba6d185fe0 147 // Read back ECG samples from the FIFO
kidecha_rahul 8:67ba6d185fe0 148 if( ecgFIFOIntFlag ) {
kidecha_rahul 8:67ba6d185fe0 149
kidecha_rahul 8:67ba6d185fe0 150 // ecgFIFOIntFlag = 0;
kidecha_rahul 8:67ba6d185fe0 151 status = ecgAFE_1.readRegister( MAX30003::STATUS ); // Read the STATUS register
kidecha_rahul 8:67ba6d185fe0 152
kidecha_rahul 8:67ba6d185fe0 153 // Check if EINT interrupt asserted
kidecha_rahul 8:67ba6d185fe0 154 if ( ( status & EINT_STATUS_MASK ) == EINT_STATUS_MASK ) {
kidecha_rahul 8:67ba6d185fe0 155
kidecha_rahul 8:67ba6d185fe0 156 readECGSamples = 0; // Reset sample counter
kidecha_rahul 8:67ba6d185fe0 157
kidecha_rahul 8:67ba6d185fe0 158 do {
kidecha_rahul 8:67ba6d185fe0 159 ecgFIFO = ecgAFE_1.readRegister( MAX30003::ECG_FIFO ); // Read FIFO
kidecha_rahul 8:67ba6d185fe0 160 pc.printf("%d samples read from FIFO \r\n", readECGSamples);
kidecha_rahul 8:67ba6d185fe0 161 // pc.printf("%d samples read from FIFO \r\n", readECGSamples);
kidecha_rahul 8:67ba6d185fe0 162 ecgSample[readECGSamples] = ecgFIFO >> 8; // Isolate voltage data
kidecha_rahul 8:67ba6d185fe0 163 ETAG[readECGSamples] = ( ecgFIFO >> 3 ) & ETAG_BITS_MASK; // Isolate ETAG
kidecha_rahul 8:67ba6d185fe0 164 readECGSamples++;
kidecha_rahul 8:67ba6d185fe0 165 // Increment sample counter
kidecha_rahul 8:67ba6d185fe0 166
kidecha_rahul 8:67ba6d185fe0 167 // Check that sample is not last sample in FIFO
kidecha_rahul 8:67ba6d185fe0 168 } while ( ETAG[readECGSamples-1] == FIFO_VALID_SAMPLE_MASK ||
kidecha_rahul 8:67ba6d185fe0 169 ETAG[readECGSamples-1] == FIFO_FAST_SAMPLE_MASK );
kidecha_rahul 8:67ba6d185fe0 170
kidecha_rahul 8:67ba6d185fe0 171 // Check if FIFO has overflowed
kidecha_rahul 8:67ba6d185fe0 172 if( ETAG[readECGSamples - 1] == FIFO_OVF_MASK ){
kidecha_rahul 8:67ba6d185fe0 173 ecgAFE_1.writeRegister( MAX30003::FIFO_RST , 0); // Reset FIFO
kidecha_rahul 8:67ba6d185fe0 174 gLed = 1;//notifies the user that an over flow occured
kidecha_rahul 8:67ba6d185fe0 175 }
kidecha_rahul 8:67ba6d185fe0 176
kidecha_rahul 8:67ba6d185fe0 177 // Print results
kidecha_rahul 8:67ba6d185fe0 178 for( idx = 0; idx < readECGSamples; idx++ ) {
kidecha_rahul 8:67ba6d185fe0 179 pc.printf("%6d\r\n", ecgSample[idx]);
kidecha_rahul 8:67ba6d185fe0 180 }
kidecha_rahul 8:67ba6d185fe0 181 //rLed = 1;
kidecha_rahul 8:67ba6d185fe0 182 gLed = ! gLed;
kidecha_rahul 8:67ba6d185fe0 183 x++;
kidecha_rahul 8:67ba6d185fe0 184 }
kidecha_rahul 8:67ba6d185fe0 185 }
kidecha_rahul 8:67ba6d185fe0 186 }while(x<20);
kidecha_rahul 8:67ba6d185fe0 187 //ecg_config_off(ecgAFE_1);
kidecha_rahul 8:67ba6d185fe0 188 gLed = ~gLed;
kidecha_rahul 8:67ba6d185fe0 189 x=0;
kidecha_rahul 8:67ba6d185fe0 190
kidecha_rahul 8:67ba6d185fe0 191
kidecha_rahul 8:67ba6d185fe0 192
kidecha_rahul 8:67ba6d185fe0 193
kidecha_rahul 8:67ba6d185fe0 194 DigitalOut rLed(LED1);
kidecha_rahul 8:67ba6d185fe0 195 A0 = 1;
kidecha_rahul 8:67ba6d185fe0 196 do
kidecha_rahul 8:67ba6d185fe0 197 {
kidecha_rahul 8:67ba6d185fe0 198 // Read back ECG samples from the FIFO
kidecha_rahul 8:67ba6d185fe0 199 if( ecgFIFOIntFlag ) {
kidecha_rahul 8:67ba6d185fe0 200
kidecha_rahul 8:67ba6d185fe0 201 // ecgFIFOIntFlag = 0;
kidecha_rahul 8:67ba6d185fe0 202 status = ecgAFE_1.readRegister( MAX30003::STATUS ); // Read the STATUS register
kidecha_rahul 8:67ba6d185fe0 203
kidecha_rahul 8:67ba6d185fe0 204 // Check if EINT interrupt asserted
kidecha_rahul 8:67ba6d185fe0 205 if ( ( status & EINT_STATUS_MASK ) == EINT_STATUS_MASK ) {
kidecha_rahul 8:67ba6d185fe0 206
kidecha_rahul 8:67ba6d185fe0 207 readECGSamples = 0; // Reset sample counter
kidecha_rahul 8:67ba6d185fe0 208
kidecha_rahul 8:67ba6d185fe0 209 do {
kidecha_rahul 8:67ba6d185fe0 210 ecgFIFO = ecgAFE_1.readRegister( MAX30003::ECG_FIFO ); // Read FIFO
kidecha_rahul 8:67ba6d185fe0 211 pc.printf("%d samples read from FIFO \r\n", readECGSamples);
kidecha_rahul 8:67ba6d185fe0 212 // pc.printf("%d samples read from FIFO \r\n", readECGSamples);
kidecha_rahul 8:67ba6d185fe0 213 ecgSample[readECGSamples] = ecgFIFO >> 8; // Isolate voltage data
kidecha_rahul 8:67ba6d185fe0 214 ETAG[readECGSamples] = ( ecgFIFO >> 3 ) & ETAG_BITS_MASK; // Isolate ETAG
kidecha_rahul 8:67ba6d185fe0 215 readECGSamples++;
kidecha_rahul 8:67ba6d185fe0 216 // Increment sample counter
kidecha_rahul 8:67ba6d185fe0 217
kidecha_rahul 8:67ba6d185fe0 218 // Check that sample is not last sample in FIFO
kidecha_rahul 8:67ba6d185fe0 219 } while ( ETAG[readECGSamples-1] == FIFO_VALID_SAMPLE_MASK ||
kidecha_rahul 8:67ba6d185fe0 220 ETAG[readECGSamples-1] == FIFO_FAST_SAMPLE_MASK );
kidecha_rahul 8:67ba6d185fe0 221
kidecha_rahul 8:67ba6d185fe0 222 // Check if FIFO has overflowed
kidecha_rahul 8:67ba6d185fe0 223 if( ETAG[readECGSamples - 1] == FIFO_OVF_MASK ){
kidecha_rahul 8:67ba6d185fe0 224 ecgAFE_1.writeRegister( MAX30003::FIFO_RST , 0); // Reset FIFO
johnGreeneMaxim 7:cf0855a0450a 225 rLed = 1;//notifies the user that an over flow occured
coreyharris 3:420d5efbd967 226 }
coreyharris 3:420d5efbd967 227
coreyharris 4:06e258ff0b97 228 // Print results
coreyharris 4:06e258ff0b97 229 for( idx = 0; idx < readECGSamples; idx++ ) {
coreyharris 6:86ac850c718d 230 pc.printf("%6d\r\n", ecgSample[idx]);
coreyharris 6:86ac850c718d 231 }
kidecha_rahul 8:67ba6d185fe0 232 //rLed = 1;
kidecha_rahul 8:67ba6d185fe0 233 rLed = ! rLed;
kidecha_rahul 8:67ba6d185fe0 234 x++;
kidecha_rahul 8:67ba6d185fe0 235 }
coreyharris 0:38c49bc37c7c 236 }
kidecha_rahul 8:67ba6d185fe0 237 }while(x<20);
kidecha_rahul 8:67ba6d185fe0 238 //ecg_config_off(ecgAFE_1);
kidecha_rahul 8:67ba6d185fe0 239 rLed = ~rLed;
kidecha_rahul 8:67ba6d185fe0 240 x=0;
kidecha_rahul 8:67ba6d185fe0 241
coreyharris 0:38c49bc37c7c 242 }
coreyharris 0:38c49bc37c7c 243 }
coreyharris 0:38c49bc37c7c 244
coreyharris 0:38c49bc37c7c 245 void ecg_config(MAX30003& ecgAFE) {
coreyharris 0:38c49bc37c7c 246
coreyharris 1:86843c27cc81 247 // Reset ECG to clear registers
coreyharris 1:86843c27cc81 248 ecgAFE.writeRegister( MAX30003::SW_RST , 0);
coreyharris 0:38c49bc37c7c 249
coreyharris 1:86843c27cc81 250 // General config register setting
coreyharris 1:86843c27cc81 251 MAX30003::GeneralConfiguration_u CNFG_GEN_r;
coreyharris 3:420d5efbd967 252 CNFG_GEN_r.bits.en_ecg = 1; // Enable ECG channel
coreyharris 3:420d5efbd967 253 CNFG_GEN_r.bits.rbiasn = 1; // Enable resistive bias on negative input
coreyharris 3:420d5efbd967 254 CNFG_GEN_r.bits.rbiasp = 1; // Enable resistive bias on positive input
coreyharris 3:420d5efbd967 255 CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias
coreyharris 3:420d5efbd967 256 CNFG_GEN_r.bits.imag = 2; // Current magnitude = 10nA
coreyharris 3:420d5efbd967 257 CNFG_GEN_r.bits.en_dcloff = 1; // Enable DC lead-off detection
coreyharris 1:86843c27cc81 258 ecgAFE.writeRegister( MAX30003::CNFG_GEN , CNFG_GEN_r.all);
coreyharris 1:86843c27cc81 259
coreyharris 1:86843c27cc81 260
coreyharris 1:86843c27cc81 261 // ECG Config register setting
coreyharris 1:86843c27cc81 262 MAX30003::ECGConfiguration_u CNFG_ECG_r;
coreyharris 3:420d5efbd967 263 CNFG_ECG_r.bits.dlpf = 1; // Digital LPF cutoff = 40Hz
coreyharris 3:420d5efbd967 264 CNFG_ECG_r.bits.dhpf = 1; // Digital HPF cutoff = 0.5Hz
coreyharris 3:420d5efbd967 265 CNFG_ECG_r.bits.gain = 3; // ECG gain = 160V/V
coreyharris 3:420d5efbd967 266 CNFG_ECG_r.bits.rate = 2; // Sample rate = 128 sps
coreyharris 1:86843c27cc81 267 ecgAFE.writeRegister( MAX30003::CNFG_ECG , CNFG_ECG_r.all);
coreyharris 1:86843c27cc81 268
coreyharris 1:86843c27cc81 269
coreyharris 1:86843c27cc81 270 //R-to-R configuration
coreyharris 1:86843c27cc81 271 MAX30003::RtoR1Configuration_u CNFG_RTOR_r;
coreyharris 3:420d5efbd967 272 CNFG_RTOR_r.bits.en_rtor = 1; // Enable R-to-R detection
coreyharris 1:86843c27cc81 273 ecgAFE.writeRegister( MAX30003::CNFG_RTOR1 , CNFG_RTOR_r.all);
coreyharris 1:86843c27cc81 274
coreyharris 1:86843c27cc81 275
coreyharris 1:86843c27cc81 276 //Manage interrupts register setting
coreyharris 1:86843c27cc81 277 MAX30003::ManageInterrupts_u MNG_INT_r;
coreyharris 3:420d5efbd967 278 MNG_INT_r.bits.efit = 0b00011; // Assert EINT w/ 4 unread samples
coreyharris 3:420d5efbd967 279 MNG_INT_r.bits.clr_rrint = 0b01; // Clear R-to-R on RTOR reg. read back
coreyharris 1:86843c27cc81 280 ecgAFE.writeRegister( MAX30003::MNGR_INT , MNG_INT_r.all);
coreyharris 0:38c49bc37c7c 281
coreyharris 0:38c49bc37c7c 282
coreyharris 1:86843c27cc81 283 //Enable interrupts register setting
coreyharris 1:86843c27cc81 284 MAX30003::EnableInterrupts_u EN_INT_r;
coreyharris 5:f8d1f651bef5 285 EN_INT_r.all = 0;
coreyharris 3:420d5efbd967 286 EN_INT_r.bits.en_eint = 1; // Enable EINT interrupt
coreyharris 4:06e258ff0b97 287 EN_INT_r.bits.en_rrint = 0; // Disable R-to-R interrupt
coreyharris 3:420d5efbd967 288 EN_INT_r.bits.intb_type = 3; // Open-drain NMOS with internal pullup
coreyharris 1:86843c27cc81 289 ecgAFE.writeRegister( MAX30003::EN_INT , EN_INT_r.all);
coreyharris 1:86843c27cc81 290
coreyharris 1:86843c27cc81 291
coreyharris 1:86843c27cc81 292 //Dyanmic modes config
coreyharris 1:86843c27cc81 293 MAX30003::ManageDynamicModes_u MNG_DYN_r;
coreyharris 3:420d5efbd967 294 MNG_DYN_r.bits.fast = 0; // Fast recovery mode disabled
coreyharris 1:86843c27cc81 295 ecgAFE.writeRegister( MAX30003::MNGR_DYN , MNG_DYN_r.all);
coreyharris 5:f8d1f651bef5 296
coreyharris 5:f8d1f651bef5 297 // MUX Config
coreyharris 5:f8d1f651bef5 298 MAX30003::MuxConfiguration_u CNFG_MUX_r;
coreyharris 5:f8d1f651bef5 299 CNFG_MUX_r.bits.openn = 0; // Connect ECGN to AFE channel
coreyharris 5:f8d1f651bef5 300 CNFG_MUX_r.bits.openp = 0; // Connect ECGP to AFE channel
coreyharris 5:f8d1f651bef5 301 ecgAFE.writeRegister( MAX30003::CNFG_EMUX , CNFG_MUX_r.all);
kidecha_rahul 8:67ba6d185fe0 302
coreyharris 1:86843c27cc81 303 return;
coreyharris 0:38c49bc37c7c 304 }
coreyharris 0:38c49bc37c7c 305
kidecha_rahul 8:67ba6d185fe0 306 void ecg_config_off(MAX30003& ecgAFE)
kidecha_rahul 8:67ba6d185fe0 307 {
kidecha_rahul 8:67ba6d185fe0 308 // General config register setting
kidecha_rahul 8:67ba6d185fe0 309 MAX30003::GeneralConfiguration_u CNFG_GEN_r;
kidecha_rahul 8:67ba6d185fe0 310 CNFG_GEN_r.bits.en_ecg = 0; // Enable ECG channel
kidecha_rahul 8:67ba6d185fe0 311 // CNFG_GEN_r.bits.rbiasn = 1; // Enable resistive bias on negative input
kidecha_rahul 8:67ba6d185fe0 312 // CNFG_GEN_r.bits.rbiasp = 1; // Enable resistive bias on positive input
kidecha_rahul 8:67ba6d185fe0 313 // CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias
kidecha_rahul 8:67ba6d185fe0 314 // CNFG_GEN_r.bits.imag = 2; // Current magnitude = 10nA
kidecha_rahul 8:67ba6d185fe0 315 // CNFG_GEN_r.bits.en_dcloff = 1; // Enable DC lead-off detection
kidecha_rahul 8:67ba6d185fe0 316 ecgAFE.writeRegister( MAX30003::CNFG_GEN , CNFG_GEN_r.all);
kidecha_rahul 8:67ba6d185fe0 317 }