A small library to read the tempature from ds1621(with little changes all those ds162x) devices over I2C.
Diff: ds1621.cpp
- Revision:
- 0:0687b136fcab
- Child:
- 1:eda09b9ea6e2
diff -r 000000000000 -r 0687b136fcab ds1621.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ds1621.cpp Tue Nov 02 22:31:32 2010 +0000 @@ -0,0 +1,48 @@ +#ifndef TEMPATURE_C +#define TEMPATURE_C + + +#include "ds1621.h" + +static I2C* i2c; + +I2C * init_tempature(I2C *interface) { + i2c = interface; + if (i2c == NULL) { + i2c = new I2C(p28,p27); + } + i2c->frequency(100000);//100khz + + return i2c; +} + /*FIXME: return a float or something instead of a lousy string*/ +void get_tempature(unsigned int adress, char * s) { // adress of the i2c ds1621 sensor, char buffer to contain the + unsigned char TempH, TempL; + int8_t data; + adress &= 0x0E; + data = 0xEE; + i2c->write(DS1621_Write|adress,(char *)&data,sizeof(data)); + data = 0xAA; + i2c->write(DS1621_Write|adress,(char *)&data,sizeof(data)); + + i2c->read(DS1621_Read|adress,(char *)&TempH,sizeof(TempH),1); + i2c->read(DS1621_Read|adress,(char *)&TempL,sizeof(TempL),0); + + pc.printf("temph = 0x%x, TempL = 0x%x",TempH,TempL); + /*itoa(TempH,s,10); // convert to string + while (*s) { + s++; // goto end of string + } + *s++ = '.'; + if (TempL == 0x80) { + *s++ = '5'; + + } else { + *s++ = '0'; + } + *s = 0x00; //mark endo of string*/ +} + + + +#endif