PRESA Raphaël
/
essai_DS1621
capteur DS1621
ds1621.h@0:78facd7c14b8, 2020-05-20 (annotated)
- Committer:
- rpresa
- Date:
- Wed May 20 12:03:32 2020 +0000
- Revision:
- 0:78facd7c14b8
essai DS1621
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rpresa | 0:78facd7c14b8 | 1 | #ifndef __DS1621_H |
rpresa | 0:78facd7c14b8 | 2 | #define __DS1621_H |
rpresa | 0:78facd7c14b8 | 3 | |
rpresa | 0:78facd7c14b8 | 4 | #define VERSION 1.0 |
rpresa | 0:78facd7c14b8 | 5 | |
rpresa | 0:78facd7c14b8 | 6 | #include <mbed.h> |
rpresa | 0:78facd7c14b8 | 7 | |
rpresa | 0:78facd7c14b8 | 8 | //Temperature conversion commands |
rpresa | 0:78facd7c14b8 | 9 | #define READ_TEMPERATURE 0xAA |
rpresa | 0:78facd7c14b8 | 10 | #define READ_COUNTER 0xA8 |
rpresa | 0:78facd7c14b8 | 11 | #define READ_SLOPE 0xA9 |
rpresa | 0:78facd7c14b8 | 12 | #define START_CONVERT_T 0xEE |
rpresa | 0:78facd7c14b8 | 13 | #define STOP_CONVERT_T 0x22 |
rpresa | 0:78facd7c14b8 | 14 | |
rpresa | 0:78facd7c14b8 | 15 | //Thermostat commands |
rpresa | 0:78facd7c14b8 | 16 | #define ACCESS_TH 0xA1 |
rpresa | 0:78facd7c14b8 | 17 | #define ACCESS_TL 0xA2 |
rpresa | 0:78facd7c14b8 | 18 | #define ACCESS_CONFIG 0xAC |
rpresa | 0:78facd7c14b8 | 19 | |
rpresa | 0:78facd7c14b8 | 20 | //Bits of Config register |
rpresa | 0:78facd7c14b8 | 21 | #define DONE 0x80 |
rpresa | 0:78facd7c14b8 | 22 | #define THF 0x40 |
rpresa | 0:78facd7c14b8 | 23 | #define TLF 0x20 |
rpresa | 0:78facd7c14b8 | 24 | #define NVB 0x10 |
rpresa | 0:78facd7c14b8 | 25 | #define POL 0x02 |
rpresa | 0:78facd7c14b8 | 26 | #define ONESHOT 0x01 |
rpresa | 0:78facd7c14b8 | 27 | |
rpresa | 0:78facd7c14b8 | 28 | class DS1621 { |
rpresa | 0:78facd7c14b8 | 29 | public: |
rpresa | 0:78facd7c14b8 | 30 | DS1621(I2C* interface, unsigned char address); |
rpresa | 0:78facd7c14b8 | 31 | |
rpresa | 0:78facd7c14b8 | 32 | // Set configuration register |
rpresa | 0:78facd7c14b8 | 33 | void SetConfig(unsigned char cfg); |
rpresa | 0:78facd7c14b8 | 34 | |
rpresa | 0:78facd7c14b8 | 35 | // Read a DS1621 register |
rpresa | 0:78facd7c14b8 | 36 | unsigned char ReadReg(unsigned char reg); |
rpresa | 0:78facd7c14b8 | 37 | |
rpresa | 0:78facd7c14b8 | 38 | // Sets temperature limit |
rpresa | 0:78facd7c14b8 | 39 | // -- works only with ACCESS_TL, and ACCESS_TH |
rpresa | 0:78facd7c14b8 | 40 | void SetLimit(unsigned char reg, float temp); |
rpresa | 0:78facd7c14b8 | 41 | |
rpresa | 0:78facd7c14b8 | 42 | // Start/Stop DS1621 temperature conversion |
rpresa | 0:78facd7c14b8 | 43 | void StartConversion(bool start); |
rpresa | 0:78facd7c14b8 | 44 | |
rpresa | 0:78facd7c14b8 | 45 | // Reads temperature or limit |
rpresa | 0:78facd7c14b8 | 46 | // -- works only with READ_TEMPERATURE, ACCESS_TL, and ACCESS_TH |
rpresa | 0:78facd7c14b8 | 47 | // -- for actual temperature, set ONESHOT mode off and start conversion |
rpresa | 0:78facd7c14b8 | 48 | // -- returns true if reg valid |
rpresa | 0:78facd7c14b8 | 49 | bool GetTemp(unsigned char reg, float *Temp); |
rpresa | 0:78facd7c14b8 | 50 | |
rpresa | 0:78facd7c14b8 | 51 | // Read high resolution temperature |
rpresa | 0:78facd7c14b8 | 52 | // -- returns temperature in 1/100ths degrees |
rpresa | 0:78facd7c14b8 | 53 | // -- DS1621 is set in ONESHOT mode |
rpresa | 0:78facd7c14b8 | 54 | // -- returns true if conversion has finished, new temperature is calculated |
rpresa | 0:78facd7c14b8 | 55 | // -- returns false if conversion is busy, previous temperature is given |
rpresa | 0:78facd7c14b8 | 56 | bool GetHResTemp(float *Temp); |
rpresa | 0:78facd7c14b8 | 57 | |
rpresa | 0:78facd7c14b8 | 58 | private: |
rpresa | 0:78facd7c14b8 | 59 | I2C* i2c; // Communication interface |
rpresa | 0:78facd7c14b8 | 60 | unsigned char address; |
rpresa | 0:78facd7c14b8 | 61 | void ReadChipTemp(unsigned char cmd, unsigned char *data); |
rpresa | 0:78facd7c14b8 | 62 | bool conversion_busy; |
rpresa | 0:78facd7c14b8 | 63 | float LastTemp; |
rpresa | 0:78facd7c14b8 | 64 | }; |
rpresa | 0:78facd7c14b8 | 65 | #endif |