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 John Greene

Committer:
coreyharris
Date:
Mon Aug 28 21:00:41 2017 +0000
Revision:
5:fb64c72bb867
Parent:
4:7865b145ff3c
Child:
6:96c0402be8c5
updated MAX30205 object declaration

Who changed what in which revision?

UserRevisionLine numberNew 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 DigitalOut gLed(LED2, LED_OFF);
coreyharris 0:6e28e543a11c 51 DigitalOut bLed(LED3, LED_OFF);
coreyharris 0:6e28e543a11c 52
coreyharris 3:4a8ab8ffd52d 53 I2C i2cBus(I2C1_SDA, I2C1_SCL); // I2C bus, P3_4 = SDA, P3_5 = SCL
coreyharris 0:6e28e543a11c 54
coreyharris 4:7865b145ff3c 55 MAX30205 temp_sensor(i2cBus, 0x48); // New MAX30205 on i2cBus
coreyharris 4:7865b145ff3c 56 int rc = temp_sensor_config(temp_sensor); // Configure sensor, return 0 on success
coreyharris 0:6e28e543a11c 57
coreyharris 4:7865b145ff3c 58 Timer temp_sensor_sampleTimer; // Create temp. sensor sample timer
coreyharris 3:4a8ab8ffd52d 59 temp_sensor_sampleTimer.start(); // Start the timer
coreyharris 0:6e28e543a11c 60
coreyharris 0:6e28e543a11c 61 MAX30205::Configuration_u temp_cfg;
coreyharris 0:6e28e543a11c 62 uint16_t rawTemperatureRead, temp_conversion_flag;
coreyharris 0:6e28e543a11c 63 float temperature;
coreyharris 0:6e28e543a11c 64
coreyharris 0:6e28e543a11c 65 while(1) {
coreyharris 0:6e28e543a11c 66
coreyharris 0:6e28e543a11c 67 if( rc == 0 ) {
coreyharris 0:6e28e543a11c 68
coreyharris 4:7865b145ff3c 69 // Start a new temperature conversion
coreyharris 4:7865b145ff3c 70 if ( ( temp_sensor_sampleTimer.read() > 1.0f ) && !temp_conversion_flag && ( rc == 0 ) ) {
coreyharris 0:6e28e543a11c 71
coreyharris 0:6e28e543a11c 72 temp_cfg.bits.one_shot = 1;
coreyharris 5:fb64c72bb867 73 rc = temp_sensor.writeConfiguration(temp_cfg); // Send one-shot cmd to begin conversion
coreyharris 2:cf07a3eb2f30 74 temp_conversion_flag = 1; // Raise flag indicating a conversion has begun
coreyharris 0:6e28e543a11c 75
coreyharris 0:6e28e543a11c 76 }
coreyharris 0:6e28e543a11c 77
coreyharris 4:7865b145ff3c 78 // Read the completed temperature conversion
coreyharris 4:7865b145ff3c 79 if ( ( temp_sensor_sampleTimer.read() > 1.05f ) && temp_conversion_flag && ( rc == 0 ) ){
coreyharris 0:6e28e543a11c 80
coreyharris 2:cf07a3eb2f30 81 temp_conversion_flag = 0; // Lower flag when conversion has completed
coreyharris 5:fb64c72bb867 82 rc = temp_sensor.readTemperature(rawTemperatureRead); // Read the temperature data
coreyharris 5:fb64c72bb867 83 temperature = temp_sensor.toCelsius(rawTemperatureRead); // Convert temp data to Celsius
coreyharris 2:cf07a3eb2f30 84 temp_sensor_sampleTimer.reset(); // Reset timer
coreyharris 0:6e28e543a11c 85
coreyharris 0:6e28e543a11c 86 pc.printf("Temperature is %2.3f deg. C \r\n", temperature);
coreyharris 0:6e28e543a11c 87
coreyharris 0:6e28e543a11c 88 }
coreyharris 0:6e28e543a11c 89
coreyharris 0:6e28e543a11c 90 }else{
coreyharris 4:7865b145ff3c 91
coreyharris 3:4a8ab8ffd52d 92 pc.printf("Something went wrong, check the I2C bus and power connections... \r\n");
coreyharris 0:6e28e543a11c 93 bLed = LED_OFF;
coreyharris 0:6e28e543a11c 94 gLed = LED_OFF;
coreyharris 4:7865b145ff3c 95
coreyharris 0:6e28e543a11c 96 while(1){
coreyharris 0:6e28e543a11c 97 rLed = !rLed;
coreyharris 0:6e28e543a11c 98 wait(0.5);
coreyharris 0:6e28e543a11c 99 }
coreyharris 4:7865b145ff3c 100
coreyharris 0:6e28e543a11c 101 }
coreyharris 0:6e28e543a11c 102 }
coreyharris 0:6e28e543a11c 103 }
coreyharris 0:6e28e543a11c 104
coreyharris 0:6e28e543a11c 105
coreyharris 0:6e28e543a11c 106 bool temp_sensor_config(MAX30205 &temp_sensor){
coreyharris 0:6e28e543a11c 107
coreyharris 0:6e28e543a11c 108 int rc = 0;
coreyharris 0:6e28e543a11c 109
coreyharris 3:4a8ab8ffd52d 110 MAX30205::Configuration_u temp_cfg;
coreyharris 3:4a8ab8ffd52d 111 temp_cfg.all = 0;
coreyharris 3:4a8ab8ffd52d 112 temp_cfg.bits.shutdown = 1; // Shutdown mode
coreyharris 3:4a8ab8ffd52d 113 temp_cfg.bits.comp_int = 1; // Interrupt mode
coreyharris 3:4a8ab8ffd52d 114 temp_cfg.bits.os_polarity = 0; // Active low OS
coreyharris 3:4a8ab8ffd52d 115 temp_cfg.bits.fault_queue = 1; // Two faults for OS condition
coreyharris 3:4a8ab8ffd52d 116 temp_cfg.bits.data_format = 0; // Normal data format
coreyharris 3:4a8ab8ffd52d 117 temp_cfg.bits.timeout = 0; // I2C timeout reset enabled
coreyharris 3:4a8ab8ffd52d 118 temp_cfg.bits.one_shot = 0; // Start with one-shot = 0
coreyharris 0:6e28e543a11c 119
coreyharris 3:4a8ab8ffd52d 120 rc = temp_sensor.writeConfiguration(temp_cfg); // Write config to MAX30205
coreyharris 0:6e28e543a11c 121
coreyharris 0:6e28e543a11c 122 return rc;
coreyharris 0:6e28e543a11c 123 }