Simple DS1621 temperature acquisition.
ds1621.h@3:d6310fd6df8e, 2011-03-21 (annotated)
- Committer:
- dupuyb
- Date:
- Mon Mar 21 16:51:22 2011 +0000
- Revision:
- 3:d6310fd6df8e
- Parent:
- 1:bef707045d41
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dupuyb | 0:d1667b4536dd | 1 | #ifndef DS1621_H |
dupuyb | 0:d1667b4536dd | 2 | #define DS1621_H |
dupuyb | 0:d1667b4536dd | 3 | //------------includes----------------- |
dupuyb | 0:d1667b4536dd | 4 | #include "mbed.h" |
dupuyb | 0:d1667b4536dd | 5 | //------------ |
dupuyb | 3:d6310fd6df8e | 6 | /** |
dupuyb | 3:d6310fd6df8e | 7 | * DS1621 simple control class, |
dupuyb | 0:d1667b4536dd | 8 | * |
dupuyb | 0:d1667b4536dd | 9 | * Example: |
dupuyb | 0:d1667b4536dd | 10 | * @code |
dupuyb | 0:d1667b4536dd | 11 | * // Continus temperature acquisition |
dupuyb | 0:d1667b4536dd | 12 | * #include "mbed.h" |
dupuyb | 0:d1667b4536dd | 13 | * #include "ds1621.h" |
dupuyb | 1:bef707045d41 | 14 | * |
dupuyb | 0:d1667b4536dd | 15 | * DigitalOut myled1(LED1); |
dupuyb | 0:d1667b4536dd | 16 | * DigitalOut myled2(LED2); |
dupuyb | 0:d1667b4536dd | 17 | * DigitalOut myled3(LED3); |
dupuyb | 0:d1667b4536dd | 18 | * DigitalOut myled4(LED4); |
dupuyb | 0:d1667b4536dd | 19 | * |
dupuyb | 1:bef707045d41 | 20 | * #define DS1621_ADDR 0 // I2c DS1621 address is 0x00 |
dupuyb | 0:d1667b4536dd | 21 | * |
dupuyb | 0:d1667b4536dd | 22 | * Serial pc(USBTX, USBRX); // Declare usb (see screen /dev/ttyUSB0 on linux) |
dupuyb | 1:bef707045d41 | 23 | * I2C i2c(p28, p27); // Declare I2C (pullup resistors 2.2k from p28 and p27 to +3.3v) |
dupuyb | 3:d6310fd6df8e | 24 | * DS1621 ds(&i2c, DS1621_ADDR); // Declare ds1621 throught i2c interface |
dupuyb | 0:d1667b4536dd | 25 | * |
dupuyb | 0:d1667b4536dd | 26 | *int main() { |
dupuyb | 0:d1667b4536dd | 27 | * i2c.frequency(5000); //5khz |
dupuyb | 0:d1667b4536dd | 28 | * pc.printf("-----------------------\n\rMain\n\r"); |
dupuyb | 0:d1667b4536dd | 29 | * char count = 0; |
dupuyb | 0:d1667b4536dd | 30 | * float temp = 0.0; |
dupuyb | 3:d6310fd6df8e | 31 | * ds.init(DS1621_ADDR); |
dupuyb | 0:d1667b4536dd | 32 | * while (1) { |
dupuyb | 0:d1667b4536dd | 33 | * myled1 = count & 0x01; |
dupuyb | 0:d1667b4536dd | 34 | * myled2 = count & 0x02; |
dupuyb | 0:d1667b4536dd | 35 | * myled3 = count & 0x04; |
dupuyb | 0:d1667b4536dd | 36 | * myled4 = count & 0x08; |
dupuyb | 0:d1667b4536dd | 37 | * count++; |
dupuyb | 3:d6310fd6df8e | 38 | * temp = ds.read(DS1621_ADDR); |
dupuyb | 0:d1667b4536dd | 39 | * pc.printf("Measurment at start + %d seconds, Temperature=%3.1f\n\r",(count*5),temp); |
dupuyb | 0:d1667b4536dd | 40 | * wait(5.0); |
dupuyb | 0:d1667b4536dd | 41 | * } |
dupuyb | 0:d1667b4536dd | 42 | *} |
dupuyb | 0:d1667b4536dd | 43 | * @endcode |
dupuyb | 0:d1667b4536dd | 44 | */ |
dupuyb | 0:d1667b4536dd | 45 | //------------defines------------------ |
dupuyb | 0:d1667b4536dd | 46 | #define DS1621_Write 0x90 |
dupuyb | 0:d1667b4536dd | 47 | #define DS1621_Read 0x91 |
dupuyb | 0:d1667b4536dd | 48 | //------------class-------------------- |
dupuyb | 0:d1667b4536dd | 49 | class DS1621 { |
dupuyb | 0:d1667b4536dd | 50 | //-----------methodes ----------------- |
dupuyb | 0:d1667b4536dd | 51 | public: |
dupuyb | 0:d1667b4536dd | 52 | /** |
dupuyb | 0:d1667b4536dd | 53 | *@brief Constructor, initializes the ds1621 on I2C interface. |
dupuyb | 0:d1667b4536dd | 54 | *@param interface |
dupuyb | 0:d1667b4536dd | 55 | *@param address DS1621 i2c address on bus |
dupuyb | 0:d1667b4536dd | 56 | *@return none |
dupuyb | 0:d1667b4536dd | 57 | */ |
dupuyb | 3:d6310fd6df8e | 58 | DS1621 (I2C* interface, uint8_t address); |
dupuyb | 0:d1667b4536dd | 59 | |
dupuyb | 0:d1667b4536dd | 60 | /** |
dupuyb | 0:d1667b4536dd | 61 | *@brief Get temperature as float to the ds1621 |
dupuyb | 0:d1667b4536dd | 62 | *@param address DS1621 i2c address on bus |
dupuyb | 0:d1667b4536dd | 63 | *@return current temperature as a float number in degrees Celsius |
dupuyb | 0:d1667b4536dd | 64 | */ |
dupuyb | 3:d6310fd6df8e | 65 | float read(uint8_t address); |
dupuyb | 3:d6310fd6df8e | 66 | |
dupuyb | 1:bef707045d41 | 67 | /** |
dupuyb | 3:d6310fd6df8e | 68 | *@brief Initialize DS1621 |
dupuyb | 3:d6310fd6df8e | 69 | *@param address DS1621 i2c address on bus |
dupuyb | 3:d6310fd6df8e | 70 | *@return none |
dupuyb | 1:bef707045d41 | 71 | */ |
dupuyb | 3:d6310fd6df8e | 72 | void init(uint8_t address); |
dupuyb | 1:bef707045d41 | 73 | |
dupuyb | 3:d6310fd6df8e | 74 | public: |
dupuyb | 3:d6310fd6df8e | 75 | bool dbx; // True activate debug message |
dupuyb | 0:d1667b4536dd | 76 | //---------- local variables ---------- |
dupuyb | 0:d1667b4536dd | 77 | private: |
dupuyb | 0:d1667b4536dd | 78 | I2C* i2c; // Communication interface |
dupuyb | 0:d1667b4536dd | 79 | //------------------------------------- |
dupuyb | 0:d1667b4536dd | 80 | }; |
dupuyb | 0:d1667b4536dd | 81 | #endif |