![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
3 channel_MUX
Dependencies: BufferedSerial MAX30003 max32630fthr1 DS1307
Diff: main.cpp
- Revision:
- 10:3709e8f3d089
- Parent:
- 9:24ecf16eab0f
- Child:
- 11:1d4ecbca034e
--- a/main.cpp Wed Aug 19 19:38:17 2020 +0000 +++ b/main.cpp Wed Apr 21 23:14:23 2021 +0000 @@ -1,48 +1,42 @@ - -#include "MAX30003.h" #include "mbed.h" #include "max32630fthr.h" -#include "ds1307.h" - -Timer timer_fast; +#include "MAX30003.h" + MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); - -void task_fast(void); -DigitalOut ledA(LED2); + void ecg_config(MAX30003 &ecgAFE); - + +/* ECG FIFO nearly full callback */ volatile bool ecgFIFOIntFlag = 0; -volatile int16_t onesec_counter = 0; -volatile bool timerflag = 0; -void ecgFIFO_callback_1() { // Triggered when the ECG FIFO is about to be full +void ecgFIFO_callback() { ecgFIFOIntFlag = 1; - + } - + 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; - timer_fast.start(); - DigitalOut rLed(LED1, LED_OFF); - Serial pc(USBTX, USBRX); // Use USB debug probe for serial link - pc.baud(115200); // Baud rate = 115200 + // Ports and serial connections + Serial pc(P3_1,P3_0); // Use USB debug probe for serial link + pc.baud(230400); // Baud rate = 115200 + + DigitalOut bLed(LED3, LED_ON); // Debug LEDs InterruptIn ecgFIFO_int(P5_4); // Config P5_4 as int. in for the - ecgFIFO_int.fall(&ecgFIFO_callback_1); // ecg FIFO interrupt at falling edge + ecgFIFO_int.fall(&ecgFIFO_callback); // ecg FIFO almost full interrupt SPI spiBus(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // SPI bus, P5_1 = MOSI, // P5_2 = MISO, P5_0 = SCK MAX30003 ecgAFE(spiBus, P5_3); // New MAX30003 on spiBus, CS = P5_3 - ecg_config(ecgAFE); // Config ECG @@ -50,41 +44,17 @@ uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status; int16_t ecgSample[32]; - //bool timerflag = false; - int16_t ecgSample_1sec[700]; - int16_t onesec_counter = 0; - int16_t sample = 300; - while(1) - { - - if (timer_fast.read() > 1) - { - //timerflag = 1; - ledA = !ledA; - timer_fast.reset(); - int8_t header_device_id[3] = {0,0,210}; - int8_t header_packet_type[2] = {0,2}; - int8_t header_packet_id[4] = {0,0,0,0}; - int8_t header_ecg_datalen[2] = {0,onesec_counter}; - int8_t header_ecg_checksum[2] = {0,0}; - - - //pc.printf("%6d\r\n", sample); - //pc.printf("%6d\r\n", onesec_counter); - - onesec_counter = 0; - } + while(1) { + // Read back ECG samples from the FIFO - else if( (ecgFIFOIntFlag==1))// && (timerflag == 0)) - { + if( ecgFIFOIntFlag ) { ecgFIFOIntFlag = 0; status = ecgAFE.readRegister( MAX30003::STATUS ); // Read the STATUS register // Check if EINT interrupt asserted - if ( ( status & EINT_STATUS_MASK ) == EINT_STATUS_MASK ) - { + if ( ( status & EINT_STATUS_MASK ) == EINT_STATUS_MASK ) { readECGSamples = 0; // Reset sample counter @@ -99,45 +69,27 @@ ETAG[readECGSamples-1] == FIFO_FAST_SAMPLE_MASK ); // Check if FIFO has overflowed - if( ETAG[readECGSamples - 1] == FIFO_OVF_MASK ) - { + if( ETAG[readECGSamples - 1] == FIFO_OVF_MASK ){ ecgAFE.writeRegister( MAX30003::FIFO_RST , 0); // Reset FIFO - rLed = 1;//notifies the user that an over flow occured + bLed = 1;//notifies the user that an over flow occured } // Print results - for( idx = 0; idx < readECGSamples; idx++ ) - { - //pc.printf("%6d\r\n", ecgSample[idx]); - ecgSample_1sec[onesec_counter] = ecgSample[idx]; - onesec_counter++; + for( idx = 0; idx < readECGSamples; idx++ ) { + pc.printf("%6d\r\n", ecgSample[idx]); } + bLed = ! bLed; } - // else - // { - // timerflag = 0; - // } - //else if (timerflag == 1) - //{ - //timerflag = 0; - //pc.printf("1 sec ends :\n"); - //onesec_counter = 0; - //timer_fast.reset(); - //timer_fast.start(); - //delete[] ecgSample_1sec; - //} - - } } } - - - - + + + + void ecg_config(MAX30003& ecgAFE) { - + // Reset ECG to clear registers ecgAFE.writeRegister( MAX30003::SW_RST , 0); @@ -195,5 +147,4 @@ ecgAFE.writeRegister( MAX30003::CNFG_EMUX , CNFG_MUX_r.all); return; -} - +} \ No newline at end of file