PRESA Raphaël
/
essai_DS1621
capteur DS1621
Diff: Main.cpp
- Revision:
- 0:78facd7c14b8
diff -r 000000000000 -r 78facd7c14b8 Main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Main.cpp Wed May 20 12:03:32 2020 +0000 @@ -0,0 +1,65 @@ +#include "ds1621.h" + + + +#define DS1621_ADDR 0x90 // I2c DS1621 address is 0x00 + +Serial pc(USBTX, USBRX); // port série USB +//pins are: TX RX + + +I2C i2c(p9, p10); // Declare I2C (pullup resistors 2.2k from p9 and p10 to +5v) +DS1621 ds(&i2c, DS1621_ADDR); // Declare ds1621 throught i2c interface + + + + +float Temperature = 24.0, + Temp_H=25.0, + Temp_L=23.0, + Temp_cons=35, + hysteresis=5.0, + periode=1.0; // acquisition toutes les secondes + +unsigned char trame[6]; +int cpt=0; // compteur trame +int flag=0; // detection de debut de trame +int etat_regulation=0; // =0 pas de regulation =1 regulation +int Sortie_reg=0; // etat sortie reg du DS1621 + + + +int main() { + i2c.frequency(5000); //5khz + pc.printf("-----------------------\n\rMain\n\r"); + char reg; + int result; + + + + ds.SetConfig(0x00); // POL=1, 1SHOT=0 + wait(1); + reg=ds.ReadReg(ACCESS_CONFIG); // lecture registre CONFIG pour controle + pc.printf("REG=%d\n\r",reg); + ds.SetLimit(ACCESS_TH,-20); // fixe TH: valeur basse pour avoir commande de sortie =0 + wait(1); + ds.SetLimit(ACCESS_TL, -21.0); // fixe TL: valeur basse pour avoir commande de sortie =0 + wait(1); + + ds.StartConversion(1); + wait(1); + + result=ds.GetTemp(ACCESS_TL,&Temp_L); + if(result==1) pc.printf("TL=%3.1f\n\r",Temp_L); + wait(1); + result= ds.GetTemp(ACCESS_TH,&Temp_H); + if(result==1) pc.printf("TH=%3.1f\n\r",Temp_H); + wait(1); + + while (1) { + result= ds.GetTemp(READ_TEMPERATURE,&Temperature); // acquisition Temp à 0.5 + //result= ds.GetHResTemp(&Temperature); // acquisition Temp à 0.1 °C + pc.printf("Temperature=%3.1f C\n\r",Temperature); + wait(1); + } +}