interface library to support TI hdc1080 humidity and temperature sensor

Dependents:   xj-Nucleo-F303K8-hdc1080-test HelloWorld_NFC02A1laatste

Revision:
0:36666c79a60f
Child:
1:dd3a07b44fe2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hdc1080.h	Thu Jul 28 02:20:22 2016 +0000
@@ -0,0 +1,70 @@
+/*
+
+  See Also: 
+    http://www.ti.com/lit/ds/symlink/hdc1080.pdf
+    https://github.com/closedcube/ClosedCube_HDC1080_Arduino/blob/master/src/ClosedCube_HDC1080.cpp
+    http://e.pavlin.si/2016/06/04/hdlc-like-data-link-via-rs485/
+
+*/
+
+#ifndef hdc1080_h
+#define hdc1080_h
+#include "mbed.h"
+
+   #define hdc_chip_addr (0x40 << 1) // Page #8.5.1.1 - 1000000
+     // left shift 1 bit for 7 bit address required by
+     // I2C library
+   //#define hdc_chip_addr 0x40 // Page #8.5.1.1 - 1000000     
+   const int off_temp  = 0x00;
+   const int off_humid_off = 0x01;
+   const int off_config = 0x02;
+   const int off_man_id = 0xFE;
+   const int off_serial_first = 0xFB;
+   const int off_serial_mid = 0xFC;
+   const int off_serial_last = 0xFD;
+   char comm = off_man_id;
+ 
+   char hdc_buff[10];
+   
+//I2C i2c(D4,D5);   
+   
+void hdc_begin() {
+  printf("hdc_begin\r\n");
+  memset(hdc_buff,0,3);
+  hdc_buff[0] = off_config;
+  int res = i2c.write(hdc_chip_addr, hdc_buff, 2);
+  printf("hdc_begin write res=%d\r\n", res);  
+}
+    
+float hdc_readTemp() {
+  printf("hdc_readTemp()\r\n");  
+  memset(hdc_buff,0,3);
+  hdc_buff[0] = off_temp;
+  int res = i2c.write(hdc_chip_addr, hdc_buff, 1);
+  printf("write res=%d\r\n", res);  
+  wait(0.015);
+  memset(hdc_buff,0,3);  
+  res = i2c.read(hdc_chip_addr, hdc_buff,2);    
+  printf("read res=%d hdc_buff [0]=%d  [1]=%d\r\n", res, (int) hdc_buff[0], (int) hdc_buff[1]);  
+}
+
+float hdc_readHumid() {
+    
+}
+
+float hdc_readManufactId() {
+  printf("hdc_readManufactId()\r\n");
+  wait(0.015);
+  memset(hdc_buff,0,3);
+  hdc_buff[0] = off_man_id;
+  int res = i2c.write(hdc_chip_addr, hdc_buff, 1);  
+  printf("write res=%d\r\n", res);
+  
+  wait(0.015);
+  memset(hdc_buff,0,3);  
+  res = i2c.read(hdc_chip_addr, hdc_buff,2);    
+  printf("read res=%d hdc_buff [0]=%d  [1]=%d\r\n", res, (int) hdc_buff[0], (int) hdc_buff[1]);
+  
+}
+
+#endif