library for ADT7410 temperature sensor first version

Committer:
igbt6
Date:
Tue Apr 29 00:35:40 2014 +0000
Revision:
3:41839eb9229f
Parent:
2:d12dffd027a8
Child:
4:89644cedc8c8
everythnig works well

Who changed what in which revision?

UserRevisionLine numberNew contents of line
igbt6 1:131a836c6b79 1 /*
igbt6 1:131a836c6b79 2 @file adt7410.h
igbt6 1:131a836c6b79 3
igbt6 1:131a836c6b79 4 @brief Temperature Sensor ADT7410 Breakout I2C Library
igbt6 1:131a836c6b79 5
igbt6 1:131a836c6b79 6 @Author lukasz uszko(luszko@op.pl)
igbt6 1:131a836c6b79 7
igbt6 1:131a836c6b79 8 Tested on FRDM-KL46Z
igbt6 1:131a836c6b79 9
igbt6 1:131a836c6b79 10 Copyright (c) 2014 luszko
igbt6 1:131a836c6b79 11 Released under the MIT License (see http://mbed.org/license/mit)
igbt6 1:131a836c6b79 12
igbt6 1:131a836c6b79 13 Documentation regarding the ADT7410 can be found here:
igbt6 1:131a836c6b79 14 http://www.analog.com/static/imported-files/data_sheets/ADT7410.pdf
igbt6 1:131a836c6b79 15 */
igbt6 1:131a836c6b79 16
igbt6 1:131a836c6b79 17
igbt6 1:131a836c6b79 18
igbt6 1:131a836c6b79 19 #ifndef ADT7410_H
igbt6 1:131a836c6b79 20 #define ADT7410_H
igbt6 1:131a836c6b79 21
igbt6 1:131a836c6b79 22 #include "mbed.h"
igbt6 1:131a836c6b79 23
igbt6 1:131a836c6b79 24
igbt6 3:41839eb9229f 25 #define ADT7410_I2C_ADDRESS 0x97 //A0 and A1 PIN are conected to VDD
igbt6 2:d12dffd027a8 26
igbt6 1:131a836c6b79 27
igbt6 2:d12dffd027a8 28 typedef enum {
igbt6 2:d12dffd027a8 29 _13_BIT=0,
igbt6 2:d12dffd027a8 30 _16_BIT=1
igbt6 2:d12dffd027a8 31 }CONF_RESOLUTION;
igbt6 2:d12dffd027a8 32
igbt6 2:d12dffd027a8 33 typedef enum {
igbt6 2:d12dffd027a8 34 CONT_CONV=0,
igbt6 2:d12dffd027a8 35 ONE_SHOT,
igbt6 2:d12dffd027a8 36 SPS_MODE,
igbt6 2:d12dffd027a8 37 SHUTDOWN
igbt6 2:d12dffd027a8 38 }CONF_OPERATION_MODE;
igbt6 2:d12dffd027a8 39
igbt6 2:d12dffd027a8 40 typedef enum {
igbt6 2:d12dffd027a8 41 INTERRUPT_MODE=0,
igbt6 2:d12dffd027a8 42 COMPARATOR_MODE=1
igbt6 2:d12dffd027a8 43 }CONF_INT_CT_MODE;
igbt6 2:d12dffd027a8 44
igbt6 2:d12dffd027a8 45 typedef enum {
igbt6 2:d12dffd027a8 46 INT_ACTIVE_LOW=0,
igbt6 2:d12dffd027a8 47 INT_ACTIVE_HIGH=1
igbt6 2:d12dffd027a8 48 }CONF_INT_PIN_POLARITY;
igbt6 2:d12dffd027a8 49
igbt6 2:d12dffd027a8 50 typedef enum {
igbt6 2:d12dffd027a8 51 CT_ACTIVE_LOW=0,
igbt6 2:d12dffd027a8 52 CT_ACTIVE_HIGH=1
igbt6 2:d12dffd027a8 53 }CONF_CT_PIN_POLARITY;
igbt6 2:d12dffd027a8 54
igbt6 2:d12dffd027a8 55 typedef enum {
igbt6 2:d12dffd027a8 56 _1_FAULT=0,
igbt6 2:d12dffd027a8 57 _2_FAULTS,
igbt6 2:d12dffd027a8 58 _3_FAULTS,
igbt6 2:d12dffd027a8 59 _4_FAULTS
igbt6 2:d12dffd027a8 60 }CONF_FAULT_QUEUE;
igbt6 2:d12dffd027a8 61
igbt6 1:131a836c6b79 62
igbt6 1:131a836c6b79 63
igbt6 1:131a836c6b79 64 class ADT7410{
igbt6 1:131a836c6b79 65
igbt6 1:131a836c6b79 66 public:
igbt6 1:131a836c6b79 67
igbt6 1:131a836c6b79 68 /** Create an ADT7410 instance
igbt6 1:131a836c6b79 69 * @param sda pin
igbt6 1:131a836c6b79 70 * @param scl pin
igbt6 1:131a836c6b79 71 * @param address: I2C slave address
igbt6 1:131a836c6b79 72 */
igbt6 3:41839eb9229f 73 ADT7410(PinName sda, PinName scl,int i2cFrequency=100000,int address = ADT7410_I2C_ADDRESS,CONF_RESOLUTION res=_13_BIT);
igbt6 1:131a836c6b79 74
igbt6 1:131a836c6b79 75 /** Create a ADT7410 instance
igbt6 1:131a836c6b79 76 * @param i2c object
igbt6 1:131a836c6b79 77 * @param address: I2C slave address
igbt6 1:131a836c6b79 78 */
igbt6 1:131a836c6b79 79 ADT7410(I2C& i2c, int address = ADT7410_I2C_ADDRESS);
igbt6 1:131a836c6b79 80
igbt6 2:d12dffd027a8 81 /** Initialization: set member values and
igbt6 1:131a836c6b79 82 * @returns
igbt6 1:131a836c6b79 83 * 1 on success,
igbt6 1:131a836c6b79 84 * 0 on error
igbt6 1:131a836c6b79 85 */
igbt6 2:d12dffd027a8 86 int initADT7410(CONF_FAULT_QUEUE faultQueue=_1_FAULT,
igbt6 2:d12dffd027a8 87 CONF_CT_PIN_POLARITY ctPinPolarity=CT_ACTIVE_LOW,
igbt6 2:d12dffd027a8 88 CONF_INT_PIN_POLARITY intPinPolarity=INT_ACTIVE_LOW,
igbt6 2:d12dffd027a8 89 CONF_INT_CT_MODE intCtMode=INTERRUPT_MODE,
igbt6 2:d12dffd027a8 90 CONF_OPERATION_MODE operMode=CONT_CONV,
igbt6 2:d12dffd027a8 91 CONF_RESOLUTION res=_16_BIT);
igbt6 1:131a836c6b79 92
igbt6 1:131a836c6b79 93 /** Read temperature from the ADT7410.
igbt6 1:131a836c6b79 94 * @param temperature (C)
igbt6 1:131a836c6b79 95 * @returns
igbt6 1:131a836c6b79 96 * 1 on success,
igbt6 1:131a836c6b79 97 * 0 on error
igbt6 1:131a836c6b79 98 */
igbt6 3:41839eb9229f 99 int readTemp();
igbt6 1:131a836c6b79 100
igbt6 2:d12dffd027a8 101 int getIdNumber(void);
igbt6 3:41839eb9229f 102
igbt6 3:41839eb9229f 103
igbt6 3:41839eb9229f 104 /** Set resolution of read data
igbt6 3:41839eb9229f 105 *
igbt6 3:41839eb9229f 106 *
igbt6 3:41839eb9229f 107 */
igbt6 3:41839eb9229f 108 int setResolution(CONF_RESOLUTION res);
igbt6 3:41839eb9229f 109
igbt6 1:131a836c6b79 110 /** Get temperature from a previous measurement
igbt6 1:131a836c6b79 111 *
igbt6 1:131a836c6b79 112 * @returns
igbt6 1:131a836c6b79 113 * temperature (C)
igbt6 1:131a836c6b79 114 */
igbt6 3:41839eb9229f 115 inline float getTemperature(void) {return currentTemperature;}
igbt6 1:131a836c6b79 116
igbt6 1:131a836c6b79 117 protected:
igbt6 1:131a836c6b79 118
igbt6 3:41839eb9229f 119 float currentTemperature;
igbt6 2:d12dffd027a8 120 I2C i2c;
igbt6 2:d12dffd027a8 121 int i2cAddr;
igbt6 2:d12dffd027a8 122 char data[4];
igbt6 2:d12dffd027a8 123 uint8_t resolution;
igbt6 2:d12dffd027a8 124
igbt6 1:131a836c6b79 125 private:
igbt6 2:d12dffd027a8 126
igbt6 1:131a836c6b79 127 /** Write data to the given register
igbt6 1:131a836c6b79 128 *
igbt6 1:131a836c6b79 129 * @returns
igbt6 1:131a836c6b79 130 * 1 on success,
igbt6 1:131a836c6b79 131 * 0 on error
igbt6 1:131a836c6b79 132 */
igbt6 2:d12dffd027a8 133
igbt6 1:131a836c6b79 134 bool write(uint8_t regAddress, uint8_t data);
igbt6 1:131a836c6b79 135
igbt6 1:131a836c6b79 136 int read(uint8_t regAddress);
igbt6 1:131a836c6b79 137
igbt6 2:d12dffd027a8 138
igbt6 2:d12dffd027a8 139 /** Write data to the given register
igbt6 2:d12dffd027a8 140 * @param register Address
igbt6 2:d12dffd027a8 141 * @param data to read
igbt6 2:d12dffd027a8 142 * @param length of data to read
igbt6 2:d12dffd027a8 143 * @returns
igbt6 2:d12dffd027a8 144 * 1 on success,
igbt6 2:d12dffd027a8 145 * 0 on error
igbt6 2:d12dffd027a8 146 */
igbt6 1:131a836c6b79 147 int read(uint8_t regAddress, uint8_t* data,int length);
igbt6 1:131a836c6b79 148
igbt6 1:131a836c6b79 149
igbt6 1:131a836c6b79 150
igbt6 1:131a836c6b79 151
igbt6 1:131a836c6b79 152 };
igbt6 1:131a836c6b79 153
igbt6 1:131a836c6b79 154 #endif