![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
UCLA CSM119 "How to Approach New Hardware Demo"
Diff: main.cpp
- Revision:
- 1:ad1b075585bc
- Parent:
- 0:33686dd26bf9
- Child:
- 2:9dfb7ebaaa6e
- Child:
- 3:2e12e0cd1f26
--- a/main.cpp Wed May 30 10:40:47 2018 +0000 +++ b/main.cpp Fri Jun 01 10:05:51 2018 +0000 @@ -5,7 +5,8 @@ #define FIFO_DATA_MAX 288 DigitalOut pwr1v8(PTA29); -DigitalOut pwr3v3b(PTB12); +DigitalOut pwr3v3b(PTC13); +DigitalOut pwr15v(PTB12); I2C i2c0(PTB1, PTB0); InterruptIn maximInterrupt(PTB18); Serial pc(USBTX, USBRX); @@ -15,6 +16,8 @@ MAX30101 hr(i2c0); +int mask_ppg = 0; +uint32_t count = 0; void interruptHandlerQueued() { MAX30101::InterruptBitField_u interruptStatus; @@ -24,60 +27,70 @@ if (interruptStatus.bits.pwr_rdy == 0x1) { printf("Powered on\r\n"); + // Soft reset + MAX30101::ModeConfiguration_u modeConf; + modeConf.all = 0; + modeConf.bits.reset = 1; + hr.setModeConfiguration(modeConf); + wait(0.01); + // Configure FIFO MAX30101::FIFO_Configuration_u fifoConf; hr.getFIFOConfiguration(fifoConf); pc.printf("FIFO Configuration: 0x%02x\r\n", fifoConf.all); // Set LED power - hr.setLEDPulseAmplitude(MAX30101::LED1_PA, 0xFF); + hr.setLEDPulseAmplitude(MAX30101::LED1_PA, 0x0C); + hr.setLEDPulseAmplitude(MAX30101::ProxModeLED_PA, 0x19); pc.printf("LED set\r\n"); MAX30101::SpO2Configuration_u spo2Conf; hr.getSpO2Configuration(spo2Conf); + spo2Conf.bits.led_pw = MAX30101::PW_1; + spo2Conf.bits.spo2_sr = MAX30101::SR_100_Hz; + hr.setSpO2Configuration(spo2Conf); + hr.getSpO2Configuration(spo2Conf); pc.printf("SpO2 Configuration: 0x%02x\r\n", spo2Conf.all); + // Proximity settings + hr.setProxIntThreshold(0x14); + // Enable HR mode - MAX30101::ModeConfiguration_u modeConf; modeConf.all = 0; modeConf.bits.mode = MAX30101::HeartRateMode; hr.setModeConfiguration(modeConf); printf("Mode set\r\n"); } + if (interruptStatus.bits.prox_int == 0x1) { + printf("Proximity Triggered, entered HR Mode."); + } + if (interruptStatus.bits.ppg_rdy == 0x1) { printf("PPG Ready.\r\n"); - maximInterrupt.disable_irq(); - while (true) { - hr.getInterruptStatus(interruptStatus); - printf("Interrupt Status: 0x%02x\r\n", interruptStatus.all); - if (interruptStatus.bits.ppg_rdy == 0x1) { - uint8_t byte; - hr.readRegister(MAX30101::FIFO_DataRegister, byte); - printf("Read byte: %hhu\r\n", byte); - hr.readRegister(MAX30101::FIFO_DataRegister, byte); - printf("Read byte: %hhu\r\n", byte); - hr.readRegister(MAX30101::FIFO_DataRegister, byte); - printf("Read byte: %hhu\r\n", byte); - } - } + mask_ppg = 1; } if (interruptStatus.bits.a_full == 0x1) { printf("FIFO Almost Full.\r\n"); -// uint8_t data[FIFO_DATA_MAX]; -// uint16_t readBytes = 0; -// hr.readFIFO(MAX30101::OneLedChannel, data, readBytes); -// printf("FIFO has %hu bytes of data\r\n", readBytes); -// -// for (uint16_t i = 0; i < readBytes; i += 3) { -// uint8_t sample[4] = {0}; -// memcpy(sample, data + i, 3); -// printf("Read data: %u\r\n", *(uint32_t *) sample); -// } + uint8_t data[FIFO_DATA_MAX]; + uint16_t readBytes = 0; + hr.readFIFO(MAX30101::OneLedChannel, data, readBytes); + + for (uint16_t i = 0; i < readBytes; i += 3) { + uint8_t sample[4] = {0}; + sample[0] = data[i + 2]; + sample[1] = data[i + 1]; + sample[2] = data[i]; + + printf("%u\r\n", *(uint32_t *) sample); + } } interruptStatus.all = 0xFF; + if (mask_ppg == 1) { + interruptStatus.bits.ppg_rdy = 0; + } hr.enableInterrupts(interruptStatus); } @@ -93,6 +106,7 @@ pwr1v8 = 1; pwr3v3b = 1; + pwr15v = 0; maximInterrupt.fall(interruptHandler); maximInterrupt.enable_irq(); @@ -101,19 +115,6 @@ interruptStatus.all = 0xFF; hr.enableInterrupts(interruptStatus); -// MAX30101::FIFO_Configuration_u fifoConf; -// hr.getFIFOConfiguration(fifoConf); -// pc.printf("FIFO Configuration: 0x%02x\r\n", fifoConf.all); -// -// MAX30101::ModeConfiguration_u modeConf; -// hr.getModeConfiguration(modeConf); -// pc.printf("Mode Configuration: 0x%02x\r\n", modeConf.all); -// - -// while (true) { -// wait(1); -// printf("%d\r\n", maximInterrupt.read()); -// } return 0; }