Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX30101 max32630fthr
Fork of MAX30101_Demo_Plot_Algorithm by
Diff: main.cpp
- Revision:
- 1:471e2b722d24
- Parent:
- 0:0bd4103885bf
- Child:
- 2:54182d6a168f
diff -r 0bd4103885bf -r 471e2b722d24 main.cpp --- a/main.cpp Thu Aug 17 15:53:16 2017 +0000 +++ b/main.cpp Mon Aug 21 15:43:51 2017 +0000 @@ -7,65 +7,56 @@ bool op_sensor_config(MAX30101 &op_sensor); /* Op Sensor FIFO nearly full callback */ -volatile bool op_sensorIntFlag = false; +volatile bool op_sensorIntFlag = 0; void op_sensor_callback() { - op_sensorIntFlag = true; + op_sensorIntFlag = 1; } int main() { - Serial pc(USBTX, USBRX); - pc.baud(115200); + Serial pc(USBTX, USBRX); // Use USB debug probe for serial link + pc.baud(115200); // Baud rate = 115200 - DigitalOut rLed(LED1, LED_OFF); + DigitalOut rLed(LED1, LED_OFF); // Debug LEDs DigitalOut gLed(LED2, LED_OFF); DigitalOut bLed(LED3, LED_OFF); - InterruptIn op_sensor_int(P3_2); + InterruptIn op_sensor_int(P3_2); // Config P3_2 as int. in for + op_sensor_int.fall(&op_sensor_callback); // FIFO ready interrupt - I2C i2cBus(I2C1_SDA, I2C1_SCL); // I2C bus + I2C i2cBus(I2C1_SDA, I2C1_SCL); // I2C bus, P3_4 = SDA, P3_5 = SCL MAX30101 * op_sensor; op_sensor = new MAX30101(i2cBus); - int rc = op_sensor_config(*op_sensor); - - op_sensor_int.fall(op_sensor_callback); + int rc = op_sensor_config(*op_sensor); MAX30101::InterruptBitField_u ints; uint8_t fifoData[MAX30101::MAX_FIFO_BYTES]; uint16_t idx, readBytes; while(1) { - if( rc == 0 ) - { + if( rc == 0 ) { - if(op_sensorIntFlag) - { - + if(op_sensorIntFlag) { pc.printf("Interrupt seen...\r\n"); - op_sensorIntFlag = false; - rc = op_sensor->getInterruptStatus(ints); + op_sensorIntFlag = 0; // Lower interrupt flag + rc = op_sensor->getInterruptStatus(ints); // Read interrupt status - if((rc == 0) && (ints.bits.a_full)) - { + if((rc == 0) && (ints.bits.a_full)) { + rc = op_sensor->readFIFO(MAX30101::OneLedChannel, fifoData, readBytes); // Read FIFO - rc = op_sensor->readFIFO(MAX30101::OneLedChannel, fifoData, readBytes); - - if(rc == 0) - { - + if(rc == 0) { pc.printf("FIFO Read, received %d bytes\r\n", readBytes); - for(idx = 0; idx < readBytes; idx++) - { - pc.printf("fifoData[0x%04x] = 0x%02x\r\n", idx, fifoData[idx]); + for(idx = 0; idx < readBytes; idx++) { + pc.printf("fifoData[0x%04x] = 0x%02x\r\n", idx, fifoData[idx]); // Print results } pc.printf("\r\n"); } } } - + } else { pc.printf("Something went wrong, check the I2C bus or power connections... \r\n"); @@ -99,8 +90,8 @@ if(rc == 0) { ints.all = 0; - ints.bits.die_temp = 1; - ints.bits.a_full = 1; + ints.bits.die_temp = 1; // Enable FIFO almost full interrupt + ints.bits.a_full = 1; // Enable internal die temp. interrupt rc = op_sensor.enableInterrupts(ints); } @@ -109,16 +100,16 @@ if(rc == 0) { fifoConfig.all = 0; - fifoConfig.bits.fifo_a_full = 15; //Max level of 15 samples - fifoConfig.bits.sample_average = MAX30101::AveragedSamples_4; + fifoConfig.bits.fifo_a_full = 15; // Max level of 15 samples + fifoConfig.bits.sample_average = MAX30101::AveragedSamples_4; // Average 4 samples rc = op_sensor.setFIFOConfiguration(fifoConfig); } MAX30101::SpO2Configuration_u spo2Config; - spo2Config.all = 0; - spo2Config.bits.spo2_sr = MAX30101::SR_1600_Hz; if(rc == 0) { + spo2Config.all = 0; + spo2Config.bits.spo2_sr = MAX30101::SR_400_Hz; // SpO2 SR = 400Hz rc = op_sensor.setSpO2Configuration(spo2Config); } @@ -126,14 +117,14 @@ if(rc == 0) { //Heart Rate only - rc = op_sensor.setLEDPulseAmplitude(MAX30101::LED1_PA, 0x1F); + rc = op_sensor.setLEDPulseAmplitude(MAX30101::LED1_PA, 0x1F); // LED1 = 6.4mA } //Set operating mode modeConfig.all = 0; - modeConfig.bits.mode = MAX30101::HeartRateMode; if(rc == 0) { + modeConfig.bits.mode = MAX30101::HeartRateMode; // Heart-rate only rc = op_sensor.setModeConfiguration(modeConfig); }