Updated i2c interface to work correctly with mBed and Hexiwear
Dependents: Hexi_Click_IRThermo_Example
Fork of MLX90614 by
Diff: mlx90614.cpp
- Revision:
- 1:4a60d3f1e91e
- Child:
- 2:01d333d06727
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mlx90614.cpp Thu Jun 09 13:07:40 2011 +0000
@@ -0,0 +1,45 @@
+
+#include "mlx90614.h"
+
+MLX90614::MLX90614(I2C* i2c,int addr){
+
+ this->i2caddress = addr;
+ this->i2c = i2c;
+
+}
+
+
+bool MLX90614::getTemp(float* temp_val){
+
+ char p1,p2,p3;
+ float temp_thermo;
+ bool ch;
+
+ i2c->stop(); //stop i2c if not ack
+ wait(0.01);
+ i2c->start(); //start I2C
+ ch=i2c->write(i2caddress); //device address with write condition
+
+ if(!ch)return false; //No Ack, return False
+
+ ch=i2c->write(0x07); //device ram address where Tobj value is present
+
+ if(!ch)return false; //No Ack, return False
+
+
+ i2c->start(); //repeat start
+ ch=i2c->write(i2caddress|0x01); //device address with read condition
+ if(!ch)return false; //No Ack, return False
+
+ p1=i2c->read(1); //Tobj low byte
+ p2=i2c->read(1); //Tobj heigh byte
+ p3=i2c->read(0); //PEC
+
+ i2c->stop(); //stop condition
+
+
+ temp_thermo=((((p2&0x007f)<<8)+p1)*0.02)-0.01; //degree centigrate conversion
+ *temp_val=temp_thermo-273; //Convert kelvin to degree Celsius
+
+ return true; //load data successfully, return true
+}
\ No newline at end of file
