MLX90614 library. Working on both Mbed2 and Mbed5
Fork of MLX90614 by
Revision 5:933b7db866c5, committed 2018-05-04
- Comitter:
- masrodjie
- Date:
- Fri May 04 07:29:44 2018 +0000
- Parent:
- 4:dcd4fe76bd13
- Commit message:
- Fix library to working on latest Mbed2 & Mbed5
Changed in this revision
mlx90614.cpp | Show annotated file Show diff for this revision Revisions of this file |
mlx90614.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r dcd4fe76bd13 -r 933b7db866c5 mlx90614.cpp --- a/mlx90614.cpp Thu Jun 09 13:50:26 2011 +0000 +++ b/mlx90614.cpp Fri May 04 07:29:44 2018 +0000 @@ -14,34 +14,25 @@ bool MLX90614::getTemp(float* temp_val){ - char p1,p2,p3; + char data[3]; float temp_thermo; - bool ch; - i2c->stop(); //stop i2c if not ack + i2c->stop(); + wait(0.02); + i2c->start(); 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 + data[0] = 0x00; + i2c->write((i2caddress<<1), data, 1, true); + wait(0.01); + data[0] = 0x07; + i2c->write((i2caddress<<1), data, 1, true); + wait(0.01); + i2c->read(((i2caddress<<1)|0x01), data, 3, true); + wait(0.01); + i2c->stop(); //stop condition - 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_thermo=((((data[1]&0x007f)<<8)+data[0])*0.02)-0.01; //degree centigrate conversion *temp_val=temp_thermo-273; //Convert kelvin to degree Celsius return true; //load data successfully, return true
diff -r dcd4fe76bd13 -r 933b7db866c5 mlx90614.h --- a/mlx90614.h Thu Jun 09 13:50:26 2011 +0000 +++ b/mlx90614.h Fri May 04 07:29:44 2018 +0000 @@ -20,8 +20,8 @@ * #include "mbed.h" * #include "mlx90614.h" * -* I2C i2c(p28,p27); //sda,scl -* MLX90614 thermometer(&i2c); +* I2C i2c(PB_9, PB_8); //sda,scl +* MLX90614 thermometer(&i2c, 0x5A); * float temp; * * void main(void){ @@ -41,9 +41,9 @@ /** Create MLX90614 interface, initialize with selected I2C port and address. * * @param i2c I2C device pointer - * @param addr Device address(default=0xB4) + * @param addr Device address(default=0x5A) */ - MLX90614(I2C* i2c,int addr=0xB4); + MLX90614(I2C* i2c,int addr=0x5A); /** Get Temperature data from MLX90614. *