ADT7410 library

Dependents:   mbed_DEMO mbed_BLE

See https://developer.mbed.org/users/yasuyuki/notebook/ADT7410/

Committer:
yasuyuki
Date:
Wed Jun 03 01:27:12 2015 +0000
Revision:
2:f01d96ee8fda
Parent:
1:b13511ed5965
one shot

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yasuyuki 0:cebbc4e855af 1 //**********************
yasuyuki 0:cebbc4e855af 2 // ADT7410.cpp for mbed
yasuyuki 0:cebbc4e855af 3 //
yasuyuki 0:cebbc4e855af 4 // ADT7410 temperature(P0_5,P0_4);
yasuyuki 0:cebbc4e855af 5 // or
yasuyuki 0:cebbc4e855af 6 // I2C i2c(P0_5,P0_4);
yasuyuki 0:cebbc4e855af 7 // ADT7410 temperature(i2c);
yasuyuki 0:cebbc4e855af 8 //
yasuyuki 0:cebbc4e855af 9 // (C)Copyright 2014 All rights reserved by Y.Onodera
yasuyuki 0:cebbc4e855af 10 // http://einstlab.web.fc2.com
yasuyuki 0:cebbc4e855af 11 //**********************
yasuyuki 0:cebbc4e855af 12
yasuyuki 0:cebbc4e855af 13 #include "mbed.h"
yasuyuki 0:cebbc4e855af 14 #include "ADT7410.h"
yasuyuki 0:cebbc4e855af 15
yasuyuki 2:f01d96ee8fda 16 //#define SPS
yasuyuki 2:f01d96ee8fda 17 #define ONESHOT
yasuyuki 2:f01d96ee8fda 18
yasuyuki 0:cebbc4e855af 19 ADT7410::ADT7410 (PinName sda, PinName scl) : _i2c(sda, scl) {
yasuyuki 0:cebbc4e855af 20 init();
yasuyuki 0:cebbc4e855af 21 }
yasuyuki 0:cebbc4e855af 22 ADT7410::ADT7410 (I2C& p_i2c) : _i2c(p_i2c) {
yasuyuki 0:cebbc4e855af 23 init();
yasuyuki 0:cebbc4e855af 24 }
yasuyuki 0:cebbc4e855af 25
yasuyuki 0:cebbc4e855af 26 void ADT7410::put(unsigned char a, unsigned char b)
yasuyuki 0:cebbc4e855af 27 {
yasuyuki 0:cebbc4e855af 28 buf[0]=a;
yasuyuki 0:cebbc4e855af 29 buf[1]=b;
yasuyuki 0:cebbc4e855af 30 _i2c.write(ADT7410_ADDR, buf, 2);
yasuyuki 0:cebbc4e855af 31 }
yasuyuki 0:cebbc4e855af 32
yasuyuki 0:cebbc4e855af 33
yasuyuki 0:cebbc4e855af 34 void ADT7410::get(unsigned char a)
yasuyuki 0:cebbc4e855af 35 {
yasuyuki 0:cebbc4e855af 36 buf[0] = a;
yasuyuki 0:cebbc4e855af 37 _i2c.write(ADT7410_ADDR, buf, 1, false); // no stop, repeated
yasuyuki 0:cebbc4e855af 38 _i2c.read( ADT7410_ADDR, buf, 2);
yasuyuki 0:cebbc4e855af 39
yasuyuki 0:cebbc4e855af 40 }
yasuyuki 0:cebbc4e855af 41
yasuyuki 1:b13511ed5965 42 short ADT7410::value()
yasuyuki 0:cebbc4e855af 43 {
yasuyuki 0:cebbc4e855af 44
yasuyuki 2:f01d96ee8fda 45 #ifdef ONESHOT
yasuyuki 2:f01d96ee8fda 46 // wakeup
yasuyuki 2:f01d96ee8fda 47 // set 16bit resolution with one shot mode
yasuyuki 2:f01d96ee8fda 48 put(ADT7410_CONFIG, 0xA0);
yasuyuki 2:f01d96ee8fda 49 wait_ms(240);
yasuyuki 2:f01d96ee8fda 50 #endif
yasuyuki 2:f01d96ee8fda 51
yasuyuki 0:cebbc4e855af 52 // RDY?
yasuyuki 0:cebbc4e855af 53 // do{
yasuyuki 0:cebbc4e855af 54 // get(ADT7410_STATUS);
yasuyuki 0:cebbc4e855af 55 // }while(buf[0] & 0x80);
yasuyuki 0:cebbc4e855af 56
yasuyuki 1:b13511ed5965 57 // get temp_high and low
yasuyuki 0:cebbc4e855af 58 get(ADT7410_TEMP_H);
yasuyuki 0:cebbc4e855af 59 temp.byte.HB=buf[0];
yasuyuki 0:cebbc4e855af 60 temp.byte.LB=buf[1];
yasuyuki 1:b13511ed5965 61 return temp.S;
yasuyuki 1:b13511ed5965 62
yasuyuki 1:b13511ed5965 63 // C = temp.S / 128
yasuyuki 0:cebbc4e855af 64
yasuyuki 0:cebbc4e855af 65 }
yasuyuki 0:cebbc4e855af 66
yasuyuki 0:cebbc4e855af 67 void ADT7410::init()
yasuyuki 0:cebbc4e855af 68 {
yasuyuki 2:f01d96ee8fda 69 #ifdef SPS
yasuyuki 2:f01d96ee8fda 70 // set 16bit resolution with 1 sps mode
yasuyuki 0:cebbc4e855af 71 put(ADT7410_CONFIG, 0xC0);
yasuyuki 2:f01d96ee8fda 72 #endif
yasuyuki 2:f01d96ee8fda 73 #ifdef ONSHOT
yasuyuki 2:f01d96ee8fda 74 // set 16bit resolution with one shot mode
yasuyuki 2:f01d96ee8fda 75 put(ADT7410_CONFIG, 0xA0);
yasuyuki 2:f01d96ee8fda 76 #endif
yasuyuki 2:f01d96ee8fda 77
yasuyuki 0:cebbc4e855af 78 }
yasuyuki 0:cebbc4e855af 79
yasuyuki 0:cebbc4e855af 80