Maxim Integrated MAX30205 C, C++ source code driver software: MAX30205 is accurate to +-0.1°C over the range of 37.0°C to 39.0°C. One-shot, shutdown modes are available for reduced power usage. Thermostat thresholds allow for temperature hysteresis or for alarm settings. The MAX30205 is available in a compact 3x3 mm, 8-pin TDFN package. Operating supply voltage range is 2.7V to 3.3V. Typical applications are for clinical digital thermometers, thermostats with hysteresis, and temperature alarms.

Dependents:   MAX30205_Human_Body_Temperature_Sensor

Files at this revision

API Documentation at this revision

Comitter:
j3
Date:
Mon Apr 03 23:11:58 2017 +0000
Child:
1:d4271ef9f37f
Commit message:
Init commit, stand alone lib separated from HSP.

Changed in this revision

MAX30205.cpp Show annotated file Show diff for this revision Revisions of this file
MAX30205.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX30205.cpp	Mon Apr 03 23:11:58 2017 +0000
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Maxim Integrated
+ * Products, Inc. shall not be used except as stated in the Maxim Integrated
+ * Products, Inc. Branding Policy.
+ *
+ * The mere transfer of this software does not imply any licenses
+ * of trade secrets, proprietary technology, copyrights, patents,
+ * trademarks, maskwork rights, or any other form of intellectual
+ * property whatsoever. Maxim Integrated Products, Inc. retains all
+ * ownership rights.
+ *******************************************************************************
+ */
+#include "MAX30205.h"
+
+//******************************************************************************
+MAX30205::MAX30205(PinName sda, PinName scl, uint8_t slaveAddress): 
+m_i2c(sda, scl), m_writeAddress(slaveAddress << 1), m_readAddress((slaveAddress << 1) | 1)
+{
+}
+
+//******************************************************************************
+MAX30205::MAX30205(I2C& i2c, uint8_t slaveAddress): 
+m_i2c(i2c), m_writeAddress(slaveAddress << 1), m_readAddress((slaveAddress << 1) | 1)
+{
+}
+
+//******************************************************************************
+MAX30205::~MAX30205(void) 
+{
+  //empty block
+}
+
+//******************************************************************************
+int32_t MAX30205::reg_write(Registers reg, uint8_t value) 
+{
+  int32_t result;
+  
+  char cmdData[2] = {reg, value};
+  
+  result = m_i2c.write(m_writeAddress, cmdData, 2);
+  
+  return result;
+}
+
+//******************************************************************************
+int32_t MAX30205::reg_write16(Registers reg, uint16_t value) 
+{
+  int32_t result;
+  
+  uint8_t hi = ((value >> 8) & 0xFF);
+  uint8_t lo = (value & 0xFF);
+  char cmdData[3] = {reg, hi, lo};
+  
+  result = m_i2c.write(m_writeAddress, cmdData, 3);
+  
+  return result;
+}
+
+//******************************************************************************
+int32_t MAX30205::reg_read(Registers reg, uint8_t& value) 
+{
+  int32_t result;
+  
+  char cmdData[1] = {reg};
+  char readData;
+
+  result = m_i2c.write(m_writeAddress, cmdData, 1);
+  if(result == 0)
+  {
+      result = m_i2c.read(m_readAddress, &readData, 1);
+      if(result == 0)
+      {
+          value = readData;
+      }
+  }
+  
+  return result;
+}
+
+//******************************************************************************
+int32_t MAX30205::reg_read16(Registers reg, uint16_t& value) 
+{
+  int32_t result;
+  
+  char data[2];
+  char cmdData[1] = {reg};
+  
+  result = m_i2c.write(m_writeAddress, cmdData, 1);
+  if(result == 0)
+  {
+      result = m_i2c.read(m_readAddress, data, 2);
+      if (result == 0)
+      {
+          value = (data[0] << 8) + data[1];
+      }
+  }
+  
+  return result;
+}
+
+//******************************************************************************
+int32_t MAX30205::readTemperature(uint16_t& value) 
+{
+  int32_t result = reg_read16(MAX30205::Temperature, value);
+  
+  return result;
+}
+
+//******************************************************************************
+float MAX30205::toCelsius(uint32_t rawTemp) 
+{
+  float val1, val2;
+  
+  val1 = static_cast<float>(rawTemp >> 8);
+  val2 = static_cast<float>(rawTemp & 0xFF);
+  
+  return(val2 + (val1 / 256.0F));
+}
+
+//******************************************************************************
+float MAX30205::toFahrenheit(float temperatureC) 
+{
+  return((temperatureC * 1.8F) + 32.0f);
+}
+
+//******************************************************************************
+int32_t MAX30205::reg_THYST_Read(uint16_t& value) 
+{
+  return reg_read16(MAX30205::THYST, value);
+}
+
+//******************************************************************************
+int32_t MAX30205::reg_THYST_Write(uint16_t value) 
+{
+  return reg_write16(MAX30205::THYST, value);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX30205.h	Mon Apr 03 23:11:58 2017 +0000
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Maxim Integrated
+ * Products, Inc. shall not be used except as stated in the Maxim Integrated
+ * Products, Inc. Branding Policy.
+ *
+ * The mere transfer of this software does not imply any licenses
+ * of trade secrets, proprietary technology, copyrights, patents,
+ * trademarks, maskwork rights, or any other form of intellectual
+ * property whatsoever. Maxim Integrated Products, Inc. retains all
+ * ownership rights.
+ *******************************************************************************
+ */
+#ifndef __MAX30205_H_
+#define __MAX30205_H_
+
+#include "mbed.h"
+
+/**
+ * Driver for the MAX30205
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "MAX30205.h"
+ *
+ * int main(void) 
+ * {
+ *     I2C i2c(I2C_SDA, I2C_SCL);
+ *     MAX30205 sensor(i2c);
+ *
+ *     //use sensor
+ * }
+ * @endcode
+ */
+
+class MAX30205
+{
+    
+public:
+    /// MAX30205 Register Addresses
+    enum Registers 
+    {
+        Temperature = 0x00,
+        Configuration = 0x01,
+        THYST = 0x02,
+        TOS = 0x03
+    };
+
+    /**
+    * @brief  Constructor using I2C PinNames
+    * @param sda - Pinname for sda
+    * @param scl - Pinname for scl
+    * @param slaveAddress - 7-bit I2C address
+    */
+    MAX30205(PinName sda, PinName scl, uint8_t slaveAddress);
+    
+    /**
+    * @brief  Constructor using reference to I2C object
+    * @param i2c - Reference to I2C object
+    * @param slaveAddress - 7-bit I2C address
+    */
+    MAX30205(I2C& i2c, uint8_t slaveAddress);
+
+    /** @brief Destructor */
+    ~MAX30205(void);
+
+    /** @brief Write register of device at slave address
+    * @param reg - Register address
+    * @param value - Value to write
+    * @return 0 on success, non-zero on failure
+    */
+    int32_t reg_write(Registers reg, uint8_t value);
+
+    /**
+    * @brief  Read register of device at slave address
+    * @param reg - Register address
+    * @param[out] value - Read data on success
+    * @return 0 on success, non-zero on failure
+    */
+    int32_t reg_read(Registers reg, uint8_t& value);
+
+    /**
+    * @brief Write a 16-bit value into device at slave address
+    * @param reg - Register address
+    * @param value - 16-bit value to write
+    * @return 0 on success, non-zero on failure
+    */
+    int32_t reg_write16(Registers reg, uint16_t value);
+
+    /**
+    * @brief Read a 16-bit value from a device at a slave address
+    * @param reg - Register address
+    * @param[out] value - Read data on success
+    * @return 0 on success, non-zero on failure
+    */
+    int32_t reg_read16(Registers reg, uint16_t& value);
+
+    /**
+    * @brief Read the temperature from the device into a 16 bit value
+    * @param[out] value - Raw temperature data on success
+    * @return 0 on success, non-zero on failure
+    */
+    int32_t readTemperature(uint16_t& value);
+
+    /**
+    * @brief Read the THYST value from a specified device instance
+    * @param[out] value - THYST register value on success
+    * @return 0 on success, non-zero on failure
+    */
+    int32_t reg_THYST_Read(uint16_t& value);
+
+    /**
+    * @brief Write the THYST to a device instance
+    * @param value - 16-bit value to write
+    * @return 0 on success, non-zero on failure
+    */
+    int32_t reg_THYST_Write(uint16_t value);
+
+    /**
+    * @brief Convert a raw temperature value into a float
+    * @param rawTemp - raw temperature value to convert
+    * @return the convereted value in degrees C
+    */
+    float toCelsius(uint32_t rawTemp);
+
+    /**
+    * @brief Convert the passed in temperature in C to Fahrenheit
+    * @param temperatureC Temperature in C to convert
+    * @returns Returns the converted Fahrenheit value
+    */
+    float toFahrenheit(float temperatureC);
+
+private:
+    /// I2C object
+    I2C m_i2c;
+    /// Device slave address
+    uint8_t m_writeAddress, m_readAddress;
+};
+
+#endif /* __MAX30205_H_ */