I2C 接続の温度センサ ADT7410 用のライブラリ. Library for temperature sensor ADT7410 connected using I2C interface.

Dependents:   Mbed2_ConnectTestAll Demo_ADT7410

Committer:
MikamiUitOpen
Date:
Mon Jun 15 07:26:05 2015 +0000
Revision:
1:ad3046485a3e
Parent:
0:b6dc7c54b451
Child:
2:c134a43c7875
2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 0:b6dc7c54b451 1 //--------------------------------------------------------------
MikamiUitOpen 0:b6dc7c54b451 2 // Class for using ADT7410 (Header)
MikamiUitOpen 1:ad3046485a3e 3 // 2015/06/15, Copyright (c) 2015 MIKAMI, Naoki
MikamiUitOpen 0:b6dc7c54b451 4 //--------------------------------------------------------------
MikamiUitOpen 0:b6dc7c54b451 5
MikamiUitOpen 0:b6dc7c54b451 6 #ifndef ADT7410_HPP
MikamiUitOpen 0:b6dc7c54b451 7 #define ADT7410_HPP
MikamiUitOpen 0:b6dc7c54b451 8
MikamiUitOpen 0:b6dc7c54b451 9 #include "mbed.h"
MikamiUitOpen 0:b6dc7c54b451 10
MikamiUitOpen 0:b6dc7c54b451 11 namespace Mikami
MikamiUitOpen 0:b6dc7c54b451 12 {
MikamiUitOpen 0:b6dc7c54b451 13 class ADT7410
MikamiUitOpen 0:b6dc7c54b451 14 {
MikamiUitOpen 0:b6dc7c54b451 15 public:
MikamiUitOpen 0:b6dc7c54b451 16 // Constructor
MikamiUitOpen 0:b6dc7c54b451 17 ADT7410(PinName sda = D14, // SDA
MikamiUitOpen 0:b6dc7c54b451 18 PinName scl = D15, // SCL
MikamiUitOpen 0:b6dc7c54b451 19 uint8_t addr = 0x90); // I2C bus address
MikamiUitOpen 0:b6dc7c54b451 20
MikamiUitOpen 0:b6dc7c54b451 21 // Set configuration register
MikamiUitOpen 0:b6dc7c54b451 22 void SetConfig(char val);
MikamiUitOpen 0:b6dc7c54b451 23
MikamiUitOpen 0:b6dc7c54b451 24 // Get value in configuration register
MikamiUitOpen 0:b6dc7c54b451 25 uint8_t GetConfig();
MikamiUitOpen 0:b6dc7c54b451 26
MikamiUitOpen 1:ad3046485a3e 27 // Read temperature
MikamiUitOpen 1:ad3046485a3e 28 float Read();
MikamiUitOpen 1:ad3046485a3e 29
MikamiUitOpen 1:ad3046485a3e 30 // Operator shorthand for Read()
MikamiUitOpen 1:ad3046485a3e 31 operator float() { return Read(); }
MikamiUitOpen 1:ad3046485a3e 32
MikamiUitOpen 1:ad3046485a3e 33 // Reset
MikamiUitOpen 1:ad3046485a3e 34 void Reset();
MikamiUitOpen 0:b6dc7c54b451 35
MikamiUitOpen 0:b6dc7c54b451 36 protected:
MikamiUitOpen 0:b6dc7c54b451 37 // Write single byte
MikamiUitOpen 0:b6dc7c54b451 38 // "STOP" を送らずにふたたび "START" を送る,つまりリスタート・コンディションに
MikamiUitOpen 0:b6dc7c54b451 39 // する場合は,"repeated" を "true" にする
MikamiUitOpen 0:b6dc7c54b451 40 void WriteSingleByte(char reg, bool repeated = false)
MikamiUitOpen 0:b6dc7c54b451 41 { i2c_.write(addr_, &reg, 1, repeated); };
MikamiUitOpen 0:b6dc7c54b451 42
MikamiUitOpen 0:b6dc7c54b451 43 private:
MikamiUitOpen 0:b6dc7c54b451 44 // Register addresses
MikamiUitOpen 0:b6dc7c54b451 45 static const uint8_t TEMPER_ = 0x00; // Temperature value MSByte
MikamiUitOpen 0:b6dc7c54b451 46 static const uint8_t CONFIG_ = 0x03; // Configuration
MikamiUitOpen 0:b6dc7c54b451 47 static const uint8_t RESET_ = 0x2F; // Software reset
MikamiUitOpen 0:b6dc7c54b451 48
MikamiUitOpen 0:b6dc7c54b451 49 const uint8_t addr_; // left-justified 7-bit slave address of ADT7410
MikamiUitOpen 0:b6dc7c54b451 50 I2C i2c_; // Object of I2C
MikamiUitOpen 0:b6dc7c54b451 51 };
MikamiUitOpen 0:b6dc7c54b451 52 }
MikamiUitOpen 0:b6dc7c54b451 53 #endif // ADT7410_HPP