modify the write function for temperature update If you use update temperature, you modify the repeat condition when write function use - read16() -> m_I2C.write(m_Addr, ®, 1); //stop condition - read16() -> m_I2C.write(m_Addr, ®, 1,1); //repeat condition
Fork of LM75B by
Diff: LM75B.cpp
- Revision:
- 17:c62f1e2d721e
- Parent:
- 9:74b44a27fa40
--- a/LM75B.cpp Mon Sep 16 21:32:18 2013 +0000 +++ b/LM75B.cpp Mon Jul 20 09:36:26 2015 +0000 @@ -16,12 +16,14 @@ #include "LM75B.h" -LM75B::LM75B(PinName sda, PinName scl, Address addr) : m_I2C(sda, scl) +LM75B::LM75B(PinName sda, PinName scl, Address addr, int hz) : m_I2C(sda, scl) { //Set the internal device address m_Addr = (int)addr; + m_I2C.frequency(hz); } + bool LM75B::open(void) { //Probe for the LM75B using a Zero Length Transfer @@ -187,13 +189,12 @@ //Read the 11-bit raw temperature value value = read16(REG_TEMP) >> 5; - //Sign extend negative numbers if (value & (1 << 10)) value |= 0xFC00; //Return the temperature in °C - return value * 0.125; + return value*0.125; } char LM75B::read8(char reg) @@ -227,7 +228,7 @@ char buff[2]; //Select the register - m_I2C.write(m_Addr, ®, 1); + m_I2C.write(m_Addr, ®, 1,1); //Read the 16-bit register m_I2C.read(m_Addr, buff, 2);