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_HR_SPO2 by
Diff: main.cpp
- Revision:
- 4:14d1b87cd3c4
- Parent:
- 3:a580414c44ce
- Child:
- 5:2f708191f1bd
diff -r a580414c44ce -r 14d1b87cd3c4 main.cpp
--- a/main.cpp Tue Aug 22 14:09:19 2017 +0000
+++ b/main.cpp Tue Aug 22 21:51:07 2017 +0000
@@ -25,11 +25,10 @@
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, P3_4 = SDA, P3_5 = SCL
+ 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);
+ MAX30101 op_sensor(i2cBus); // Create new MAX30101 on i2cBus
+ int rc = op_sensor_config(op_sensor); // Config sensor, return 0 on success
MAX30101::InterruptBitField_u ints;
uint8_t fifoData[MAX30101::MAX_FIFO_BYTES];
@@ -39,23 +38,31 @@
while(1) {
if( rc == 0 ) {
-
+
+ // Check if op_sensor interrupt asserted
if(op_sensorIntFlag) {
+
pc.printf("Interrupt seen...\r\n");
op_sensorIntFlag = 0; // Lower interrupt flag
- rc = op_sensor->getInterruptStatus(ints); // Read interrupt status
+ rc = op_sensor.getInterruptStatus(ints); // Read interrupt status
+ // Check if FIFO almost full interrupt asserted
if((rc == 0) && (ints.bits.a_full)) {
- rc = op_sensor->readFIFO(MAX30101::OneLedChannel, fifoData, readBytes); // Read FIFO
+
+ // Read FIFO
+ rc = op_sensor.readFIFO(MAX30101::OneLedChannel, fifoData, readBytes);
if(rc == 0) {
+
pc.printf("FIFO Read, received %d samples\r\n\r\n", readBytes/3);
+ // Convert read bytes into samples
for(idx = 0; idx < readBytes; idx+=3) {
sample = (fifoData[idx]<<16) | (fifoData[idx+1]<<8) | (fifoData[idx+2]);
- opSample = sample >> 8;
+ opSample = sample >> 8; // Sign extends sample to 16-bit opSample
pc.printf("Op. Sample : %i\r\n", opSample); // Print results
}
+
pc.printf("\r\n\r\n");
}
@@ -64,7 +71,8 @@
} else {
- pc.printf("Something went wrong, check the I2C bus or power connections... \r\n");
+ pc.printf("Something went wrong, "
+ "check the I2C bus or power connections... \r\n");
bLed = LED_OFF;
gLed = LED_OFF;
@@ -104,7 +112,7 @@
{
fifoConfig.all = 0;
fifoConfig.bits.fifo_a_full = 15; // Max level of 15 samples
- fifoConfig.bits.sample_average = MAX30101::AveragedSamples_8; // Average 4 samples
+ fifoConfig.bits.sample_average = MAX30101::AveragedSamples_8; // Average 8 samples
rc = op_sensor.setFIFOConfiguration(fifoConfig);
}
