MAX30205 Human Body Temperature Sensor

Dependents:   test_MAX30205

Files at this revision

API Documentation at this revision

Comitter:
Rhyme
Date:
Tue Apr 25 05:04:06 2017 +0000
Child:
1:eed7f4c33402
Commit message:
First working version, minimum test is done, as usual

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	Tue Apr 25 05:04:06 2017 +0000
@@ -0,0 +1,96 @@
+#include "mbed.h"
+#include "MAX30205.h"
+
+/**
+ * Internal Registers
+ * The device contains four registers,
+ * each of which consists of 2bytes.
+ * The configuration register contains only 1 byte of
+ * actual data and, when read as a 2-byte register,
+ * repeats the same data for the second byte.
+ */
+ 
+#define REG_TEMP  0x00
+#define REG_CONF  0x01
+#define REG_THYST 0x02
+#define REG_TOS   0x03
+
+MAX30205::MAX30205(PinName sda, PinName scl, int addr): m_i2c(sda, scl), m_addr(addr<<1) 
+{
+    // activate the peripheral
+}
+
+MAX30205::~MAX30205()
+{
+}
+
+uint16_t MAX30205::getTemp(void) 
+{
+    uint16_t temp ;
+    uint8_t data[2] ;
+    readRegs(REG_TEMP, data, 2) ;
+    temp = (data[0] << 8) | data[1] ;
+    return(temp) ;
+}
+
+uint8_t MAX30205::getConf(void)
+{
+    uint8_t data[2] ;
+    readRegs(REG_CONF, data, 2) ;
+    return(data[0]) ;
+}
+
+void MAX30205::setConf(uint8_t conf)
+{
+    uint8_t data[3] ;
+    data[0] = REG_CONF ;
+    data[1] = conf ;
+    data[2] = conf ;
+    writeRegs(data, 3) ;
+}
+
+uint16_t MAX30205::getThyst(void)
+{
+    uint16_t thyst ;
+    uint8_t data[2] ;
+    readRegs(REG_THYST, data, 2) ;
+    thyst = (data[0] << 8) | data[1] ;
+    return(thyst) ;
+}
+
+void MAX30205::setThyst(uint16_t thyst)
+{
+    uint8_t data[3] ;
+    data[0] = REG_THYST ;
+    data[1] = (thyst >> 8) & 0xFF ;
+    data[2] = thyst & 0xFF ;
+    writeRegs(data, 3) ;
+}
+
+uint16_t MAX30205::getTos(void)
+{
+    uint16_t tos ;
+    uint8_t data[2] ;
+    readRegs(REG_TOS, data, 2) ;
+    tos = (data[0] << 8) | data[1] ;
+    return(tos) ;
+}
+
+void MAX30205::setTos(uint16_t tos)
+{
+    uint8_t data[3] ;
+    data[0] = REG_TOS ;
+    data[1] = (tos >> 8) & 0xFF ;
+    data[2] = tos & 0xFF ;
+    writeRegs(data, 3) ;
+}
+
+void MAX30205::readRegs(int addr, uint8_t * data, int len) {
+    char t[1] = {addr};
+    m_i2c.write(m_addr, t, 1, true);
+    m_i2c.read(m_addr, (char *)data, len);
+}
+
+void MAX30205::writeRegs(uint8_t * data, int len) {
+    m_i2c.write(m_addr, (char *)data, len);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX30205.h	Tue Apr 25 05:04:06 2017 +0000
@@ -0,0 +1,107 @@
+#ifndef _MAX30205_H_
+#define _MAX30205_H_
+/**
+ * MAX30205 Human Body Temperature Sensor 
+ */
+#include "mbed.h"
+
+class MAX30205
+{
+public:
+  /**
+  * MAX30205 constructor
+  *
+  * @param sda SDA pin
+  * @param sdl SCL pin
+  * @param addr addr of the I2C peripheral
+  */
+  MAX30205(PinName sda, PinName scl, int addr);
+
+  /**
+  * MAX30205 destructor
+  */
+  ~MAX30205();
+  
+/**
+ * Get temperature
+ * @param (none)
+ * @returns uint16_t temperature value
+ * @note bit[15] Sign
+ * @note bit[14] 64 C
+ * @note bit[13] 32 C
+ * @note bit[12] 16 C
+ * @note bit[11]  8 C
+ * @note bit[10]  4 C
+ * @note bit[ 9]  2 C
+ * @note bit[ 8]  1 C
+ * @note bit[ 7]  0.5 C
+ * @note bit[ 6]  0.25 C
+ * @note bit[ 5]  0.125 C
+ * @note bit[ 4]  0.0625 C
+ * @note bit[ 3]  0.03125 C
+ * @note bit[ 2]  0.015625 C
+ * @note bit[ 1]  0.0078125 C
+ * @note bit[ 0]  0.00390625 C
+ */
+uint16_t getTemp(void) ;
+
+/**
+ * Get configuration register
+ * @param (none)
+ * @returns uint8_t configuration register value
+ * @note bit[7] ONE-SHOT
+ * @note bit[6] /TIMEOUT I2C but timeout 0: enable 1: disable
+ * @note bit[5] DATAFORMAT 0: normal (0 - +50) 1: extended (64c + 2's comp)
+ * @note bit[4] FAULT_QUEUE[1] determine the number of faults necessary to
+ * @note bit[3] FAULT_QUEUE[0] trigger an OS condition.
+ * @note bit[2] OS_POLARITY 0: OS output polarity active low 1: active high
+ * @note bit[1] /COMPARATOR/INTERRUPT 0: comparator ode  1: interrupt mode
+ * @note bit[0] SHUTDOWN 0: exit from shutdown 1: enter shutdown mode
+ */
+ 
+uint8_t  getConf(void) ;
+
+/**
+ * Set configuration register
+ * @param uint8_t register value
+ * @returns (none) 
+ */
+void     setConf(uint8_t conf) ;
+
+/**
+ * Get Thyst (lower limit threshold)
+ * @param (none)
+ * @returns uint16_t Thyst value
+ */
+uint16_t getThyst(void) ;
+
+/**
+ * Set Thyst
+ * @param uint16_t thyst
+ * @returns (none)
+ */
+void     setThyst(uint16_t thyst) ;
+
+/**
+ * Get Tos (upper limit threshold)
+ * @param (none)
+ * @returns uint16_t Tos
+ */
+uint16_t getTos(void) ;
+
+/**
+ * Set Tos
+ * @param uint16_t Tos
+ * @returns (none)
+ */
+void     setTos(uint16_t tos) ;
+
+private:
+  I2C m_i2c;
+  int m_addr;
+  void readRegs(int addr, uint8_t * data, int len);
+  void writeRegs(uint8_t * data, int len);
+
+};
+
+#endif /* _MAX30205_H_ */
\ No newline at end of file