library for ADT7410 temperature sensor first version

Committer:
igbt6
Date:
Sun Apr 27 19:05:13 2014 +0000
Revision:
2:d12dffd027a8
Parent:
1:131a836c6b79
Child:
3:41839eb9229f
comunication wit sensor works correctly

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 2:d12dffd027a8 25 #define ADT7410_I2C_ADDRESS 0x96 //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 2:d12dffd027a8 73 ADT7410(PinName sda, PinName scl,int i2cFrequency=100000,int address = ADT7410_I2C_ADDRESS,CONF_RESOLUTION res=_16_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 1:131a836c6b79 99 int readTemp(float* pTemperature = NULL);
igbt6 1:131a836c6b79 100
igbt6 2:d12dffd027a8 101 int getIdNumber(void);
igbt6 1:131a836c6b79 102 /** Get temperature from a previous measurement
igbt6 1:131a836c6b79 103 *
igbt6 1:131a836c6b79 104 * @returns
igbt6 1:131a836c6b79 105 * temperature (C)
igbt6 1:131a836c6b79 106 */
igbt6 2:d12dffd027a8 107 float getTemperature() {return temperature;};
igbt6 1:131a836c6b79 108
igbt6 1:131a836c6b79 109 protected:
igbt6 1:131a836c6b79 110
igbt6 2:d12dffd027a8 111 float temperature;
igbt6 2:d12dffd027a8 112 I2C i2c;
igbt6 2:d12dffd027a8 113 int i2cAddr;
igbt6 2:d12dffd027a8 114 char data[4];
igbt6 2:d12dffd027a8 115 uint8_t resolution;
igbt6 2:d12dffd027a8 116
igbt6 1:131a836c6b79 117 private:
igbt6 2:d12dffd027a8 118
igbt6 1:131a836c6b79 119 /** Write data to the given register
igbt6 1:131a836c6b79 120 *
igbt6 1:131a836c6b79 121 * @returns
igbt6 1:131a836c6b79 122 * 1 on success,
igbt6 1:131a836c6b79 123 * 0 on error
igbt6 1:131a836c6b79 124 */
igbt6 2:d12dffd027a8 125
igbt6 1:131a836c6b79 126 bool write(uint8_t regAddress, uint8_t data);
igbt6 1:131a836c6b79 127
igbt6 1:131a836c6b79 128 int read(uint8_t regAddress);
igbt6 1:131a836c6b79 129
igbt6 2:d12dffd027a8 130
igbt6 2:d12dffd027a8 131 /** Write data to the given register
igbt6 2:d12dffd027a8 132 * @param register Address
igbt6 2:d12dffd027a8 133 * @param data to read
igbt6 2:d12dffd027a8 134 * @param length of data to read
igbt6 2:d12dffd027a8 135 * @returns
igbt6 2:d12dffd027a8 136 * 1 on success,
igbt6 2:d12dffd027a8 137 * 0 on error
igbt6 2:d12dffd027a8 138 */
igbt6 1:131a836c6b79 139 int read(uint8_t regAddress, uint8_t* data,int length);
igbt6 1:131a836c6b79 140
igbt6 1:131a836c6b79 141
igbt6 1:131a836c6b79 142
igbt6 1:131a836c6b79 143
igbt6 1:131a836c6b79 144 };
igbt6 1:131a836c6b79 145
igbt6 1:131a836c6b79 146 #endif