Updated i2c interface to work correctly with mBed and Hexiwear
Dependents: Hexi_Click_IRThermo_Example
Fork of MLX90614 by
Revision 1:4a60d3f1e91e, committed 2011-06-09
- Comitter:
- aquahika
- Date:
- Thu Jun 09 13:07:40 2011 +0000
- Parent:
- 0:9237d31f0d03
- Child:
- 2:01d333d06727
- Commit message:
Changed in this revision
--- a/mlx90614.c Wed Jun 08 09:20:11 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-
-#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
--- /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
--- a/mlx90614.h Wed Jun 08 09:20:11 2011 +0000
+++ b/mlx90614.h Thu Jun 09 13:07:40 2011 +0000
@@ -1,26 +1,26 @@
-#include "mbed.h"
-
-//Melexis Infrared Thermometer MLX90614 Library
-
-//*****************************************************************
-// Build : 2011-06-08 Hikaru Sugiura
-// Only read thermo data.
-//
-// This program is based on Mr.Mitesh Patel's "mlx90614".
-// http://mbed.org/users/mitesh2patel/programs/mlx90614/lqnetj
-//
-// This program does not check CRC.
-// If you want to check CRC, please do it your self :)
-//****************************************************************//
-
-class MLX90614{
-
- public:
- MLX90614(I2C* i2c,int addr=0xB4);
- bool getTemp(float* temp_val);
-
- private:
- I2C* i2c;
- int i2caddress;
-
+#include "mbed.h"
+
+//Melexis Infrared Thermometer MLX90614 Library
+
+//*****************************************************************
+// Build : 2011-06-08 Hikaru Sugiura
+// Only read thermo data.
+//
+// This program is based on Mr.Mitesh Patel's "mlx90614".
+// http://mbed.org/users/mitesh2patel/programs/mlx90614/lqnetj
+//
+// This program does not check CRC.
+// If you want to check CRC, please do it your self :)
+//****************************************************************//
+
+class MLX90614{
+
+ public:
+ MLX90614(I2C* i2c,int addr=0xB4);
+ bool getTemp(float* temp_val);
+
+ private:
+ I2C* i2c;
+ int i2caddress;
+
};
\ No newline at end of file
