TMP112 and TMP102 Interface Example

Dependencies:   mbed tmp112

main.cpp

Committer:
CamiloRuiz
Date:
2016-05-12
Revision:
0:373d0c67a763

File content as of revision 0:373d0c67a763:

/*
Copyright (c) 2016 Camilo Ruiz 
 
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

//this should work with tmp102 too
//I do not use negative values on my application, this code has to be tweaked to support it
//I do not use extended mode, this code has to be tweaked to support it

//greetings from Colombia :)

//I used TinyBle platform from SeeedStudio

#include "mbed.h"
#include "tiny_ble.h"
#include "TMP112.h"

TMP112 TempSensor(p3, p4,0x90);

DigitalOut power_out(POWER_OUT_EN); //power output TinyBle
Serial pc(UART_TX, UART_RX);

int main()
{
    pc.baud(115200);
    power_out=1;        //enable power output TinyBle
    wait(1.0);          //give sensor some time to  powerup
    TempSensor.writeCFG(TMP112_12BITS| TMP112_CFG_1FAULT | TMP112_CFG_ALERT_LOW | TMP112_CFG_TM_COMP_MODE
                        | TMP112_CFG_ON | TMP112_CFG_CR_1Hz | TMP112_CFG_EM_OFF);
    TempSensor.write_TM_Htemp(25.5);
    TempSensor.write_TM_Ltemp(25.0);
    while(1) {
        pc.printf("temperature: %f \n", TempSensor.readTemperature());
        pc.printf("tresh High:  %f \n", TempSensor.readTM_Htemp());
        pc.printf("tresh low:   %f \n", TempSensor.readTM_Ltemp());
        pc.printf("Config:      %X \n", TempSensor.readCFG());
        wait(1.0);

    }
}