
MAX30205EVSYS demo program designed for implementation with the MAX32630FTHR. The MAX30205 can be integrated to the MAX32630FTHR by fly-wires or integration of the MAX30101WING. The program output temperature data every second to a serial terminal.
Dependencies: MAX30205 max32630fthr
Fork of MAX30205_Demo by
main.cpp@7:579d8a8c4e8e, 2018-03-06 (annotated)
- Committer:
- johnGreeneMaxim
- Date:
- Tue Mar 06 03:03:42 2018 +0000
- Revision:
- 7:579d8a8c4e8e
- Parent:
- 6:96c0402be8c5
Added initialization of temp_cfg
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
coreyharris | 5:fb64c72bb867 | 1 | /******************************************************************************* |
coreyharris | 5:fb64c72bb867 | 2 | * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved. |
coreyharris | 5:fb64c72bb867 | 3 | * |
coreyharris | 5:fb64c72bb867 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
coreyharris | 5:fb64c72bb867 | 5 | * copy of this software and associated documentation files (the "Software"), |
coreyharris | 5:fb64c72bb867 | 6 | * to deal in the Software without restriction, including without limitation |
coreyharris | 5:fb64c72bb867 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
coreyharris | 5:fb64c72bb867 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
coreyharris | 5:fb64c72bb867 | 9 | * Software is furnished to do so, subject to the following conditions: |
coreyharris | 5:fb64c72bb867 | 10 | * |
coreyharris | 5:fb64c72bb867 | 11 | * The above copyright notice and this permission notice shall be included |
coreyharris | 5:fb64c72bb867 | 12 | * in all copies or substantial portions of the Software. |
coreyharris | 5:fb64c72bb867 | 13 | * |
coreyharris | 5:fb64c72bb867 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
coreyharris | 5:fb64c72bb867 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
coreyharris | 5:fb64c72bb867 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
coreyharris | 5:fb64c72bb867 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
coreyharris | 5:fb64c72bb867 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
coreyharris | 5:fb64c72bb867 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
coreyharris | 5:fb64c72bb867 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
coreyharris | 5:fb64c72bb867 | 21 | * |
coreyharris | 5:fb64c72bb867 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
coreyharris | 5:fb64c72bb867 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
coreyharris | 5:fb64c72bb867 | 24 | * Products, Inc. Branding Policy. |
coreyharris | 5:fb64c72bb867 | 25 | * |
coreyharris | 5:fb64c72bb867 | 26 | * The mere transfer of this software does not imply any licenses |
coreyharris | 5:fb64c72bb867 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
coreyharris | 5:fb64c72bb867 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
coreyharris | 5:fb64c72bb867 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
coreyharris | 5:fb64c72bb867 | 30 | * ownership rights. |
coreyharris | 5:fb64c72bb867 | 31 | ******************************************************************************* |
coreyharris | 5:fb64c72bb867 | 32 | */ |
coreyharris | 5:fb64c72bb867 | 33 | |
coreyharris | 5:fb64c72bb867 | 34 | |
coreyharris | 0:6e28e543a11c | 35 | #include "mbed.h" |
coreyharris | 0:6e28e543a11c | 36 | #include "max32630fthr.h" |
coreyharris | 0:6e28e543a11c | 37 | #include "MAX30205.h" |
coreyharris | 0:6e28e543a11c | 38 | |
coreyharris | 0:6e28e543a11c | 39 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
coreyharris | 0:6e28e543a11c | 40 | |
coreyharris | 0:6e28e543a11c | 41 | bool temp_sensor_config(MAX30205 &temp_sensor); |
coreyharris | 0:6e28e543a11c | 42 | |
coreyharris | 0:6e28e543a11c | 43 | int main() |
coreyharris | 0:6e28e543a11c | 44 | { |
coreyharris | 0:6e28e543a11c | 45 | |
coreyharris | 3:4a8ab8ffd52d | 46 | Serial pc(USBTX, USBRX); // Use USB debug probe for serial link |
coreyharris | 3:4a8ab8ffd52d | 47 | pc.baud(115200); // Baud rate = 115200 |
coreyharris | 0:6e28e543a11c | 48 | |
coreyharris | 3:4a8ab8ffd52d | 49 | DigitalOut rLed(LED1, LED_OFF); // Debug LEDs |
coreyharris | 0:6e28e543a11c | 50 | |
coreyharris | 3:4a8ab8ffd52d | 51 | I2C i2cBus(I2C1_SDA, I2C1_SCL); // I2C bus, P3_4 = SDA, P3_5 = SCL |
coreyharris | 0:6e28e543a11c | 52 | |
coreyharris | 4:7865b145ff3c | 53 | MAX30205 temp_sensor(i2cBus, 0x48); // New MAX30205 on i2cBus |
coreyharris | 4:7865b145ff3c | 54 | int rc = temp_sensor_config(temp_sensor); // Configure sensor, return 0 on success |
coreyharris | 0:6e28e543a11c | 55 | |
coreyharris | 4:7865b145ff3c | 56 | Timer temp_sensor_sampleTimer; // Create temp. sensor sample timer |
coreyharris | 3:4a8ab8ffd52d | 57 | temp_sensor_sampleTimer.start(); // Start the timer |
coreyharris | 0:6e28e543a11c | 58 | |
coreyharris | 0:6e28e543a11c | 59 | MAX30205::Configuration_u temp_cfg; |
johnGreeneMaxim | 7:579d8a8c4e8e | 60 | temp_cfg.all = 0; |
coreyharris | 0:6e28e543a11c | 61 | uint16_t rawTemperatureRead, temp_conversion_flag; |
coreyharris | 0:6e28e543a11c | 62 | float temperature; |
coreyharris | 0:6e28e543a11c | 63 | |
coreyharris | 0:6e28e543a11c | 64 | while(1) { |
coreyharris | 0:6e28e543a11c | 65 | |
coreyharris | 0:6e28e543a11c | 66 | if( rc == 0 ) { |
coreyharris | 0:6e28e543a11c | 67 | |
coreyharris | 4:7865b145ff3c | 68 | // Start a new temperature conversion |
coreyharris | 4:7865b145ff3c | 69 | if ( ( temp_sensor_sampleTimer.read() > 1.0f ) && !temp_conversion_flag && ( rc == 0 ) ) { |
coreyharris | 0:6e28e543a11c | 70 | |
coreyharris | 0:6e28e543a11c | 71 | temp_cfg.bits.one_shot = 1; |
coreyharris | 5:fb64c72bb867 | 72 | rc = temp_sensor.writeConfiguration(temp_cfg); // Send one-shot cmd to begin conversion |
coreyharris | 2:cf07a3eb2f30 | 73 | temp_conversion_flag = 1; // Raise flag indicating a conversion has begun |
coreyharris | 0:6e28e543a11c | 74 | |
coreyharris | 0:6e28e543a11c | 75 | } |
coreyharris | 0:6e28e543a11c | 76 | |
coreyharris | 4:7865b145ff3c | 77 | // Read the completed temperature conversion |
coreyharris | 4:7865b145ff3c | 78 | if ( ( temp_sensor_sampleTimer.read() > 1.05f ) && temp_conversion_flag && ( rc == 0 ) ){ |
coreyharris | 0:6e28e543a11c | 79 | |
coreyharris | 2:cf07a3eb2f30 | 80 | temp_conversion_flag = 0; // Lower flag when conversion has completed |
coreyharris | 5:fb64c72bb867 | 81 | rc = temp_sensor.readTemperature(rawTemperatureRead); // Read the temperature data |
coreyharris | 5:fb64c72bb867 | 82 | temperature = temp_sensor.toCelsius(rawTemperatureRead); // Convert temp data to Celsius |
coreyharris | 2:cf07a3eb2f30 | 83 | temp_sensor_sampleTimer.reset(); // Reset timer |
coreyharris | 0:6e28e543a11c | 84 | |
coreyharris | 0:6e28e543a11c | 85 | pc.printf("Temperature is %2.3f deg. C \r\n", temperature); |
coreyharris | 0:6e28e543a11c | 86 | |
coreyharris | 0:6e28e543a11c | 87 | } |
coreyharris | 0:6e28e543a11c | 88 | |
coreyharris | 0:6e28e543a11c | 89 | }else{ |
coreyharris | 4:7865b145ff3c | 90 | |
coreyharris | 3:4a8ab8ffd52d | 91 | pc.printf("Something went wrong, check the I2C bus and power connections... \r\n"); |
johnGreeneMaxim | 6:96c0402be8c5 | 92 | |
coreyharris | 0:6e28e543a11c | 93 | while(1){ |
coreyharris | 0:6e28e543a11c | 94 | rLed = !rLed; |
coreyharris | 0:6e28e543a11c | 95 | wait(0.5); |
coreyharris | 0:6e28e543a11c | 96 | } |
coreyharris | 4:7865b145ff3c | 97 | |
coreyharris | 0:6e28e543a11c | 98 | } |
coreyharris | 0:6e28e543a11c | 99 | } |
coreyharris | 0:6e28e543a11c | 100 | } |
coreyharris | 0:6e28e543a11c | 101 | |
coreyharris | 0:6e28e543a11c | 102 | |
coreyharris | 0:6e28e543a11c | 103 | bool temp_sensor_config(MAX30205 &temp_sensor){ |
coreyharris | 0:6e28e543a11c | 104 | |
coreyharris | 0:6e28e543a11c | 105 | int rc = 0; |
coreyharris | 0:6e28e543a11c | 106 | |
coreyharris | 3:4a8ab8ffd52d | 107 | MAX30205::Configuration_u temp_cfg; |
coreyharris | 3:4a8ab8ffd52d | 108 | temp_cfg.all = 0; |
coreyharris | 3:4a8ab8ffd52d | 109 | temp_cfg.bits.shutdown = 1; // Shutdown mode |
coreyharris | 3:4a8ab8ffd52d | 110 | temp_cfg.bits.comp_int = 1; // Interrupt mode |
coreyharris | 3:4a8ab8ffd52d | 111 | temp_cfg.bits.os_polarity = 0; // Active low OS |
coreyharris | 3:4a8ab8ffd52d | 112 | temp_cfg.bits.fault_queue = 1; // Two faults for OS condition |
coreyharris | 3:4a8ab8ffd52d | 113 | temp_cfg.bits.data_format = 0; // Normal data format |
coreyharris | 3:4a8ab8ffd52d | 114 | temp_cfg.bits.timeout = 0; // I2C timeout reset enabled |
coreyharris | 3:4a8ab8ffd52d | 115 | temp_cfg.bits.one_shot = 0; // Start with one-shot = 0 |
coreyharris | 0:6e28e543a11c | 116 | |
coreyharris | 3:4a8ab8ffd52d | 117 | rc = temp_sensor.writeConfiguration(temp_cfg); // Write config to MAX30205 |
coreyharris | 0:6e28e543a11c | 118 | |
coreyharris | 0:6e28e543a11c | 119 | return rc; |
coreyharris | 0:6e28e543a11c | 120 | } |