Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 0:6c56fb4bc5f0 1 #include "TMP102.h"
nexpaq 0:6c56fb4bc5f0 2
nexpaq 0:6c56fb4bc5f0 3 #define TEMP_REG_ADDR 0x00
nexpaq 0:6c56fb4bc5f0 4
nexpaq 0:6c56fb4bc5f0 5 TMP102::TMP102(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) {
nexpaq 0:6c56fb4bc5f0 6 m_i2c.frequency(400000);
nexpaq 0:6c56fb4bc5f0 7 }
nexpaq 0:6c56fb4bc5f0 8 TMP102::~TMP102() { }
nexpaq 0:6c56fb4bc5f0 9
nexpaq 0:6c56fb4bc5f0 10 float TMP102::read() {
nexpaq 0:6c56fb4bc5f0 11 const char tempRegAddr = TEMP_REG_ADDR;
nexpaq 0:6c56fb4bc5f0 12
nexpaq 0:6c56fb4bc5f0 13 m_i2c.write(m_addr, &tempRegAddr, 1);
nexpaq 0:6c56fb4bc5f0 14
nexpaq 0:6c56fb4bc5f0 15 char reg[2] = {0,0};
nexpaq 0:6c56fb4bc5f0 16 m_i2c.read(m_addr, reg, 2);
nexpaq 0:6c56fb4bc5f0 17
nexpaq 0:6c56fb4bc5f0 18 unsigned short res = (reg[0] << 4) | (reg[1] >> 4);
nexpaq 0:6c56fb4bc5f0 19
nexpaq 0:6c56fb4bc5f0 20 float temp = (float) ((float)res * 0.0625);
nexpaq 0:6c56fb4bc5f0 21
nexpaq 0:6c56fb4bc5f0 22 return temp;
nexpaq 0:6c56fb4bc5f0 23 }