X-Git-Url: http://git.smho.de/gw/?p=owSlave2.git;a=blobdiff_plain;f=DS2438_SHT2X%2FDS2438_SHT2X.c;h=349736ee416c8b82b165bcd79cbfa692c1e46045;hp=0da98384346d6ef9063d16b191e7a97ef1ad3066;hb=HEAD;hpb=a6a04f58e4afd20f206fdf4a8a7b3ce4062f1b67 diff --git a/DS2438_SHT2X/DS2438_SHT2X.c b/DS2438_SHT2X/DS2438_SHT2X.c index 0da9838..349736e 100644 --- a/DS2438_SHT2X/DS2438_SHT2X.c +++ b/DS2438_SHT2X/DS2438_SHT2X.c @@ -1,4 +1,4 @@ -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de +// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -39,15 +39,14 @@ #include #include #include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/MAX44009.h" -#include "../common/I2C/SHT2x.h" +#include "../common/I2C/SHT2xV2.h" +#include "../common/calibr.h" extern void OWINIT(); extern void EXTERN_SLEEP(); uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0x00, 0x00, 0x05, 0x16};/**/ -uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; -//uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x08, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; +uint8_t config_info[26]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x02,0x07,0x00,0x07,0x00,0x00,0x00,0x00, 0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; extern uint8_t mode; @@ -86,8 +85,7 @@ volatile int16_t am2302_temp; volatile uint16_t am2302_hum; uint8_t userRegister[1]; -int16_t sRH,sT; -volatile double temperatureC,humidityRH; +double temperatureC,humidityRH; volatile double l; #if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) @@ -148,47 +146,34 @@ int main(void){ uint8_t i; for(i=0;i<64;i++) pack.bytes[i]=0; + pack.page3[0]=0xF1; MCUSR=0; USI_TWI_Master_Initialise(); - SHT2x_SoftReset(); - SHT2x_ReadUserRegister(userRegister); - //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT; - SHT2x_WriteUserRegister(userRegister); //write changed user reg - // --- measure humidity with "Hold Master Mode (HM)" --- - SHT2x_MeasurePoll(HUMIDITY, &sRH); - // --- measure temperature with "Polling Mode" (no hold master) --- - SHT2x_MeasurePoll(TEMP, &sT); - //-- calculate humidity and temperature -- - temperatureC = SHT2x_CalcTemperatureC(sT); - humidityRH = SHT2x_CalcRH(sRH); - + initSHT2x(); + _delay_ms(100); sei(); - while(1) { + while(1) { if (gcontrol) { wdcounter=3; gcontrol=0; } if (wdcounter>2) { - //PORTB|=(1<