![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
k
Dependencies: MAX30003 max32630fthr
main.cpp@12:10b49ad3c492, 2020-09-29 (annotated)
- Committer:
- parthsagar2010
- Date:
- Tue Sep 29 19:00:06 2020 +0000
- Revision:
- 12:10b49ad3c492
- Parent:
- 11:300afaf2696b
- Child:
- 13:0e7bbc06083f
Timestamp_beta
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
coreyharris | 6:86ac850c718d | 1 | |
parthsagar2010 | 8:6b9359f81cc0 | 2 | #include "MAX30003.h" |
coreyharris | 0:38c49bc37c7c | 3 | #include "mbed.h" |
coreyharris | 0:38c49bc37c7c | 4 | #include "max32630fthr.h" |
parthsagar2010 | 9:24ecf16eab0f | 5 | #include "ds1307.h" |
parthsagar2010 | 11:300afaf2696b | 6 | //#include <BufferedSerial.h> |
parthsagar2010 | 10:54aa50490b15 | 7 | #include <string> |
parthsagar2010 | 10:54aa50490b15 | 8 | //#include <Serial.h> |
parthsagar2010 | 11:300afaf2696b | 9 | |
parthsagar2010 | 11:300afaf2696b | 10 | #define TARGET_TX_PIN P3_1 |
parthsagar2010 | 11:300afaf2696b | 11 | #define TARGET_RX_PIN P3_0 |
parthsagar2010 | 11:300afaf2696b | 12 | |
parthsagar2010 | 9:24ecf16eab0f | 13 | Timer timer_fast; |
parthsagar2010 | 10:54aa50490b15 | 14 | Timer t; |
coreyharris | 0:38c49bc37c7c | 15 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
coreyharris | 0:38c49bc37c7c | 16 | |
parthsagar2010 | 9:24ecf16eab0f | 17 | void task_fast(void); |
parthsagar2010 | 9:24ecf16eab0f | 18 | DigitalOut ledA(LED2); |
coreyharris | 0:38c49bc37c7c | 19 | void ecg_config(MAX30003 &ecgAFE); |
parthsagar2010 | 11:300afaf2696b | 20 | //BufferedSerial pc(P3_1,P3_0); // Use USB debug probe for serial link static Unbuffered |
parthsagar2010 | 12:10b49ad3c492 | 21 | static BufferedSerial pc(TARGET_TX_PIN, TARGET_RX_PIN, 9600); |
parthsagar2010 | 11:300afaf2696b | 22 | |
parthsagar2010 | 10:54aa50490b15 | 23 | //Serial uart_1(USBTX, USBRX); // Use USB debug probe for serial link static Unbuffered |
parthsagar2010 | 10:54aa50490b15 | 24 | // |
parthsagar2010 | 10:54aa50490b15 | 25 | //Serial pc(P3_1,P3_0); |
coreyharris | 0:38c49bc37c7c | 26 | volatile bool ecgFIFOIntFlag = 0; |
parthsagar2010 | 9:24ecf16eab0f | 27 | volatile bool timerflag = 0; |
parthsagar2010 | 11:300afaf2696b | 28 | |
parthsagar2010 | 11:300afaf2696b | 29 | FileHandle *mbed::mbed_override_console(int fd) |
parthsagar2010 | 11:300afaf2696b | 30 | { |
parthsagar2010 | 11:300afaf2696b | 31 | return &pc; |
parthsagar2010 | 11:300afaf2696b | 32 | } |
parthsagar2010 | 11:300afaf2696b | 33 | |
parthsagar2010 | 8:6b9359f81cc0 | 34 | void ecgFIFO_callback_1() { // Triggered when the ECG FIFO is about to be full |
coreyharris | 0:38c49bc37c7c | 35 | |
coreyharris | 0:38c49bc37c7c | 36 | ecgFIFOIntFlag = 1; |
coreyharris | 0:38c49bc37c7c | 37 | } |
coreyharris | 0:38c49bc37c7c | 38 | |
parthsagar2010 | 12:10b49ad3c492 | 39 | time_t asUnixTime(int year, int mon, int mday, int hour, int min, int sec) { |
parthsagar2010 | 12:10b49ad3c492 | 40 | struct tm t; |
parthsagar2010 | 12:10b49ad3c492 | 41 | t.tm_year = year - 1900; |
parthsagar2010 | 12:10b49ad3c492 | 42 | t.tm_mon = mon - 1; // convert to 0 based month |
parthsagar2010 | 12:10b49ad3c492 | 43 | t.tm_mday = mday; |
parthsagar2010 | 12:10b49ad3c492 | 44 | t.tm_hour = hour; |
parthsagar2010 | 12:10b49ad3c492 | 45 | t.tm_min = min; |
parthsagar2010 | 12:10b49ad3c492 | 46 | t.tm_sec = sec; |
parthsagar2010 | 12:10b49ad3c492 | 47 | t.tm_isdst = -1; // Is Daylight saving time on? 1 = yes, 0 = no, -1 = unknown |
parthsagar2010 | 12:10b49ad3c492 | 48 | |
parthsagar2010 | 12:10b49ad3c492 | 49 | return mktime(&t); // returns seconds elapsed since January 1, 1970 (begin of the Epoch) |
parthsagar2010 | 12:10b49ad3c492 | 50 | } |
parthsagar2010 | 11:300afaf2696b | 51 | int main(void) |
coreyharris | 3:420d5efbd967 | 52 | { |
parthsagar2010 | 11:300afaf2696b | 53 | // Constants |
coreyharris | 4:06e258ff0b97 | 54 | const int EINT_STATUS_MASK = 1 << 23; |
coreyharris | 6:86ac850c718d | 55 | const int FIFO_OVF_MASK = 0x7; |
coreyharris | 6:86ac850c718d | 56 | const int FIFO_VALID_SAMPLE_MASK = 0x0; |
coreyharris | 6:86ac850c718d | 57 | const int FIFO_FAST_SAMPLE_MASK = 0x1; |
coreyharris | 6:86ac850c718d | 58 | const int ETAG_BITS_MASK = 0x7; |
parthsagar2010 | 9:24ecf16eab0f | 59 | timer_fast.start(); |
parthsagar2010 | 8:6b9359f81cc0 | 60 | DigitalOut rLed(LED1, LED_OFF); |
parthsagar2010 | 10:54aa50490b15 | 61 | // pc.baud(9600); |
coreyharris | 3:420d5efbd967 | 62 | |
parthsagar2010 | 11:300afaf2696b | 63 | //pc.set_baud(115200); // Baud rate = 115200 |
parthsagar2010 | 11:300afaf2696b | 64 | //pc.set_format( |
parthsagar2010 | 11:300afaf2696b | 65 | // /* bits */ 8, |
parthsagar2010 | 11:300afaf2696b | 66 | // /* parity */ BufferedSerial::None, |
parthsagar2010 | 11:300afaf2696b | 67 | // /* stop bit */ 1 //1 |
parthsagar2010 | 11:300afaf2696b | 68 | //); |
parthsagar2010 | 10:54aa50490b15 | 69 | //uart_1.baud(115200); |
coreyharris | 1:86843c27cc81 | 70 | InterruptIn ecgFIFO_int(P5_4); // Config P5_4 as int. in for the |
parthsagar2010 | 8:6b9359f81cc0 | 71 | ecgFIFO_int.fall(&ecgFIFO_callback_1); // ecg FIFO interrupt at falling edge |
coreyharris | 0:38c49bc37c7c | 72 | |
coreyharris | 1:86843c27cc81 | 73 | SPI spiBus(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // SPI bus, P5_1 = MOSI, |
coreyharris | 1:86843c27cc81 | 74 | // P5_2 = MISO, P5_0 = SCK |
parthsagar2010 | 10:54aa50490b15 | 75 | |
coreyharris | 4:06e258ff0b97 | 76 | MAX30003 ecgAFE(spiBus, P5_3); // New MAX30003 on spiBus, CS = P5_3 |
parthsagar2010 | 8:6b9359f81cc0 | 77 | |
coreyharris | 4:06e258ff0b97 | 78 | ecg_config(ecgAFE); // Config ECG |
parthsagar2010 | 12:10b49ad3c492 | 79 | |
coreyharris | 0:38c49bc37c7c | 80 | |
coreyharris | 4:06e258ff0b97 | 81 | ecgAFE.writeRegister( MAX30003::SYNCH , 0); |
coreyharris | 0:38c49bc37c7c | 82 | |
coreyharris | 4:06e258ff0b97 | 83 | uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status; |
coreyharris | 1:86843c27cc81 | 84 | int16_t ecgSample[32]; |
parthsagar2010 | 9:24ecf16eab0f | 85 | //bool timerflag = false; |
parthsagar2010 | 10:54aa50490b15 | 86 | int16_t ecgSample_1sec[200]; |
parthsagar2010 | 10:54aa50490b15 | 87 | uint8_t ecg_1 = 0; |
parthsagar2010 | 10:54aa50490b15 | 88 | uint8_t ecg_2 = 0; |
parthsagar2010 | 10:54aa50490b15 | 89 | uint16_t onesec_counter = 0; |
parthsagar2010 | 10:54aa50490b15 | 90 | uint16_t onesec_counter_temp = 0; |
parthsagar2010 | 10:54aa50490b15 | 91 | |
parthsagar2010 | 9:24ecf16eab0f | 92 | int16_t sample = 300; |
parthsagar2010 | 10:54aa50490b15 | 93 | uint8_t final[10]; |
parthsagar2010 | 12:10b49ad3c492 | 94 | |
parthsagar2010 | 10:54aa50490b15 | 95 | uint16_t checksum_ = 0; |
parthsagar2010 | 10:54aa50490b15 | 96 | uint16_t mod_checksum = 0; |
parthsagar2010 | 10:54aa50490b15 | 97 | |
parthsagar2010 | 10:54aa50490b15 | 98 | uint8_t p_1 = 0; |
parthsagar2010 | 10:54aa50490b15 | 99 | uint8_t p_2 = 0; |
parthsagar2010 | 10:54aa50490b15 | 100 | uint8_t p_3 = 0; |
parthsagar2010 | 10:54aa50490b15 | 101 | uint8_t p_4 = 0; |
parthsagar2010 | 10:54aa50490b15 | 102 | |
parthsagar2010 | 10:54aa50490b15 | 103 | uint8_t data_len_1 = 0; |
parthsagar2010 | 10:54aa50490b15 | 104 | uint8_t data_len_2 = 0; |
parthsagar2010 | 12:10b49ad3c492 | 105 | uint32_t packet_1 = 0; |
parthsagar2010 | 10:54aa50490b15 | 106 | uint8_t cksm_1 = 0; |
parthsagar2010 | 10:54aa50490b15 | 107 | uint8_t cksm_2 = 0; |
parthsagar2010 | 10:54aa50490b15 | 108 | uint8_t header_device_id[3] = {0,0,210}; |
parthsagar2010 | 10:54aa50490b15 | 109 | uint8_t header_packet_type[2] = {0,2}; |
parthsagar2010 | 10:54aa50490b15 | 110 | |
parthsagar2010 | 10:54aa50490b15 | 111 | uint8_t ending[5] = {'@','#','%','!','7'}; |
parthsagar2010 | 10:54aa50490b15 | 112 | |
parthsagar2010 | 11:300afaf2696b | 113 | char buf[20]; |
parthsagar2010 | 11:300afaf2696b | 114 | pc.write("Welcome",8*sizeof(char)); |
parthsagar2010 | 11:300afaf2696b | 115 | printf("In the main loop"); |
parthsagar2010 | 11:300afaf2696b | 116 | bool flag_first = false; |
parthsagar2010 | 12:10b49ad3c492 | 117 | int counter_reader = 0; |
parthsagar2010 | 11:300afaf2696b | 118 | do |
parthsagar2010 | 11:300afaf2696b | 119 | { |
parthsagar2010 | 12:10b49ad3c492 | 120 | if (pc.readable()) |
parthsagar2010 | 12:10b49ad3c492 | 121 | { |
parthsagar2010 | 11:300afaf2696b | 122 | scanf("%s",buf); |
parthsagar2010 | 11:300afaf2696b | 123 | printf("The entered string is %s : \n ",buf); |
parthsagar2010 | 12:10b49ad3c492 | 124 | |
parthsagar2010 | 12:10b49ad3c492 | 125 | packet_1 = atoi(buf); |
parthsagar2010 | 12:10b49ad3c492 | 126 | set_time(packet_1); |
parthsagar2010 | 12:10b49ad3c492 | 127 | |
parthsagar2010 | 12:10b49ad3c492 | 128 | counter_reader++; |
parthsagar2010 | 12:10b49ad3c492 | 129 | //flag_first = true; |
coreyharris | 2:812d40f1853d | 130 | |
parthsagar2010 | 11:300afaf2696b | 131 | } |
parthsagar2010 | 11:300afaf2696b | 132 | |
parthsagar2010 | 12:10b49ad3c492 | 133 | }while (counter_reader<=3); // take the third timestamp |
parthsagar2010 | 11:300afaf2696b | 134 | while(1) |
parthsagar2010 | 9:24ecf16eab0f | 135 | { |
parthsagar2010 | 10:54aa50490b15 | 136 | |
parthsagar2010 | 9:24ecf16eab0f | 137 | |
parthsagar2010 | 12:10b49ad3c492 | 138 | if (timer_fast.read() >= 0.95) |
parthsagar2010 | 9:24ecf16eab0f | 139 | { |
parthsagar2010 | 11:300afaf2696b | 140 | //t.start(); |
parthsagar2010 | 10:54aa50490b15 | 141 | //ledA = !ledA; |
parthsagar2010 | 12:10b49ad3c492 | 142 | |
parthsagar2010 | 10:54aa50490b15 | 143 | |
parthsagar2010 | 10:54aa50490b15 | 144 | pc.write((uint8_t *)header_device_id, sizeof(header_device_id)); |
parthsagar2010 | 10:54aa50490b15 | 145 | |
parthsagar2010 | 10:54aa50490b15 | 146 | pc.write((uint8_t *)header_packet_type, sizeof(header_packet_type)); |
parthsagar2010 | 12:10b49ad3c492 | 147 | time_t seconds = time(NULL); |
parthsagar2010 | 12:10b49ad3c492 | 148 | packet_1 = seconds; |
parthsagar2010 | 12:10b49ad3c492 | 149 | //packet_1 ++; |
parthsagar2010 | 12:10b49ad3c492 | 150 | //printf("Time as seconds since January 1, 1970 = %d\n", packet_1); |
parthsagar2010 | 10:54aa50490b15 | 151 | p_1 = packet_1 & 0xff; |
parthsagar2010 | 10:54aa50490b15 | 152 | p_2 = (packet_1 >> 8) & 0xff; |
parthsagar2010 | 10:54aa50490b15 | 153 | p_3 = (packet_1 >> 16) & 0xff; |
parthsagar2010 | 10:54aa50490b15 | 154 | p_4 = (packet_1 >> 24) & 0xff; |
parthsagar2010 | 10:54aa50490b15 | 155 | // checksum_ = checksum_ + (packet_1 & 0xffff) + ((packet_1 >> 16) & 0xffff) ; |
parthsagar2010 | 10:54aa50490b15 | 156 | checksum_ = checksum_ + p_1 + p_2 + p_3 + p_4 ; |
parthsagar2010 | 10:54aa50490b15 | 157 | uint8_t header_packet_id[4] = {p_4,p_3,p_2,p_1}; |
parthsagar2010 | 10:54aa50490b15 | 158 | pc.write((uint8_t *)header_packet_id, sizeof(header_packet_id)); |
parthsagar2010 | 10:54aa50490b15 | 159 | onesec_counter_temp = onesec_counter * 2; |
parthsagar2010 | 10:54aa50490b15 | 160 | data_len_1 = onesec_counter_temp & 0xff; |
parthsagar2010 | 10:54aa50490b15 | 161 | data_len_2 = (onesec_counter_temp >> 8) & 0xff; |
parthsagar2010 | 10:54aa50490b15 | 162 | checksum_ = checksum_ + data_len_1 + data_len_2; |
parthsagar2010 | 10:54aa50490b15 | 163 | //pc.write((uint32_t *)packet_1, sizeof(packet_1)); |
parthsagar2010 | 10:54aa50490b15 | 164 | uint8_t header_ecg_datalen[2] = {data_len_2,data_len_1}; |
parthsagar2010 | 10:54aa50490b15 | 165 | pc.write((uint8_t *)header_ecg_datalen, sizeof(header_ecg_datalen)); |
parthsagar2010 | 10:54aa50490b15 | 166 | mod_checksum = checksum_ % 65536 ; |
parthsagar2010 | 10:54aa50490b15 | 167 | cksm_1 = mod_checksum & 0xff; |
parthsagar2010 | 10:54aa50490b15 | 168 | cksm_2 = (mod_checksum >> 8) & 0xff; |
parthsagar2010 | 10:54aa50490b15 | 169 | uint8_t header_ecg_checksum[2] = {cksm_2,cksm_1}; |
parthsagar2010 | 10:54aa50490b15 | 170 | pc.write((uint8_t *)header_ecg_checksum, sizeof(header_ecg_checksum)); |
parthsagar2010 | 10:54aa50490b15 | 171 | |
parthsagar2010 | 10:54aa50490b15 | 172 | pc.write((int16_t *)ecgSample_1sec,onesec_counter * sizeof(int16_t)); |
parthsagar2010 | 10:54aa50490b15 | 173 | onesec_counter = 0; |
parthsagar2010 | 10:54aa50490b15 | 174 | // memset(ecgSample_1sec, 0, sizeof(ecgSample_1sec)); |
parthsagar2010 | 10:54aa50490b15 | 175 | |
parthsagar2010 | 10:54aa50490b15 | 176 | pc.write((uint8_t *)ending, sizeof(ending)); |
parthsagar2010 | 10:54aa50490b15 | 177 | checksum_ = 0; |
parthsagar2010 | 11:300afaf2696b | 178 | // t.stop(); |
parthsagar2010 | 11:300afaf2696b | 179 | // auto us = t.elapsed_time().count(); |
parthsagar2010 | 11:300afaf2696b | 180 | // printf("Timer time: %llu ms \n", us); |
parthsagar2010 | 9:24ecf16eab0f | 181 | timer_fast.reset(); |
parthsagar2010 | 9:24ecf16eab0f | 182 | } |
coreyharris | 4:06e258ff0b97 | 183 | // Read back ECG samples from the FIFO |
parthsagar2010 | 9:24ecf16eab0f | 184 | else if( (ecgFIFOIntFlag==1))// && (timerflag == 0)) |
parthsagar2010 | 9:24ecf16eab0f | 185 | { |
coreyharris | 2:812d40f1853d | 186 | |
coreyharris | 5:f8d1f651bef5 | 187 | ecgFIFOIntFlag = 0; |
coreyharris | 4:06e258ff0b97 | 188 | status = ecgAFE.readRegister( MAX30003::STATUS ); // Read the STATUS register |
coreyharris | 2:812d40f1853d | 189 | |
coreyharris | 3:420d5efbd967 | 190 | // Check if EINT interrupt asserted |
parthsagar2010 | 9:24ecf16eab0f | 191 | if ( ( status & EINT_STATUS_MASK ) == EINT_STATUS_MASK ) |
parthsagar2010 | 9:24ecf16eab0f | 192 | { |
coreyharris | 3:420d5efbd967 | 193 | |
coreyharris | 4:06e258ff0b97 | 194 | readECGSamples = 0; // Reset sample counter |
coreyharris | 3:420d5efbd967 | 195 | |
coreyharris | 2:812d40f1853d | 196 | do { |
coreyharris | 6:86ac850c718d | 197 | ecgFIFO = ecgAFE.readRegister( MAX30003::ECG_FIFO ); // Read FIFO |
coreyharris | 4:06e258ff0b97 | 198 | ecgSample[readECGSamples] = ecgFIFO >> 8; // Isolate voltage data |
parthsagar2010 | 10:54aa50490b15 | 199 | ecgSample[readECGSamples] = ((ecgSample[readECGSamples]<<8)&0xFF00)|((ecgSample[readECGSamples]>>8)&0x00FF); |
coreyharris | 6:86ac850c718d | 200 | ETAG[readECGSamples] = ( ecgFIFO >> 3 ) & ETAG_BITS_MASK; // Isolate ETAG |
coreyharris | 4:06e258ff0b97 | 201 | readECGSamples++; // Increment sample counter |
coreyharris | 3:420d5efbd967 | 202 | |
coreyharris | 3:420d5efbd967 | 203 | // Check that sample is not last sample in FIFO |
coreyharris | 6:86ac850c718d | 204 | } while ( ETAG[readECGSamples-1] == FIFO_VALID_SAMPLE_MASK || |
coreyharris | 6:86ac850c718d | 205 | ETAG[readECGSamples-1] == FIFO_FAST_SAMPLE_MASK ); |
coreyharris | 2:812d40f1853d | 206 | |
coreyharris | 3:420d5efbd967 | 207 | // Check if FIFO has overflowed |
parthsagar2010 | 9:24ecf16eab0f | 208 | if( ETAG[readECGSamples - 1] == FIFO_OVF_MASK ) |
parthsagar2010 | 9:24ecf16eab0f | 209 | { |
coreyharris | 3:420d5efbd967 | 210 | ecgAFE.writeRegister( MAX30003::FIFO_RST , 0); // Reset FIFO |
johnGreeneMaxim | 7:cf0855a0450a | 211 | rLed = 1;//notifies the user that an over flow occured |
coreyharris | 3:420d5efbd967 | 212 | } |
parthsagar2010 | 10:54aa50490b15 | 213 | //uint8_t header_ecg_checksum[2] = {'%','%'}; |
parthsagar2010 | 10:54aa50490b15 | 214 | //pc.write((uint8_t *)header_ecg_checksum, sizeof(header_ecg_checksum)); |
coreyharris | 3:420d5efbd967 | 215 | |
parthsagar2010 | 10:54aa50490b15 | 216 | //pc.write((int16_t *)ecgSample,readECGSamples * sizeof(int16_t )); |
parthsagar2010 | 10:54aa50490b15 | 217 | //memcpy(ecgSample_1sec , ecgSample, sizeof(ecgSample)); |
parthsagar2010 | 10:54aa50490b15 | 218 | |
parthsagar2010 | 10:54aa50490b15 | 219 | //memcpy(ecgSample_1sec + (onesec_counter * sizeof(int16_t)), ecgSample, sizeof(ecgSample)); |
parthsagar2010 | 10:54aa50490b15 | 220 | for( idx = 0; idx < readECGSamples; idx++ ) |
parthsagar2010 | 9:24ecf16eab0f | 221 | { |
parthsagar2010 | 9:24ecf16eab0f | 222 | //pc.printf("%6d\r\n", ecgSample[idx]); |
parthsagar2010 | 9:24ecf16eab0f | 223 | ecgSample_1sec[onesec_counter] = ecgSample[idx]; |
parthsagar2010 | 10:54aa50490b15 | 224 | |
parthsagar2010 | 10:54aa50490b15 | 225 | cksm_1 = ecgSample[idx] & 0xff; |
parthsagar2010 | 10:54aa50490b15 | 226 | cksm_2 = (ecgSample[idx] >> 8) & 0xff; |
parthsagar2010 | 10:54aa50490b15 | 227 | checksum_ += cksm_1 + cksm_2; |
parthsagar2010 | 9:24ecf16eab0f | 228 | onesec_counter++; |
coreyharris | 6:86ac850c718d | 229 | } |
parthsagar2010 | 11:300afaf2696b | 230 | |
coreyharris | 0:38c49bc37c7c | 231 | } |
parthsagar2010 | 10:54aa50490b15 | 232 | |
coreyharris | 0:38c49bc37c7c | 233 | } |
coreyharris | 0:38c49bc37c7c | 234 | } |
coreyharris | 0:38c49bc37c7c | 235 | } |
coreyharris | 0:38c49bc37c7c | 236 | |
coreyharris | 0:38c49bc37c7c | 237 | |
coreyharris | 0:38c49bc37c7c | 238 | |
coreyharris | 0:38c49bc37c7c | 239 | |
coreyharris | 0:38c49bc37c7c | 240 | void ecg_config(MAX30003& ecgAFE) { |
coreyharris | 0:38c49bc37c7c | 241 | |
coreyharris | 1:86843c27cc81 | 242 | // Reset ECG to clear registers |
coreyharris | 1:86843c27cc81 | 243 | ecgAFE.writeRegister( MAX30003::SW_RST , 0); |
coreyharris | 0:38c49bc37c7c | 244 | |
coreyharris | 1:86843c27cc81 | 245 | // General config register setting |
coreyharris | 1:86843c27cc81 | 246 | MAX30003::GeneralConfiguration_u CNFG_GEN_r; |
coreyharris | 3:420d5efbd967 | 247 | CNFG_GEN_r.bits.en_ecg = 1; // Enable ECG channel |
coreyharris | 3:420d5efbd967 | 248 | CNFG_GEN_r.bits.rbiasn = 1; // Enable resistive bias on negative input |
coreyharris | 3:420d5efbd967 | 249 | CNFG_GEN_r.bits.rbiasp = 1; // Enable resistive bias on positive input |
coreyharris | 3:420d5efbd967 | 250 | CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias |
coreyharris | 3:420d5efbd967 | 251 | CNFG_GEN_r.bits.imag = 2; // Current magnitude = 10nA |
coreyharris | 3:420d5efbd967 | 252 | CNFG_GEN_r.bits.en_dcloff = 1; // Enable DC lead-off detection |
parthsagar2010 | 12:10b49ad3c492 | 253 | //CNFG_GEN_r.bits.fmstr = 1; //125 sps FMSTR 1 |
coreyharris | 1:86843c27cc81 | 254 | ecgAFE.writeRegister( MAX30003::CNFG_GEN , CNFG_GEN_r.all); |
coreyharris | 1:86843c27cc81 | 255 | |
coreyharris | 1:86843c27cc81 | 256 | |
coreyharris | 1:86843c27cc81 | 257 | // ECG Config register setting |
coreyharris | 1:86843c27cc81 | 258 | MAX30003::ECGConfiguration_u CNFG_ECG_r; |
coreyharris | 3:420d5efbd967 | 259 | CNFG_ECG_r.bits.dlpf = 1; // Digital LPF cutoff = 40Hz |
coreyharris | 3:420d5efbd967 | 260 | CNFG_ECG_r.bits.dhpf = 1; // Digital HPF cutoff = 0.5Hz |
coreyharris | 3:420d5efbd967 | 261 | CNFG_ECG_r.bits.gain = 3; // ECG gain = 160V/V |
coreyharris | 3:420d5efbd967 | 262 | CNFG_ECG_r.bits.rate = 2; // Sample rate = 128 sps |
coreyharris | 1:86843c27cc81 | 263 | ecgAFE.writeRegister( MAX30003::CNFG_ECG , CNFG_ECG_r.all); |
coreyharris | 1:86843c27cc81 | 264 | |
coreyharris | 1:86843c27cc81 | 265 | |
coreyharris | 1:86843c27cc81 | 266 | //R-to-R configuration |
coreyharris | 1:86843c27cc81 | 267 | MAX30003::RtoR1Configuration_u CNFG_RTOR_r; |
coreyharris | 3:420d5efbd967 | 268 | CNFG_RTOR_r.bits.en_rtor = 1; // Enable R-to-R detection |
coreyharris | 1:86843c27cc81 | 269 | ecgAFE.writeRegister( MAX30003::CNFG_RTOR1 , CNFG_RTOR_r.all); |
coreyharris | 1:86843c27cc81 | 270 | |
coreyharris | 1:86843c27cc81 | 271 | |
coreyharris | 1:86843c27cc81 | 272 | //Manage interrupts register setting |
coreyharris | 1:86843c27cc81 | 273 | MAX30003::ManageInterrupts_u MNG_INT_r; |
coreyharris | 3:420d5efbd967 | 274 | MNG_INT_r.bits.efit = 0b00011; // Assert EINT w/ 4 unread samples |
coreyharris | 3:420d5efbd967 | 275 | MNG_INT_r.bits.clr_rrint = 0b01; // Clear R-to-R on RTOR reg. read back |
coreyharris | 1:86843c27cc81 | 276 | ecgAFE.writeRegister( MAX30003::MNGR_INT , MNG_INT_r.all); |
coreyharris | 0:38c49bc37c7c | 277 | |
coreyharris | 0:38c49bc37c7c | 278 | |
coreyharris | 1:86843c27cc81 | 279 | //Enable interrupts register setting |
coreyharris | 1:86843c27cc81 | 280 | MAX30003::EnableInterrupts_u EN_INT_r; |
coreyharris | 5:f8d1f651bef5 | 281 | EN_INT_r.all = 0; |
coreyharris | 3:420d5efbd967 | 282 | EN_INT_r.bits.en_eint = 1; // Enable EINT interrupt |
coreyharris | 4:06e258ff0b97 | 283 | EN_INT_r.bits.en_rrint = 0; // Disable R-to-R interrupt |
coreyharris | 3:420d5efbd967 | 284 | EN_INT_r.bits.intb_type = 3; // Open-drain NMOS with internal pullup |
coreyharris | 1:86843c27cc81 | 285 | ecgAFE.writeRegister( MAX30003::EN_INT , EN_INT_r.all); |
coreyharris | 1:86843c27cc81 | 286 | |
coreyharris | 1:86843c27cc81 | 287 | |
coreyharris | 1:86843c27cc81 | 288 | //Dyanmic modes config |
coreyharris | 1:86843c27cc81 | 289 | MAX30003::ManageDynamicModes_u MNG_DYN_r; |
coreyharris | 3:420d5efbd967 | 290 | MNG_DYN_r.bits.fast = 0; // Fast recovery mode disabled |
coreyharris | 1:86843c27cc81 | 291 | ecgAFE.writeRegister( MAX30003::MNGR_DYN , MNG_DYN_r.all); |
coreyharris | 5:f8d1f651bef5 | 292 | |
coreyharris | 5:f8d1f651bef5 | 293 | // MUX Config |
coreyharris | 5:f8d1f651bef5 | 294 | MAX30003::MuxConfiguration_u CNFG_MUX_r; |
coreyharris | 5:f8d1f651bef5 | 295 | CNFG_MUX_r.bits.openn = 0; // Connect ECGN to AFE channel |
coreyharris | 5:f8d1f651bef5 | 296 | CNFG_MUX_r.bits.openp = 0; // Connect ECGP to AFE channel |
coreyharris | 5:f8d1f651bef5 | 297 | ecgAFE.writeRegister( MAX30003::CNFG_EMUX , CNFG_MUX_r.all); |
coreyharris | 1:86843c27cc81 | 298 | |
coreyharris | 1:86843c27cc81 | 299 | return; |
coreyharris | 0:38c49bc37c7c | 300 | } |
coreyharris | 0:38c49bc37c7c | 301 |