![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
k
Dependencies: MAX30003 max32630fthr DS1307
Diff: main.cpp
- Revision:
- 2:812d40f1853d
- Parent:
- 1:86843c27cc81
- Child:
- 3:420d5efbd967
--- a/main.cpp Thu Aug 17 19:56:40 2017 +0000 +++ b/main.cpp Fri Aug 18 17:37:07 2017 +0000 @@ -36,35 +36,52 @@ ecgAFE->writeRegister( MAX30003::SYNCH , 0); - uint32_t ecgFIFO, readSamples, idx, ETAG[32]; + uint32_t ecgFIFO, readSamples, idx, ETAG[32], status, RtoR; int16_t ecgSample[32]; + float BPM; + while(1) { bLed = LED_ON; /* Read back ECG samples from the FIFO */ if( ecgFIFOIntFlag ) { - pc.printf("Interrupt received....\r\n\r\n"); + pc.printf("Interrupt received....\r\n"); bLed = LED_OFF; - ecgFIFOIntFlag = 0; // Clear interrupt flag - readSamples = 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 - } while ( ETAG[readSamples-1] == 0x0 || ETAG[readSamples-1] == 0x1 ); // Check that sample is valid + // Clear interrupt flag + + status = ecgAFE->readRegister( MAX30003::STATUS ); + pc.printf("Status : 0x%x\r\nCurrent BPM is %f\r\n\r\n", status, BPM); + - pc.printf("%d samples read from FIFO \r\n", readSamples); + if( ( status & (1<<10) ) == (1<<10) ){ + ecgFIFOIntFlag = 0; + pc.printf("R-to-R Interrupt \r\n"); + RtoR = ecgAFE->readRegister( MAX30003::RTOR ); + BPM = 60.0*RtoR/32768.0; + pc.printf("RtoR : %d\r\n\r\n", RtoR); + } + + if ( ( status & (1<<23) ) == (1<<23) ) { + ecgFIFOIntFlag = 0; + pc.printf("FIFO Interrupt \r\n"); + readSamples = 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 + } while ( ETAG[readSamples-1] == 0x0 || ETAG[readSamples-1] == 0x1 ); // Check that sample is valid - for( idx = 0; idx < readSamples; idx++ ) { - pc.printf("Sample : %6d, \tETAG : 0x%x\r\n", ecgSample[idx], ETAG[idx]); + pc.printf("%d samples read from FIFO \r\n", readSamples); + + for( idx = 0; idx < readSamples; idx++ ) { + pc.printf("Sample : %6d, \tETAG : 0x%x\r\n", ecgSample[idx], ETAG[idx]); + } + pc.printf("\r\n\r\n\r\n"); } - - pc.printf("\r\n\r\n\r\n"); - + } - } } @@ -106,7 +123,8 @@ //Manage interrupts register setting MAX30003::ManageInterrupts_u MNG_INT_r; - MNG_INT_r.bits.efit = 0b00011; + MNG_INT_r.bits.efit = 0b00011; + MNG_INT_r.bits.clr_rrint = 0b01; ecgAFE.writeRegister( MAX30003::MNGR_INT , MNG_INT_r.all); @@ -114,6 +132,7 @@ MAX30003::EnableInterrupts_u EN_INT_r; EN_INT_r.all = 0; EN_INT_r.bits.en_eint = 1; + EN_INT_r.bits.en_rrint = 1; EN_INT_r.bits.intb_type = 0b11; ecgAFE.writeRegister( MAX30003::EN_INT , EN_INT_r.all);