Analog Devices / ADT7410 16-Bit Digital I2C Temperature Sensor
Dependents: Frequency_Counter_w_GPS_1PPS MQTToverCC3000 Frequency_Cntr_1PPS_F746ZG
Diff: ADT7410.h
- Revision:
- 0:6ec4df1fa459
- Child:
- 1:4a1eb0f32025
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ADT7410.h Fri Nov 28 10:32:19 2014 +0000 @@ -0,0 +1,133 @@ +/* + * mbed library program + * Analog Devices / ADT7410 16-Bit Digital I2C Temperature Sensor + * http://www.analog.com/en/mems-sensors/digital-temperature-sensors/adt7410/products/product.html + * + * Copyright (c) 2014 Kenji Arai / JH1PJL + * http://www.page.sannet.ne.jp/kenjia/index.html + * http://mbed.org/users/kenjiArai/ + * Created: November 26th, 2014 + * Revised: November 28th, 2014 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef MBED_ADT7410 +#define MBED_ADT7410 + +// ADT7410 Temperature Sensor +// 7bit address = 0b01100000(0x48) -> 8bit = 0b11000000(0x90) -> 0x91(Read) or 0x90(Write) +// ADDR_01 = (A1=0=J4)+(A0=1=J3), ADDR_1N = (A1=1)+(A0=No Connection =0) +// -> Please make sure your H/W configuration +#define ADT7410ADDR_00 0x90 +#define ADT7410ADDR_NN 0x90 +#define ADT7410ADDR_N1 0x92 +#define ADT7410ADDR_01 0x92 +#define ADT7410ADDR_1N 0x96 +#define ADT7410ADDR_10 0x96 +#define ADT7410ADDR_11 0x98 + +// ID +#define I_AM_ADT7410 0x19 +#define GET_ID(x) ((x >> 3) & 0x1f) +#define GET_REV(x) (x & 0x7) + +// Configration +#define OPERATION_MODE_CONT 0x00 +#define OPERATION_MODE_ONESHOT 0x20 +#define OPERATION_MODE_1SPS 0x40 +#define OPERATION_MODE_SHTDWN 0x60 +#define RESOLUTION_15BIT 0x00 +#define RESOLUTION_16BIT 0x80 + +/** ADT7410 class + * + * Analog Devices / ADT7410 16-Bit Digital I2C Temperature Sensor + * + * @code + * #include "mbed.h" + * #include "ADT7410.h" + * + * // I2C Communication + * ADT7410 t(PinName p_sda, PinName p_scl, addr); + * // If you connected I2C line not only this device but also other devices, + * // you need to declare following method. + * I2C i2c(PinName p_sda, PinName p_scl); + * ADT7410 t(I2C& p_i2c, addr); + * + * int main() { + * while(1){ + * printf("T=%5.2f degC\r\n", t.read_temp()); + * wait(1.0): + * } + * } + * @endcode + */ + +class ADT7410 +{ +public: + /** Configure data pin + * @param data SDA and SCL pins + * @param ADT7410 address (H/W configuration of A1,A0) + */ + ADT7410(PinName p_sda, PinName p_scl, uint8_t addr); + + /** Configure data pin (with other devices on I2C line) + * @param I2C previous definition + * @param ADT7410 address (H/W configuration of A1,A0) + */ + ADT7410(I2C& p_i2c, uint8_t addr); + + /** Read temperature data + * @param none + * @return temperature + */ + float read_temp(void); + + /** Read status reg. + * @param none + * @return status register value + */ + uint8_t read_status(void); + + /** Read configration reg. + * @param none + * @return configrartion register value + */ + uint8_t read_config(void); + + /** Set configration reg. + * @param + * @return configrartion register value + */ + uint8_t set_config(uint8_t cfg); + + /** Read ADT7410 chip ID + * @param none + * @return ID number + */ + uint8_t read_id(void); + + /** Read ADT7410 chip revision + * @param none + * @return revision data + */ + uint8_t read_revision(void); + +protected: + I2C _i2c; + + void read_all(); + void init(); + +private: + uint8_t dt[16]; + char ADT7410_addr; +}; + +#endif // MBED_ADT7410