I2C 接続の温度センサ ADT7410 用のライブラリ. Library for temperature sensor ADT7410 connected using I2C interface.
Dependents: Mbed2_ConnectTestAll Demo_ADT7410
ADT7410.cpp
- Committer:
- MikamiUitOpen
- Date:
- 2017-10-28
- Revision:
- 5:bbcd91ba7c6b
- Parent:
- 4:3769397d3803
- Child:
- 6:438204ab1793
File content as of revision 5:bbcd91ba7c6b:
//-------------------------------------------------------------- // Class for ADT7410 // Default: 13-bit resolution // // このプログラムを作った際の mbed のリビジョン:Rev.154 // 2017/10/28, Copyright (c) 2017 MIKAMI, Naoki //-------------------------------------------------------------- #include "ADT7410.hpp" namespace Mikami { // Constructor ADT7410::ADT7410(PinName sda, PinName scl, uint8_t addr) : ADDR_(addr), i2c_(sda, scl) { Reset(); } // Get value in configuration register // See Figure 17 in data sheet of ADT7410 uint8_t ADT7410::GetConfig() { WriteSingleByte(CONFIG_, true); char rReg[1]; i2c_.read(ADDR_, rReg, 1); return rReg[0]; } // Read temperature // See Figure 18 in data sheet of ADT7410 float ADT7410::Read() { WriteSingleByte(TEMPER_, true); char rReg[2]; i2c_.read(ADDR_, rReg, 2); int16_t value = (rReg[0] << 8) | rReg[1]; if ( (GetConfig() & 0x80) == 0x00 ) value &= 0xfff8; // For 13-bit resolution return value/128.0f; } // Reset // See p.19 in data sheet Rev.A of ADT7410 void ADT7410::Reset() { WriteSingleByte(RESET_); wait_ms(250); SetConfig(0x00); } }