-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de\r
// All rights reserved.\r
//\r
// Redistribution and use in source and binary forms, with or without\r
#include <avr/wdt.h>\r
#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/TWI_Master.h"\r
+#include "../common/I2C/SHT2xV2.h"\r
#include "../common/I2C/BMP280.h"\r
#include "../common/calibr.h"\r
+#include "../common/owSlave_tools.h"\r
\r
-extern void OWINIT();\r
-extern void EXTERN_SLEEP();\r
+OWST_EXTERN_VARS\r
\r
\r
uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/\r
uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/\r
-uint8_t config_info1[16]={0x02,0x03, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; \r
-uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,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=3;\r
\r
+uint8_t config_info1[26]={0x02,0x03, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x02,14,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 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
\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
+OWST_WDT_ISR\r
\r
typedef union {\r
volatile uint8_t bytes[8];\r
\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
+OWST_TESTSW\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
\r
uint8_t userRegister[1];\r
int16_t sRH,sT;\r
-volatile double temperatureC,humidityRH;\r
+double temperatureC,humidityRH;\r
volatile double l;\r
uint32_t P;\r
int32_t t;\r
\r
int main(void){\r
- PRR|=(1<<PRADC); // adc for save Power\r
- PORTA=0xFF;\r
- PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom\r
- DDRB|=(1<<PORTB0); //Als Ausgang und 0\r
- \r
+ OWST_INIT_USI_ON\r
+ \r
pack1.temp=0x0550;\r
pack1.config=0x7F;\r
pack1.TH=75;\r
PORTA=0xFF;\r
PORTB=0xFF;\r
OWINIT();\r
+ OWST_EN_PULLUP\r
\r
- ACSR|=(1<<ACD); //Disable Comparator\r
- ADCSRB|=(1<<ACME); //Disable Analog multiplexer\r
- MCUCR &=~(1<<PUD); //All Pins Pullup...\r
- //MCUCR &=~(1<<BODS);\r
-\r
+ OWST_WDR_CONFIG8\r
\r
- WDTCSR |= ((1<<WDCE) ); // Enable the WD Change Bit//| (1<<WDE)\r
- WDTCSR |= (1<<WDIE) | // Enable WDT Interrupt\r
- (1<<WDP3) | (1<<WDP0); // Set Timeout to ~8 seconds\r
if (testSW()) {\r
- config_info2[5]=8;\r
+ config_info2[5]=12;\r
}else{\r
config_info2[5]=7;\r
}\r
- \r
+ pack2.page3[0]=0xF1;\r
\r
MCUSR=0;\r
- USI_TWI_Master_Initialise();\r
+ TWI_Master_Initialise();\r
\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
+ initSHT2x();\r
+ _delay_ms(10);\r
bmp280Init();\r
gcontrol=1;\r
sei();\r
while(1) {\r
+ \r
if (gcontrol) {\r
- wdcounter=3;\r
+ wdcounter=2;\r
\r
}\r
\r
if (wdcounter>2) {\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
- humidityRH=calibr_hum(temperatureC,-0.45,humidityRH)*10.0;\r
- temperatureC=temperatureC*10.0-4.5;\r
+ getSHT2xHumTemp(&temperatureC,&humidityRH);\r
+ double RH=calibr_hum(temperatureC,-0.2,humidityRH)*10.0;\r
+ double TC =temperatureC *10.0-2;\r
+\r
if (testSW()) {\r
- am2302_hum= humidityRH*10.0;\r
- am2302_temp=temperatureC*25.6;\r
+ DS2438_2_VAD=RH;\r
+ DS2438_2_TEMP=(double)TC*25.6;\r
//am2302_temp=am2302_temp-20;\r
- config_info2[5]=8;\r
+ config_info2[5]=12;\r
+ DS2438_2_VDD=0x01F4;\r
\r
}else{\r
\r
- double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);\r
+ double hhum=(1.0546-0.000216*TC)*(RH);\r
//am2302_hum=0.318*hhum +76.0;\r
- am2302_hum=0.31*hhum +80;\r
- am2302_temp=temperatureC*25.6;\r
+ DS2438_2_VAD=0.31*hhum +80;\r
+ DS2438_2_TEMP=TC*25.6;\r
//am2302_temp=am2302_temp-20;\r
config_info2[5]=7;\r
+ DS2438_2_VDD=0x01F4;\r
}\r
wdcounter=0;\r
}\r
\r
}\r
\r
- \r
-#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)\r
- if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))\r
-#endif \r
-#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__)\r
- if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))\r
-#endif\r
- {\r
-\r
- MCUCR|=(1<<SE)|(1<<SM1);\r
- MCUCR&=~(1<<ISC01);\r
- } else {\r
- MCUCR|=(1<<SE);\r
- MCUCR&=~(1<<SM1);\r
- }\r
- //MCUCR&=~(1<<ISC01);\r
- asm("SLEEP");\r
+ OWST_MAIN_END \r
}\r
\r
\r