test MAX31850

Dependencies:   OneWireFB mbed

Committer:
fblanc
Date:
Wed Sep 28 06:46:10 2016 +0000
Revision:
4:031e71e61e80
Parent:
0:55f2866e9c0c
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fblanc 0:55f2866e9c0c 1 #include "shtlib.h"
fblanc 0:55f2866e9c0c 2
fblanc 0:55f2866e9c0c 3 int sht_writefile(SHT75 sht,float *ptr_temperature,float *ptr_humidity) {
fblanc 0:55f2866e9c0c 4 float humi_f,rh_lin,rh_true; // working registers for Illustration purposes
fblanc 0:55f2866e9c0c 5 int t; // temporary store for the temp ticks
fblanc 0:55f2866e9c0c 6 int h; // temp store for the humidity ticks
fblanc 0:55f2866e9c0c 7 sht.readTempTicks(&t);
fblanc 0:55f2866e9c0c 8 *ptr_temperature = ((float)(t) * SHT_D2) + SHT_D1;
fblanc 0:55f2866e9c0c 9 sht.readHumidityTicks(&h);
fblanc 0:55f2866e9c0c 10 humi_f = (float)(h);
fblanc 0:55f2866e9c0c 11 rh_lin = SHT_C3 * humi_f * humi_f + SHT_C2 * humi_f + SHT_C1;
fblanc 0:55f2866e9c0c 12 rh_true=(((*ptr_temperature/100)-25)*(SHT_T1+SHT_T2*humi_f)+rh_lin);
fblanc 0:55f2866e9c0c 13 if (rh_true>100)rh_true=-1; //cut if the value is outside
fblanc 0:55f2866e9c0c 14 if (rh_true<1)rh_true=-1; //the physical possible range
fblanc 0:55f2866e9c0c 15 *ptr_humidity = rh_true;
fblanc 0:55f2866e9c0c 16 return 0;
fblanc 0:55f2866e9c0c 17 }
fblanc 0:55f2866e9c0c 18
fblanc 0:55f2866e9c0c 19
fblanc 0:55f2866e9c0c 20 int sht_init(SHT75 sht, const char *hwAddr, char *text_temp, char *text_humi) {
fblanc 0:55f2866e9c0c 21 int t;
fblanc 0:55f2866e9c0c 22 char shtcode[9];
fblanc 0:55f2866e9c0c 23 sht.reset();
fblanc 0:55f2866e9c0c 24 if (sht.readTempTicks(&t)==true) {
fblanc 0:55f2866e9c0c 25 shtcode[7]=hwAddr[5];
fblanc 0:55f2866e9c0c 26 shtcode[6]=hwAddr[4];
fblanc 0:55f2866e9c0c 27 shtcode[5]=hwAddr[3];
fblanc 0:55f2866e9c0c 28 shtcode[4]=hwAddr[2];
fblanc 0:55f2866e9c0c 29 shtcode[3]=hwAddr[1];
fblanc 0:55f2866e9c0c 30 shtcode[2]=hwAddr[0];
fblanc 0:55f2866e9c0c 31 shtcode[1]=0x00;
fblanc 0:55f2866e9c0c 32 shtcode[0]=0x80; //famille SHT_temp
fblanc 0:55f2866e9c0c 33 shtcode[8]=crc8((uint8_t*)&shtcode[0],8);
fblanc 0:55f2866e9c0c 34 sprintf(text_temp,"%02X%02X%02X%02X%02X%02X%02X%02X%02X",
fblanc 0:55f2866e9c0c 35 shtcode[0], shtcode[1], shtcode[2],
fblanc 0:55f2866e9c0c 36 shtcode[3], shtcode[4], shtcode[5],
fblanc 0:55f2866e9c0c 37 shtcode[6], shtcode[7], shtcode[8]);
fblanc 0:55f2866e9c0c 38 shtcode[0]=0x81; //famille SHT_humi
fblanc 0:55f2866e9c0c 39 shtcode[8]=crc8((uint8_t*)&shtcode[0],8);
fblanc 0:55f2866e9c0c 40 sprintf(text_humi,"%02X%02X%02X%02X%02X%02X%02X%02X%02X",
fblanc 0:55f2866e9c0c 41 shtcode[0], shtcode[1], shtcode[2],
fblanc 0:55f2866e9c0c 42 shtcode[3], shtcode[4], shtcode[5],
fblanc 0:55f2866e9c0c 43 shtcode[6], shtcode[7], shtcode[8]);
fblanc 0:55f2866e9c0c 44 return true; //sht present
fblanc 0:55f2866e9c0c 45 }
fblanc 0:55f2866e9c0c 46 return false;//sht absent
fblanc 0:55f2866e9c0c 47 }