Yasubumi KANAZAWA / test_TMP102
Revision:
0:89475bc39c8b
Child:
1:c9c43b132ed7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test_TMP102.cpp	Sat Nov 25 03:25:15 2017 +0000
@@ -0,0 +1,26 @@
+#include "test_TMP102.h"
+
+test_TMP102::test_TMP102(PinName sda, PinName scl) : i2c(sda, scl)
+{
+    init();
+}
+
+test_TMP102::~test_TMP102()
+{
+}
+
+void test_TMP102::init(void)
+{
+}
+
+float test_TMP102::read(void)
+{
+    char reg[2]= {0,0};
+    i2c.write(ADDR_TMP102, 0x00, 1); //Pointer to the temperature register
+    i2c.read(ADDR_TMP102, reg, 2); // read two bytes data
+
+    // calculate temperature
+    int16_t res = ((int8_t)reg[0] << 4) | ((uint8_t)reg[1] >> 4);
+    float temp = (float) ((float)res * 0.0625);
+    return temp;
+}
\ No newline at end of file