interface library to support TI hdc1080 humidity and temperature sensor
Dependents: xj-Nucleo-F303K8-hdc1080-test HelloWorld_NFC02A1laatste
hdc1080.h@0:36666c79a60f, 2016-07-28 (annotated)
- Committer:
- joeata2wh
- Date:
- Thu Jul 28 02:20:22 2016 +0000
- Revision:
- 0:36666c79a60f
- Child:
- 1:dd3a07b44fe2
wip still not working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joeata2wh | 0:36666c79a60f | 1 | /* |
joeata2wh | 0:36666c79a60f | 2 | |
joeata2wh | 0:36666c79a60f | 3 | See Also: |
joeata2wh | 0:36666c79a60f | 4 | http://www.ti.com/lit/ds/symlink/hdc1080.pdf |
joeata2wh | 0:36666c79a60f | 5 | https://github.com/closedcube/ClosedCube_HDC1080_Arduino/blob/master/src/ClosedCube_HDC1080.cpp |
joeata2wh | 0:36666c79a60f | 6 | http://e.pavlin.si/2016/06/04/hdlc-like-data-link-via-rs485/ |
joeata2wh | 0:36666c79a60f | 7 | |
joeata2wh | 0:36666c79a60f | 8 | */ |
joeata2wh | 0:36666c79a60f | 9 | |
joeata2wh | 0:36666c79a60f | 10 | #ifndef hdc1080_h |
joeata2wh | 0:36666c79a60f | 11 | #define hdc1080_h |
joeata2wh | 0:36666c79a60f | 12 | #include "mbed.h" |
joeata2wh | 0:36666c79a60f | 13 | |
joeata2wh | 0:36666c79a60f | 14 | #define hdc_chip_addr (0x40 << 1) // Page #8.5.1.1 - 1000000 |
joeata2wh | 0:36666c79a60f | 15 | // left shift 1 bit for 7 bit address required by |
joeata2wh | 0:36666c79a60f | 16 | // I2C library |
joeata2wh | 0:36666c79a60f | 17 | //#define hdc_chip_addr 0x40 // Page #8.5.1.1 - 1000000 |
joeata2wh | 0:36666c79a60f | 18 | const int off_temp = 0x00; |
joeata2wh | 0:36666c79a60f | 19 | const int off_humid_off = 0x01; |
joeata2wh | 0:36666c79a60f | 20 | const int off_config = 0x02; |
joeata2wh | 0:36666c79a60f | 21 | const int off_man_id = 0xFE; |
joeata2wh | 0:36666c79a60f | 22 | const int off_serial_first = 0xFB; |
joeata2wh | 0:36666c79a60f | 23 | const int off_serial_mid = 0xFC; |
joeata2wh | 0:36666c79a60f | 24 | const int off_serial_last = 0xFD; |
joeata2wh | 0:36666c79a60f | 25 | char comm = off_man_id; |
joeata2wh | 0:36666c79a60f | 26 | |
joeata2wh | 0:36666c79a60f | 27 | char hdc_buff[10]; |
joeata2wh | 0:36666c79a60f | 28 | |
joeata2wh | 0:36666c79a60f | 29 | //I2C i2c(D4,D5); |
joeata2wh | 0:36666c79a60f | 30 | |
joeata2wh | 0:36666c79a60f | 31 | void hdc_begin() { |
joeata2wh | 0:36666c79a60f | 32 | printf("hdc_begin\r\n"); |
joeata2wh | 0:36666c79a60f | 33 | memset(hdc_buff,0,3); |
joeata2wh | 0:36666c79a60f | 34 | hdc_buff[0] = off_config; |
joeata2wh | 0:36666c79a60f | 35 | int res = i2c.write(hdc_chip_addr, hdc_buff, 2); |
joeata2wh | 0:36666c79a60f | 36 | printf("hdc_begin write res=%d\r\n", res); |
joeata2wh | 0:36666c79a60f | 37 | } |
joeata2wh | 0:36666c79a60f | 38 | |
joeata2wh | 0:36666c79a60f | 39 | float hdc_readTemp() { |
joeata2wh | 0:36666c79a60f | 40 | printf("hdc_readTemp()\r\n"); |
joeata2wh | 0:36666c79a60f | 41 | memset(hdc_buff,0,3); |
joeata2wh | 0:36666c79a60f | 42 | hdc_buff[0] = off_temp; |
joeata2wh | 0:36666c79a60f | 43 | int res = i2c.write(hdc_chip_addr, hdc_buff, 1); |
joeata2wh | 0:36666c79a60f | 44 | printf("write res=%d\r\n", res); |
joeata2wh | 0:36666c79a60f | 45 | wait(0.015); |
joeata2wh | 0:36666c79a60f | 46 | memset(hdc_buff,0,3); |
joeata2wh | 0:36666c79a60f | 47 | res = i2c.read(hdc_chip_addr, hdc_buff,2); |
joeata2wh | 0:36666c79a60f | 48 | printf("read res=%d hdc_buff [0]=%d [1]=%d\r\n", res, (int) hdc_buff[0], (int) hdc_buff[1]); |
joeata2wh | 0:36666c79a60f | 49 | } |
joeata2wh | 0:36666c79a60f | 50 | |
joeata2wh | 0:36666c79a60f | 51 | float hdc_readHumid() { |
joeata2wh | 0:36666c79a60f | 52 | |
joeata2wh | 0:36666c79a60f | 53 | } |
joeata2wh | 0:36666c79a60f | 54 | |
joeata2wh | 0:36666c79a60f | 55 | float hdc_readManufactId() { |
joeata2wh | 0:36666c79a60f | 56 | printf("hdc_readManufactId()\r\n"); |
joeata2wh | 0:36666c79a60f | 57 | wait(0.015); |
joeata2wh | 0:36666c79a60f | 58 | memset(hdc_buff,0,3); |
joeata2wh | 0:36666c79a60f | 59 | hdc_buff[0] = off_man_id; |
joeata2wh | 0:36666c79a60f | 60 | int res = i2c.write(hdc_chip_addr, hdc_buff, 1); |
joeata2wh | 0:36666c79a60f | 61 | printf("write res=%d\r\n", res); |
joeata2wh | 0:36666c79a60f | 62 | |
joeata2wh | 0:36666c79a60f | 63 | wait(0.015); |
joeata2wh | 0:36666c79a60f | 64 | memset(hdc_buff,0,3); |
joeata2wh | 0:36666c79a60f | 65 | res = i2c.read(hdc_chip_addr, hdc_buff,2); |
joeata2wh | 0:36666c79a60f | 66 | printf("read res=%d hdc_buff [0]=%d [1]=%d\r\n", res, (int) hdc_buff[0], (int) hdc_buff[1]); |
joeata2wh | 0:36666c79a60f | 67 | |
joeata2wh | 0:36666c79a60f | 68 | } |
joeata2wh | 0:36666c79a60f | 69 | |
joeata2wh | 0:36666c79a60f | 70 | #endif |