Rostislav Krylov / MLX90614

Dependents:   HAND

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mlx90614.cpp Source File

mlx90614.cpp

00001  #include "mlx90614.h"
00002 
00003 
00004 
00005 
00006 MLX90614::MLX90614(I2C* i2c,int addr){
00007 
00008     this->i2caddress = addr;
00009     this->i2c = i2c; 
00010     
00011 }
00012 
00013 
00014 bool MLX90614::getTemp(float* temp_val){
00015 
00016     char p1,p2,p3;
00017     float temp_thermo;
00018     bool ch;
00019 
00020     i2c->stop();                            //stop i2c if not ack
00021     wait(0.01);
00022     i2c->start();                           //start I2C                   
00023     ch=i2c->write(i2caddress);              //device address with write condition
00024     
00025     if(!ch)return false;                    //No Ack, return False
00026     
00027     ch=i2c->write(0x07);                    //device ram address where Tobj value is present
00028 
00029     if(!ch)return false;                    //No Ack, return False
00030 
00031 
00032     i2c->start();                           //repeat start
00033     ch=i2c->write(i2caddress|0x01);         //device address with read condition 
00034     if(!ch)return false;                    //No Ack, return False
00035 
00036     p1=i2c->read(1);     //Tobj low byte
00037     p2=i2c->read(1);     //Tobj heigh byte
00038     p3=i2c->read(0);     //PEC
00039     
00040     i2c->stop();                            //stop condition
00041      
00042     
00043     temp_thermo=((((p2&0x007f)<<8)+p1)*0.02)-0.01;      //degree centigrate conversion
00044     *temp_val=temp_thermo-273;                          //Convert kelvin to degree Celsius
00045     
00046     return true;                            //load data successfully, return true 
00047 }