Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TMP102.cpp Source File

TMP102.cpp

00001 #include "TMP102.h"
00002 
00003 #define TEMP_REG_ADDR 0x00
00004 
00005 TMP102::TMP102(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) {
00006     m_i2c.frequency(400000);
00007 }
00008 TMP102::~TMP102 () { }
00009 
00010 float TMP102::read() {
00011     const char tempRegAddr = TEMP_REG_ADDR;
00012 
00013     m_i2c.write(m_addr, &tempRegAddr, 1);
00014 
00015     char reg[2] = {0,0};
00016     m_i2c.read(m_addr, reg, 2);
00017 
00018     unsigned short res = (reg[0] << 4) | (reg[1] >> 4);
00019 
00020     float temp =  (float) ((float)res * 0.0625);
00021 
00022     return temp;
00023 }