#include <avr/sleep.h>\r
#include <avr/pgmspace.h>\r
#include "../common/I2C/USI_TWI_Master.h"\r
-#include "../common/I2C/SHT2x.h"\r
+#include "../common/I2C/SHT2xV2.h"\r
+#include "../common/owSlave_tools.h"\r
\r
+OWST_EXTERN_VARS\r
\r
-extern void OWINIT();\r
-extern void EXTERN_SLEEP();\r
+//#define K_Type\r
+#define J_Type\r
\r
+#ifdef K_Type\r
//const float k_rs[54] PROGMEM ={0.000000,24.125000,48.585366,72.731707,96.829268,121.097561,145.700000,170.600000,195.650000,220.625000,245.365854,269.853659,294.119048,318.195122,342.166667,366.000000,389.761905,413.428571,437.023810,460.558140,484.047619,507.511628,530.976190,554.418605,577.883721,601.395349,624.952381,648.571429,672.285714,696.073171,719.976190,744.000000,768.146341,792.439024,816.853659,841.414634,866.125000,890.975000,916.000000,941.179487,966.525000,992.025641,1017.717949,1043.589744,1069.657895,1095.945946,1122.432432,1149.184211,1176.189189,1203.472222,1231.083333,1259.000000,1287.285714,1315.941176};\r
const float k_rs[61] PROGMEM ={ -212.538462, -166.260870, -124.892857, -97.562500, -66.888889, -34.157895, 0.000000, 24.125000, 48.585366, 72.731707, 96.829268, 121.097561, 145.700000, 170.600000, 195.650000, 220.625000, 245.365854, 269.853659, 294.119048, 318.192771, 342.166667, 366.000000, 389.761905, 413.428571, 437.023810, 460.558140, 484.047619, 507.511628, 530.976190, 554.418605, 577.883721, 601.395349, 624.952381, 648.571429, 672.285714, 696.073171, 719.976190, 744.000000, 768.146341, 792.439024, 816.853659, 841.414634, 866.125000, 890.975000, 916.000000, 941.179487, 966.525000, 992.025641, 1017.717949, 1043.589744, 1069.657895, 1095.945946, 1122.432432, 1149.173333, 1176.189189, 1203.472222, 1231.083333, 1259.000000, 1287.285714, 1315.941176, 1344.941176};\r
#define k_ofs 6\r
+#endif\r
+#ifdef J_Type\r
+#define k_ofs 0\r
+//J-Type\r
+const float k_rs[70] PROGMEM ={0, 18.302913, 34.830476, 50.783019, 70.653704, 90.505455, 110.341818, 130.165455, 149.163636, 160.791071, 180.596364, 200.398214, 220.200000, 240.000000, 250.882883, 270.603636, 290.409091, 310.216364, 330.025455, 342.472727, 360.649091, 380.461818, 400.275000, 420.087273, 435.275676, 450.703636, 470.503636, 490.298214, 510.082456, 523.486726, 540.621053, 560.370175, 580.105172, 591.979487, 610.527119, 630.213559, 644.601653, 660.534426, 680.168852, 690.787097, 710.391935, 729.123810, 740.559375, 760.126562, 770.684615, 790.235385, 800.782812, 820.331250, 834.681250, 850.446032, 870.017460, 880.600000, 900.196774, 911.099187, 930.432787, 950.073333, 960.728333, 980.396667, 1000.078333, 1010.772881, 1030.475862, 1050.187931, 1065.717241, 1080.631034, 1100.358621, 1120.089655, 1131.840000,1150.556897, 1170.294737, 1190.035088};\r
+#endif\r
\r
-//const float j_rs[70] PROGMEM ={0, 18.302913, 34.830476, 50.783019, 70.653704, 90.505455, 110.341818, 130.165455, 149.163636, 160.791071, 180.596364, 200.398214, 220.200000, 240.000000, 250.882883, 270.603636, 290.409091, 310.216364, 330.025455, 342.472727, 360.649091, 380.461818, 400.275000, 420.087273, 435.275676, 450.703636, 470.503636, 490.298214, 510.082456, 523.486726, 540.621053, 560.370175, 580.105172, 591.979487, 610.527119, 630.213559, 644.601653, 660.534426, 680.168852, 690.787097, 710.391935, 729.123810, 740.559375, 760.126562, 770.684615, 790.235385, 800.782812, 820.331250, 834.681250, 850.446032, 870.017460, 880.600000, 900.196774, 911.099187, 930.432787, 950.073333, 960.728333, 980.396667, 1000.078333, 1010.772881, 1030.475862, 1050.187931, 1065.717241, 1080.631034, 1100.358621, 1120.089655, 1131.840000,1150.556897, 1170.294737, 1190.035088};\r
double gettemp_rs(double V) {\r
uint8_t iv=(uint8_t)(V+k_ofs);\r
float t0=pgm_read_float(&(k_rs[iv]));\r
uint8_t config_info1[26]={0x01,0x02 ,0x00,0x00, 0x00,0x00, 0x00,0x00, 0x02,6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; \r
uint8_t config_info2[26]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x02,7,0x00,7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; \r
\r
-#if (owid>128) \r
-#error "Variable not correct"\r
-#endif\r
-\r
-extern uint8_t mode;\r
-extern uint8_t gcontrol;\r
-extern uint8_t reset_indicator;\r
-extern uint8_t alarmflag;\r
-volatile uint8_t wdcounter=5;\r
-\r
-\r
-#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__)\r
-ISR(WATCHDOG_vect) {\r
-#else\r
-ISR(WDT_vect) {\r
-#endif \r
- //sleep_disable(); // Disable Sleep on Wakeup\r
- wdcounter++;\r
- if (reset_indicator==1) reset_indicator++;\r
- else if (reset_indicator==2) mode=0;\r
-/* if (timeout==2) {\r
- DIS_TIMER;\r
- EN_OWINT;\r
- mode=OWM_SLEEP;\r
- }\r
- timeout++;*/\r
- //sleep_enable(); // Enable Sleep Mode\r
-\r
-}\r
-\r
-int testSW(void) {\r
- uint8_t r;\r
- DDRB&=~(1<<PORTB0); //Eingang\r
- __asm__ __volatile__ ("nop");\r
- PORTB|=(1<<PORTB0); //Pullup\r
- __asm__ __volatile__ ("nop");\r
- __asm__ __volatile__ ("nop");\r
- __asm__ __volatile__ ("nop");\r
- __asm__ __volatile__ ("nop");\r
- __asm__ __volatile__ ("nop");\r
- r=PINB&(1<<PORTB0);\r
- __asm__ __volatile__ ("nop");\r
- PORTB&=~(1<<PORTB0);\r
- __asm__ __volatile__ ("nop");\r
- DDRB|=(1<<PORTB0); //Eingang\r
- return (r==0);\r
- \r
- \r
-}\r
+OWST_WDT_ISR\r
+OWST_TESTSW\r
\r
\r
typedef union {\r
return (double)ADC;\r
}\r
\r
-volatile int16_t am2302_temp;\r
-volatile uint16_t am2302_hum;\r
+volatile int16_t DS2438_2_TEMP;\r
+volatile uint16_t DS2438_2_VAD;\r
+volatile uint16_t DS2438_2_VDD=0x01F4;\r
\r
\r
-uint8_t userRegister[1];\r
-int16_t sRH,sT;\r
-volatile double temperatureC,humidityRH;\r
-volatile double l;\r
\r
-uint8_t max_adr=0;\r
+double temperatureC,humidityRH;\r
+double TC;\r
+double l;\r
\r
int main(void){\r
- //PRR|=(1<<PRADC); // adc for save Power\r
- pack1.temp=0x0550;\r
+ OWST_INIT_ALL_ON\r
+ pack1.temp=0x0550;\r
pack1.config=0x7F;\r
pack1.TH=75;\r
pack1.TL=70;\r
pack1.rr00=0;\r
pack1.rr10=0x10;\r
PORTA=0xFF-(1<<PINA1)-(1<<PINA2);\r
- PORTB=0xFF;\r
OWINIT();\r
\r
- MCUCR &=~(1<<PUD); //All Pins Pullup...\r
- MCUCR |=(1<<BODS);\r
+ OWST_EN_PULLUP\r
+ OWST_WDR_CONFIG1 \r
\r
- WDTCSR |= ((1<<WDCE) ); // Enable the WD Change Bit//| (1<<WDE)\r
- WDTCSR |= (1<<WDIE) | // Enable WDT Interrupt\r
- (1<<WDP2) | (1<<WDP1); // Set Timeout to ~1 seconds\r
if (testSW()) {\r
- config_info2[5]=8;\r
+ config_info2[5]=12;\r
}else{\r
config_info2[5]=7;\r
}\r
- MCUSR=0;\r
USI_TWI_Master_Initialise();\r
- SHT2x_SoftReset();\r
- SHT2x_ReadUserRegister(userRegister);\r
- //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;\r
- SHT2x_WriteUserRegister(userRegister); //write changed user reg\r
- // --- measure humidity with "Hold Master Mode (HM)" ---\r
- SHT2x_MeasurePoll(HUMIDITY, &sRH);\r
- // --- measure temperature with "Polling Mode" (no hold master) ---\r
- SHT2x_MeasurePoll(TEMP, &sT);\r
- //-- calculate humidity and temperature --\r
- //temperatureC = SHT2x_CalcTemperatureC(sT);\r
- //humidityRH = SHT2x_CalcRH(sRH);\r
- \r
+ initSHT2x();\r
+ \r
gcontrol=1;\r
+ for(uint8_t i=0;i<8;i++) pack2.page6[i]=owid1[i];\r
+ pack2.page3[0]=0xF1;\r
sei();\r
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);\r
//DDRB|=(1<<PINB1);\r
\r
if (wdcounter>0) {\r
if (par==0) {\r
- //PORTB|=(1<<PINB1); //Dauer 440ms\r
- SHT2x_MeasurePoll(HUMIDITY, &sRH);\r
- // --- measure temperature with "Polling Mode" (no hold master) ---\r
- SHT2x_MeasurePoll(TEMP, &sT);\r
- //-- calculate humidity and temperature --\r
- temperatureC = SHT2x_CalcTemperatureC(sT)*10.0-2;\r
- humidityRH = SHT2x_CalcRH(sRH)*10.0+5;\r
- if (humidityRH>1000) humidityRH=1000;\r
+ getSHT2xHumTemp(&temperatureC,&humidityRH);\r
+ double RH=humidityRH*10.0;\r
+ TC =temperatureC *10.0;\r
+\r
if (testSW()) {\r
- am2302_hum= humidityRH*10.0;\r
- am2302_temp=temperatureC*25.6;\r
- //\r
- config_info2[5]=8;\r
- }else{\r
- double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);\r
- //am2302_hum=0.318*hhum +76.0;\r
- am2302_hum=0.31*hhum +80;\r
- am2302_temp=temperatureC*25.6;\r
- //am2302_temp=am2302_temp-45;\r
+ DS2438_2_VAD=RH;\r
+ DS2438_2_TEMP=TC*25.6;\r
+ \r
+ config_info2[5]=12;\r
+ \r
+ }else{\r
+ \r
+ double hhum=(1.0546-0.000216*TC)*(RH);\r
+ DS2438_2_VAD=0.31*hhum +80;\r
+ DS2438_2_TEMP=TC*25.6;\r
config_info2[5]=7;\r
}\r
}\r
+ DS2438_2_VDD=0x01F4;\r
ares[par]=ADmess();\r
par++;\r
if (par>15) par=0;\r
wdcounter=0;\r
}\r
\r
- if (gcontrol==1) {\r
+ if ((gcontrol&1)==1) {\r
gcontrol=0;\r
sum=0;\r
for(uint8_t i=0;i<16;i++) {\r
sum+=ares[i];\r
}\r
- V=sum/20.0/1024.0*1.12*1000.0/16.0;//Spannung in mV\r
+ V=sum/20.0/1024.0*1.18*1000.0/16.0;//Spannung in mV\r
//V=sum/20.0/1024.0*1.01*1000.0/16.0;\r
int16_t htemp;\r
ktemp=gettemp_rs(V);\r
//htemp=(ktemp*16)/10;\r
- htemp=(ktemp*16+temperatureC*1.6)/10;\r
+ htemp=(ktemp*16+TC*1.6)/10;\r
\r
int16_t w=htemp;\r
int8_t t8=w>>4;\r