- New Device compinations
authorTobias <tm@tm3d.de>
Tue, 9 Feb 2016 18:52:22 +0000 (19:52 +0100)
committerTobias <tm@tm3d.de>
Tue, 9 Feb 2016 18:52:22 +0000 (19:52 +0100)
- ASM-files for Device in common. Only in C files are the specific function

18 files changed:
DS18B20_BMP280_DS2438_SHT/DS18B20_DS2438.c
DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c
DS2423/DS2423.cproj
DS2423_BMP280/DS2423_BMP280.atsln [new file with mode: 0644]
DS2423_BMP280/DS2423_BMP280.c [new file with mode: 0644]
DS2423_BMP280/DS2423_BMP280.cproj [new file with mode: 0644]
DS2438_DHT22/DS2438_DHT22.atsln
DS2438_DHT22/DS2438_DHT22.c
DS2438_DHT22/DS2438_DHT22.cproj
DS2438_SHT2X/DS2438_SHT2X.atsln [new file with mode: 0644]
DS2438_SHT2X/DS2438_SHT2X.c [new file with mode: 0644]
DS2438_SHT2X/DS2438_SHT2X.cproj [new file with mode: 0644]
DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.atsln [new file with mode: 0644]
DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.c [new file with mode: 0644]
DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.cproj [new file with mode: 0644]
DS2450_SHT2X_BMP280_MAX44009/OWDS2450.S [new file with mode: 0644]
common/OWDS2423.S [new file with mode: 0644]
common/OWDS2438.S [new file with mode: 0644]

index 5b98b1c..b4b62d0 100644 (file)
@@ -59,7 +59,7 @@ extern uint8_t mode;
 extern uint8_t gcontrol;
 extern uint8_t reset_indicator;
 extern uint8_t alarmflag;
-volatile uint8_t wdcounter;
+volatile uint8_t wdcounter=3;
 
 
 #if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
@@ -133,6 +133,26 @@ volatile int16_t am2302_temp;
 volatile uint16_t am2302_hum;
 
 
+int testSW(void) {
+       uint8_t r;
+       DDRB&=~(1<<PORTB0);  //Eingang
+       __asm__ __volatile__ ("nop");
+       PORTB|=(1<<PORTB0); //Pullup
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       r=PINB&(1<<PORTB0);
+       __asm__ __volatile__ ("nop");
+       PORTB&=~(1<<PORTB0);
+       __asm__ __volatile__ ("nop");
+       DDRB|=(1<<PORTB0);  //Eingang
+       return (r==0);
+       
+       
+}
+
 uint8_t userRegister[1];
 int16_t sRH,sT;
 volatile double temperatureC,humidityRH;
@@ -142,6 +162,10 @@ volatile double l;
 
 int main(void){
     PRR|=(1<<PRADC);  // adc for save Power
+       PORTA=0xFF;
+       PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
+       DDRB|=(1<<PORTB0); //Als Ausgang und 0
+       
        pack1.temp=0x0550;
        pack1.config=0x7F;
        pack1.TH=75;
@@ -153,12 +177,21 @@ int main(void){
        PORTB=0xFF;
        OWINIT();
 
+       ACSR|=(1<<ACD);  //Disable Comparator
+       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
        MCUCR &=~(1<<PUD); //All Pins Pullup...
        MCUCR |=(1<<BODS);
 
+       
        WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
        WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~1 seconds
+       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds
+       if (testSW()) {
+               config_info2[5]=8;
+               }else{
+               config_info2[5]=7;
+       }
+       
 
        MCUSR=0;
        USI_TWI_Master_Initialise();
@@ -178,7 +211,11 @@ int main(void){
        gcontrol=1;
        sei();
     while(1)   {
-               if (wdcounter>0) {
+               if ((gcontrol==2)||(gcontrol==3)) {
+                       wdcounter=3;
+                       gcontrol=0;
+               }               
+               if (wdcounter>3) {
                        SHT2x_MeasurePoll(HUMIDITY, &sRH);
                        // --- measure temperature with "Polling Mode" (no hold master) ---
                        SHT2x_MeasurePoll(TEMP, &sT);
@@ -208,10 +245,7 @@ int main(void){
                                sei();
                                EXTERN_SLEEP(); 
                }
-               if ((gcontrol==2)||(gcontrol==3)) {
-                       gcontrol=0;
-                       
-               }
+               
 
                
 #if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
index d455f89..5a0094e 100644 (file)
@@ -190,6 +190,7 @@ uint8_t cmode=0;
 double R0=0;
 int16_t hr;
 uint8_t startup=5;
+uint8_t reset_R0=0;
 
 int main(void){
     PRR|=(1<<PRADC);  // adc for save Power
@@ -261,9 +262,32 @@ int main(void){
        sei();
        //DDRB|=(1<<PINB1);
     while(1)   {
+               if (pack1.config==0x1F) {
+                       if (reset_R0==0) {
+                               reset_R0=1;
+                               pack1.config=0x7F;
+                               R0=0;
+                               hr=R0*100;
+                               pack2.page3[0]=hr&0xFF;
+                               pack2.page3[1]=(hr>>8)&0xFF;
+                               
+                               while(EECR & (1<<EEPE));
+                               EECR = (0<<EEPM1)|(0<<EEPM0);
+                               EEARL = 0;
+                               EEDR = hr&0xFF;
+                               EECR |= (1<<EEMPE);
+                               EECR |= (1<<EEPE);
+                               while(EECR & (1<<EEPE));
+                               EECR = (0<<EEPM1)|(0<<EEPM0);
+                               EEARL = 1;
+                               EEDR = hr>>8;
+                               EECR |= (1<<EEMPE);
+                               EECR |= (1<<EEPE);
+
+                       }
+               } else reset_R0=0;                      //PORTB|=(1<<PINB1); //Dauer 440ms
                if (wdcounter>0) {
                        if (startup!=0) startup--;
-                       //PORTB|=(1<<PINB1); //Dauer 440ms
                        SHT2x_MeasurePoll(HUMIDITY, &sRH);
                        // --- measure temperature with "Polling Mode" (no hold master) ---
                        SHT2x_MeasurePoll(TEMP, &sT);
@@ -310,7 +334,8 @@ int main(void){
                        pack2.page3[6]=(hr>>8)&0xFF;
                        
                        l=l/ip;
-                       if (startup!=0){
+                       
+                       if (startup==0){
                        if (l>R0) {
                                R0=l;
                                hr=R0*100;
@@ -334,7 +359,7 @@ int main(void){
                        }
                         l=l/R0;
                        l=log(1/l);
-                       l=l*160; //fuer DS18B20
+                       l=l*160*4; //fuer DS18B20
                        wdcounter=0;
                        
                }
index 24adaf9..d86cc1e 100644 (file)
@@ -2,7 +2,7 @@
 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>6.2</ProjectVersion>
+    <ProjectVersion>7.0</ProjectVersion>
     <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
     <ProjectGuid>{26106a5a-6618-4774-943f-65c46ddb610b}</ProjectGuid>
     <avrdevice>ATtiny84A</avrdevice>
       <ToolName>Atmel-ICE</ToolName>
     </com_atmel_avrdbg_tool_atmelice>
     <avrtoolinterface>debugWIRE</avrtoolinterface>
+    <ExternalProgrammingToolCommand />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
     <ToolchainSettings>
       <AvrGcc>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>NDEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-      </AvrGcc>
+  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+  <avrgcc.compiler.symbols.DefSymbols>
+    <ListValues>
+      <Value>DEBUG</Value>
+    </ListValues>
+  </avrgcc.compiler.symbols.DefSymbols>
+  <avrgcc.compiler.directories.IncludePaths>
+    <ListValues>
+      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+    </ListValues>
+  </avrgcc.compiler.directories.IncludePaths>
+  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
+  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+  <avrgcc.linker.libraries.Libraries>
+    <ListValues>
+      <Value>libm</Value>
+    </ListValues>
+  </avrgcc.linker.libraries.Libraries>
+  <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+</AvrGcc>
     </ToolchainSettings>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
     <ToolchainSettings>
       <AvrGcc>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
+  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+  <avrgcc.compiler.symbols.DefSymbols>
+    <ListValues>
+      <Value>DEBUG</Value>
+    </ListValues>
+  </avrgcc.compiler.symbols.DefSymbols>
+  <avrgcc.compiler.directories.IncludePaths>
+    <ListValues>
+      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+    </ListValues>
+  </avrgcc.compiler.directories.IncludePaths>
+  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
+  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+  <avrgcc.linker.libraries.Libraries>
+    <ListValues>
+      <Value>libm</Value>
+    </ListValues>
+  </avrgcc.linker.libraries.Libraries>
+  <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+</AvrGcc>
     </ToolchainSettings>
   </PropertyGroup>
   <ItemGroup>
diff --git a/DS2423_BMP280/DS2423_BMP280.atsln b/DS2423_BMP280/DS2423_BMP280.atsln
new file mode 100644 (file)
index 0000000..3b8bc1f
--- /dev/null
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Atmel Studio Solution File, Format Version 11.00
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2423_BMP280", "DS2423_BMP280.cproj", "{26106A5A-6618-4774-943F-65C46DDB610B}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|AVR = Debug|AVR
+               Release|AVR = Release|AVR
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.ActiveCfg = Debug|AVR
+               {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.Build.0 = Debug|AVR
+               {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.ActiveCfg = Release|AVR
+               {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.Build.0 = Release|AVR
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/DS2423_BMP280/DS2423_BMP280.c b/DS2423_BMP280/DS2423_BMP280.c
new file mode 100644 (file)
index 0000000..8ec5432
--- /dev/null
@@ -0,0 +1,164 @@
+
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//  * Redistributions of source code must retain the above copyright
+//    notice, this list of conditions and the following disclaimer.
+//  * Redistributions in binary form must reproduce the above copyright
+//    notice, this list of conditions and the following disclaimer in the
+//    documentation and/or other materials provided with the
+//    distribution.
+//  * All advertising materials mentioning features or use of this
+//    software must display the following acknowledgement: This product
+//    includes software developed by tm3d.de and its contributors.
+//  * Neither the name of tm3d.de nor the names of its contributors may
+//    be used to endorse or promote products derived from this software
+//    without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#define _4_COUNTERS_
+#define _EEPROM_SAVE_
+//#define _CPULLUP_
+
+#define F_CPU 8000000UL
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include <avr/wdt.h>
+#include <avr/sleep.h>
+#include "../common/I2C/USI_TWI_Master.h"
+#include "../common/I2C/BMP280.h"
+
+
+
+extern void OWINIT();
+extern void EXTERN_SLEEP();
+
+uint8_t owid[8]={0x1D, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x5C};/**/
+uint8_t config_info[16]={0x09,0x0D,0x09,0x0D,0x01,0x08,0x02,0x08,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+
+       
+
+extern volatile uint8_t mode;
+extern uint8_t gcontrol;
+extern uint8_t reset_indicator;
+
+
+volatile uint8_t wdcounter;
+
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
+ISR(WATCHDOG_vect) {
+#else
+ISR(WDT_vect) {
+#endif 
+       wdcounter++;
+       //if (reset_indicator==1) reset_indicator++;
+       //else if (reset_indicator==2) mode=0;
+}
+
+
+typedef union {
+       volatile uint8_t bytes[45];
+       struct {
+               uint16_t addr;
+               uint8_t status;
+               uint8_t scratch[32];//3
+               uint32_t counter;  //35
+               uint32_t zero;   //39
+               uint16_t crc;  //43
+       };
+} counterpack_t;
+counterpack_t pack;
+
+volatile uint8_t lastcps;
+typedef union {
+       uint32_t c32[4];
+       uint8_t c8[16];
+} counters_t;
+
+volatile counters_t counters;
+
+volatile uint8_t istat;
+
+
+volatile uint8_t wdcounter;
+
+int main(void){
+     PRR|=(1<<PRADC);  // adc for save Power
+     PORTA=0xFF;
+     PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
+     DDRB|=(1<<PORTB0); //Als Ausgang und 0
+     
+     
+     OWINIT();
+
+     ACSR|=(1<<ACD);  //Disable Comparator
+     ADCSRB|=(1<<ACME); //Disable Analog multiplexer
+     MCUCR &=~(1<<PUD); //All Pins Pullup...
+     MCUCR |=(1<<BODS);
+
+     
+     WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
+     WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
+     (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds
+        
+        
+       pack.zero=0;
+       counters.c32[0]=0;
+       counters.c32[2]=0;
+       counters.c32[1]=0;
+       counters.c32[3]=0;
+       ACSR|=(1<<ACD);  //Disable Comparator
+       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
+       MCUCR &=~(1<<PUD); //All Pins Pullup...
+       
+       USI_TWI_Master_Initialise();
+       bmp280Init();   
+
+       uint32_t P;
+       int32_t t;
+       bmp280ConvertInt(&t,&P,1);
+       _delay_ms(200);
+       bmp280ConvertInt(&t,&P,1);
+       counters.c32[3]=P;
+       counters.c32[2]=t;
+       wdcounter=100;
+       sei();
+    while(1)   {
+               
+               if (wdcounter>2) {
+                       bmp280ConvertInt(&t,&P,1);
+                       while (mode!=0) ;
+                       cli();
+                       counters.c32[3]=P;
+                       counters.c32[2]=t;
+                       sei();
+                       
+                       wdcounter=0;
+               }
+
+               if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))       {
+                       MCUCR|=(1<<SE)|(1<<SM1);
+                       MCUCR&=~(1<<ISC01);
+               } else {
+                       MCUCR|=(1<<SE);
+                       MCUCR&=~(1<<SM1);
+               }
+               asm("SLEEP");
+   }
+}
\ No newline at end of file
diff --git a/DS2423_BMP280/DS2423_BMP280.cproj b/DS2423_BMP280/DS2423_BMP280.cproj
new file mode 100644 (file)
index 0000000..d6305a2
--- /dev/null
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectVersion>7.0</ProjectVersion>
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
+    <ProjectGuid>{26106a5a-6618-4774-943f-65c46ddb610b}</ProjectGuid>
+    <avrdevice>ATtiny84A</avrdevice>
+    <avrdeviceseries>none</avrdeviceseries>
+    <OutputType>Executable</OutputType>
+    <Language>C</Language>
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
+    <OutputFileExtension>.elf</OutputFileExtension>
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
+    <AssemblyName>DS2423_BMP280</AssemblyName>
+    <Name>DS2423_BMP280</Name>
+    <RootNamespace>DS2423_BMP280</RootNamespace>
+    <ToolchainFlavour>Native</ToolchainFlavour>
+    <KeepTimersRunning>true</KeepTimersRunning>
+    <OverrideVtor>false</OverrideVtor>
+    <CacheFlash>true</CacheFlash>
+    <ProgFlashFromRam>true</ProgFlashFromRam>
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>
+    <UncachedRange />
+    <preserveEEPROM>true</preserveEEPROM>
+    <OverrideVtorValue>exception_table</OverrideVtorValue>
+    <BootSegment>2</BootSegment>
+    <eraseonlaunchrule>1</eraseonlaunchrule>
+    <AsfFrameworkConfig>
+      <framework-data xmlns="">
+        <options />
+        <configurations />
+        <files />
+        <documentation help="" />
+        <offline-documentation help="" />
+        <dependencies>
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.22.0" />
+        </dependencies>
+      </framework-data>
+    </AsfFrameworkConfig>
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
+    <com_atmel_avrdbg_tool_atmelice>
+      <ToolOptions>
+        <InterfaceProperties>
+        </InterfaceProperties>
+        <InterfaceName>debugWIRE</InterfaceName>
+      </ToolOptions>
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
+      <ToolNumber>J41800024445</ToolNumber>
+      <ToolName>Atmel-ICE</ToolName>
+    </com_atmel_avrdbg_tool_atmelice>
+    <avrtoolinterface>debugWIRE</avrtoolinterface>
+    <ExternalProgrammingToolCommand />
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
+    <ToolchainSettings>
+      <AvrGcc>
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+        <avrgcc.compiler.symbols.DefSymbols>
+          <ListValues>
+            <Value>DEBUG</Value>
+          </ListValues>
+        </avrgcc.compiler.symbols.DefSymbols>
+        <avrgcc.compiler.directories.IncludePaths>
+          <ListValues>
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+          </ListValues>
+        </avrgcc.compiler.directories.IncludePaths>
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+        <avrgcc.linker.libraries.Libraries>
+          <ListValues>
+            <Value>libm</Value>
+          </ListValues>
+        </avrgcc.linker.libraries.Libraries>
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+      </AvrGcc>
+    </ToolchainSettings>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+    <ToolchainSettings>
+      <AvrGcc>
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+        <avrgcc.compiler.symbols.DefSymbols>
+          <ListValues>
+            <Value>DEBUG</Value>
+          </ListValues>
+        </avrgcc.compiler.symbols.DefSymbols>
+        <avrgcc.compiler.directories.IncludePaths>
+          <ListValues>
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+          </ListValues>
+        </avrgcc.compiler.directories.IncludePaths>
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+        <avrgcc.linker.libraries.Libraries>
+          <ListValues>
+            <Value>libm</Value>
+          </ListValues>
+        </avrgcc.linker.libraries.Libraries>
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+      </AvrGcc>
+    </ToolchainSettings>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\BMP280.c">
+      <SubType>compile</SubType>
+      <Link>BMP280.c</Link>
+    </Compile>
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
+      <SubType>compile</SubType>
+      <Link>USI_TWI_Master.c</Link>
+    </Compile>
+    <Compile Include="D:\oc\dev\owSlave2\common\OWDS2423.S">
+      <SubType>compile</SubType>
+      <Link>OWDS2423.S</Link>
+    </Compile>
+    <Compile Include="DS2423_BMP280.c">
+      <SubType>compile</SubType>
+    </Compile>
+  </ItemGroup>
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+</Project>
\ No newline at end of file
index 77e7763..1c780e5 100644 (file)
@@ -1,7 +1,9 @@
 
-Microsoft Visual Studio Solution File, Format Version 11.00
+Microsoft Visual Studio Solution File, Format Version 12.00
 # Atmel Studio Solution File, Format Version 11.00
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2438_DHT22", "DS2438_DHT22.cproj", "{91468D4F-8AE2-4C59-8A35-549C49E00934}"
+VisualStudioVersion = 14.0.23107.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2438_DHT22", "DS2438_DHT22.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
 EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -9,10 +11,10 @@ Global
                Release|AVR = Release|AVR
        EndGlobalSection
        GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.ActiveCfg = Debug|AVR
-               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.Build.0 = Debug|AVR
-               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.ActiveCfg = Release|AVR
-               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.Build.0 = Release|AVR
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
index 6d4a5a0..a182bed 100644 (file)
 
 
 #define F_CPU 8000000UL
-//#define FP_CALC
 #include <avr/io.h>
 #include <avr/interrupt.h>
 #include <util/delay.h>
 #include <avr/wdt.h>
 #include <avr/sleep.h>
+#include <avr/pgmspace.h>
 
-extern void OWINIT();
 
+extern void OWINIT();
+extern void EXTERN_SLEEP();
 
-uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0x00, 0x00, 0x05, 0x16};/**/
+uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0xDD, 0xDD, 0x05, 0xCE};/**/
 uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-       
+
+
 
 extern uint8_t mode;
 extern uint8_t gcontrol;
@@ -55,11 +57,8 @@ volatile uint8_t wdcounter;
 
 
 typedef union {
-#if  defined(__AVR_ATtiny25__)
-       volatile uint8_t bytes[16];
-#else
+
        volatile uint8_t bytes[64];
-#endif
        struct {
                uint8_t status;  //1
                int16_t temp;  //2
@@ -68,8 +67,6 @@ typedef union {
                uint8_t threshold; //8
                
                uint8_t page1[8]; //9
-#if  defined(__AVR_ATtiny25__)
-#else
                uint8_t page2[8]; //17
                uint8_t page3[8]; //25
                uint8_t page4[8];  //33
@@ -77,27 +74,15 @@ typedef union {
                uint8_t page6[8];  //49
                uint8_t page7[8];  //57
                //uint8_t crc;  //65
-#endif
        };
 } pack_t;
 volatile pack_t pack;
 
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-
-#define DDR_SENSOR   DDRB 
-#define PORT_SENSOR  PORTB
-#define PIN_SENSOR   PINB
-#define SENSOR       PB4
-#endif
 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
 #define DDR_SENSOR   DDRA
 #define PORT_SENSOR  PORTA
 #define PIN_SENSOR   PINA
 #define SENSOR       PINA2
-#endif
-
-
 
 #define SENSOR_sda_out         DDR_SENSOR |= (1 << SENSOR)
 #define SENSOR_sda_in                  DDR_SENSOR &= ~(1 << SENSOR);PORT_SENSOR |= (1 << SENSOR) // release sda => hi in consequence of pullup
@@ -112,53 +97,64 @@ volatile uint16_t am2302_hum;
 uint8_t am_wait(uint8_t _time,uint8_t _signal){
        TCNT1=0;
        while(TCNT1==0);
-       if (_signal) 
-               while((SENSOR_is_hi)&&(TCNT1<_time)) {}
+       if (_signal)
+       while((SENSOR_is_hi)&&(TCNT1<_time)) {}
        else
-               while((SENSOR_is_low)&&(TCNT1<_time)) {}
-        
-               if (TCNT1>=_time) {return 1;}
+       while((SENSOR_is_low)&&(TCNT1<_time)) {}
+       
+       if (TCNT1>=_time) {return 1;}
        return 0;
 }
 
-volatile uint8_t am2302_mode=0;        
+volatile uint8_t am2302_mode=0;
 volatile uint8_t timeout=0;
 
 
 
+
+
+
+uint8_t userRegister[1];
+int16_t sRH,sT;
+volatile 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__)
 ISR(WATCHDOG_vect) {
-#else
+       #else
 ISR(WDT_vect) {
-#endif 
-       sleep_disable();          // Disable Sleep on Wakeup
-       am2302_mode++;
+       #endif
+       wdcounter++;
        if (reset_indicator==1) reset_indicator++;
        else if (reset_indicator==2) mode=0;
-/*     if (timeout==2) {
-               DIS_TIMER;
-               EN_OWINT;
-               mode=OWM_SLEEP;
-       }
-       timeout++;*/
-       sleep_enable();           // Enable Sleep Mode
-
 }
-
-       
        
-uint8_t am2302_1() {
+int testSW(void) {
+       uint8_t r;
+       DDRB&=~(1<<PORTB0);  //Eingang
+       __asm__ __volatile__ ("nop");
+       PORTB|=(1<<PORTB0); //Pullup
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       r=PINB&(1<<PORTB0);
+       __asm__ __volatile__ ("nop");
+       PORTB&=~(1<<PORTB0);
+       __asm__ __volatile__ ("nop");
+       DDRB|=(1<<PORTB0);  //Eingang
+       return (r==0);
+}
+
+uint8_t am2302() {
        int16_t lam2302_temp;
        uint16_t lam2302_hum;
        uint8_t rSREG;
        uint8_t sensor_data[5];
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-       TCCR1=(1<<CS12); //Clock/8 1µs
-#endif
 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
        TCCR1B=(1<<CS11); //Clock/8 1µs
-#endif
+
        SENSOR_sda_out;
        SENSOR_sda_low; // MCU start signal
        TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)
@@ -166,7 +162,7 @@ uint8_t am2302_1() {
        SENSOR_sda_in;
        if (am_wait(200,1)) return 2;
 
-       // AM2302 response signal min: 75us typ:80us max:85us
+       // AM2302 response signal min: 75us typ:80us max:85us or 500us different types
        if (am_wait(100,0)) return 3;
        if (am_wait(100,1)) return 4;
        
@@ -188,40 +184,28 @@ uint8_t am2302_1() {
        // checksum
        if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4])
        {
-               // debug output
-               //printf("%b %b %b %b %b %b" CR, sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4], ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ));
                PORTB&=~(1<<PINB0);
                return 7;
        }
-#ifdef FP_CALC
-       double htemp;
-       if (sensor_data[2]&0x80) { //min
-               sensor_data[2]&=~(0x80);
-               htemp=-((sensor_data[2]<<8) + sensor_data[3]);
-       } else
-               htemp=((sensor_data[2]<<8) + sensor_data[3]);
-       double hhum=(1.0546-0.000216*htemp)*((sensor_data[0]<<8) + sensor_data[1]);
-       
-       lam2302_hum=0.318*hhum +76;
-       lam2302_temp=htemp*25.6;
-#else
-
        if (sensor_data[2]&0x80) { //minus
                sensor_data[2]&=~(0x80);
                lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3]);
        } else
                lam2302_temp=((sensor_data[2]<<8) + sensor_data[3]);
-       
-       lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);
-       volatile uint32_t h1=lam2302_temp*lam2302_hum*3/44803;
-       lam2302_hum=lam2302_hum*16/49-h1+80;
-       //lam2302_temp=lam2302_temp*128/5;
-
-       int16_t h2=lam2302_temp%5;
-       lam2302_temp=lam2302_temp/5;
-       lam2302_temp*=128;
-       lam2302_temp+=h2*128/5;
-#endif    
+       if (!testSW()) {
+               double htemp=lam2302_temp;
+        double hhum=(1.0546-0.000216*htemp)*((sensor_data[0]<<8) + sensor_data[1]);
+               //htemp=Temperauter * 10 
+               //lam2302_hum=0.318*hhum +76;
+               lam2302_hum=0.31*hhum +80; //hhum = Hum*10 -> 5V also all *5
+               config_info[5]=7;
+       }
+       else {
+               
+               lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);
+               config_info[5]=12;
+       }
+       lam2302_temp=lam2302_temp*25.6;
        rSREG=SREG;
        cli();
        am2302_hum=lam2302_hum;
@@ -231,179 +215,87 @@ uint8_t am2302_1() {
 }
 
 
-uint8_t am2302_2() { //4mhz
-       int16_t lam2302_temp;
-       uint16_t lam2302_hum;
-       uint8_t rSREG;
-       uint8_t sensor_data[5];
-       #if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-       TCCR1=(1<<CS11)|(1<<CS10); //Clock/8 1µs
-       #endif
-
-       #if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-       TCCR1B=(1<<CS11); //Clock/8 1µs
-       #endif
-       SENSOR_sda_out;
-       SENSOR_sda_low; // MCU start signal
-       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)
-       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)
-       SENSOR_sda_in;
-       if (am_wait(200,1)) return 2;
-
-       // AM2302 response signal min: 75us typ:80us max:85us
-       if (am_wait(100,0)) return 3;
-       if (am_wait(100,1)) return 4;
-       
-       for(uint8_t i = 0; i < 5; i++)  {
-               uint8_t sensor_byte = 0;
-               for(uint8_t j = 1; j <= 8; j++) {// get 8 bits from sensor
-                       if (am_wait(88,0)) return 5;
-                       
-                       TCNT1=0;while(TCNT1==0);;while(TCNT1<35)                ;
-                       sensor_byte <<= 1; // add new lower byte
-                       if (SENSOR_is_hi) {// if sda high after 30us => bit=1 else bit=0
-                               sensor_byte |= 1;
-                               if (am_wait(45,1)) return 6;// 30us - 75us = 45us
-                       }
-               }
-               sensor_data[i] = sensor_byte;
-       }
-
-       // checksum
-       if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4])
-       {
-               // debug output
-               //printf("%b %b %b %b %b %b" CR, sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4], ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ));
-               PORTB&=~(1<<PINB0);
-               return 7;
-       }
-#ifdef FP_CALC
-       lam2302_hum=0.318* ((sensor_data[0]<<8) + sensor_data[1])+76;
-       if (sensor_data[2]&0x80) { //minus
-               sensor_data[2]&=~(0x80);
-               lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3])*25.6;
-       } else
-               lam2302_temp=((sensor_data[2]<<8) + sensor_data[3])*25.6;
-#else
 
 
-       if (sensor_data[2]&0x80) { //minus
-               sensor_data[2]&=~(0x80);
-               lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3]);
-       } else
-       lam2302_temp=((sensor_data[2]<<8) + sensor_data[3]);
-       
-       lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);
-       volatile uint32_t h1=lam2302_temp*lam2302_hum*3/44803;
-       lam2302_hum=lam2302_hum*16/49-h1+80;
-       //lam2302_temp=lam2302_temp*128/5;
-
-       int16_t h2=lam2302_temp%5;
-       lam2302_temp=lam2302_temp/5;
-       lam2302_temp*=128;
-       lam2302_temp+=h2*128/5;
-#endif 
-       
-       
-       rSREG=SREG;
-       cli();
-       am2302_hum=lam2302_hum;
-       am2302_temp=lam2302_temp;
-       SREG=rSREG;
-       return 0;
-}
 
 
-int main(void){
-    PRR|=(1<<PRUSI)|(1<<PRADC);  //Switch off usi and adc for save Power
-       
-       OWINIT();
 
-       ACSR|=(1<<ACD);  //Disable Comparator
-       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-       MCUCR &=~(1<<PUD);
-       
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
 
-       PORTB|=(1<<PINB0)|(1<<PINB1)|(1<<PINB3)|(1<<PINB4)|(1<<PINB5);
-       DDRB|=(1<<PINB1); //DBLINE
-#define SENSON PORTB|=(1<<PINB0);
-#define SENSOFF PORTB&=~(1<<PINB0);
-       DDRB|=(1<<PINB0); //stromversorgung
-       
-       // Set up Watch Dog Timer for Inactivity
-       WDTCR |= ((1<<WDCE) | (1<<WDE));   // Enable the WD Change Bit
-       WDTCR =   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~2 seconds
-#endif
+       int main(void){
+               PRR|=(1<<PRUSI)|(1<<PRADC);   // adc and usi for save Power
+               PORTA=0xFF;
+               PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
+               DDRB|=(1<<PORTB0); //Als Ausgang und 0
+               
+               
+               OWINIT();
 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
+               ACSR|=(1<<ACD);  //Disable Comparator
+               ADCSRB|=(1<<ACME); //Disable Analog multiplexer
+               MCUCR &=~(1<<PUD); //All Pins Pullup...
+               MCUCR |=(1<<BODS);
 
-       //PORTB|=(1<<PINB0)|(1<<PINB1)|(1<<PINB3)|(1<<PINB4)|(1<<PINB5);
-       //DDRA|=(1<<PINB1);
-       DDRA|=(1<<PINA1); //stromversorgung
+               
+               DDRA|=(1<<PINA1); //stromversorgung
 #define SENSON PORTA|=(1<<PINA1);
 #define SENSOFF PORTA&=~(1<<PINA1);
 
-       // Set up Watch Dog Timer for Inactivity
-//     WDTCSR |= (1<<WDCE) ;   // Enable the WD Change Bit
-//     WDTCSR =   (1<<WDIE) |              // Enable WDT Interrupt
-//     (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~2 seconds
-#endif
+               // Set up Watch Dog Timer for Inactivity
+               WDTCSR |= (1<<WDCE) ;   // Enable the WD Change Bit
+               WDTCSR =   (1<<WDIE) |              // Enable WDT Interrupt
+                       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~2 seconds           
+               
+               if (testSW()) {
+                       config_info[5]=12;  //hum *10
+                       }else{
+                       config_info[5]=7; //HIH4031
+               }
+               
+               uint8_t i;
+               for(i=0;i<64;i++) pack.bytes[i]=0;
+               MCUSR=0;
+               
+               uint8_t err;
+               uint8_t pn=1;
+               SENSON
+               _delay_ms(4000);
+               err =am2302();
+               
+               sei();
+               
+               while(1)   {
+                       if (gcontrol) {
+                               if (wdcounter>2) {
+                                       wdcounter=0;
+                                       SENSON
+                               }
+                               gcontrol=0;
+                       }
+                       if (wdcounter==2) {
+                               err=am2302();
+                               if (err!=0) {
+                                       pack.page3[pn]=err;
+                                       pn=pn+1;if (pn>31) pn=1;
+                               }
+                               SENSOFF
+                               wdcounter=3;
+                       }
+                       if (wdcounter>=16) {
+                               wdcounter=0;
+                               SENSON
+                       }
+                       
+                       
 
-       
-    uint8_t i;
-       uint8_t err;
-#if  defined(__AVR_ATtiny25__)
-    for(i=0;i<16;i++) pack.bytes[i]=0;
-#else
-       uint8_t pn=1;
-    for(i=0;i<64;i++) pack.bytes[i]=0;
-#endif
-       //pack.bytes[0]=1;
-       //pack.bytes[1]=2;
-       SENSON
-       _delay_ms(4000);
-       err =am2302_1();
-       sei();
-    while(1)   {
-               alarmflag=1;
-               if (am2302_mode==2) {
-                       err=am2302_1();
-                       if (err!=0) {
-#if  defined(__AVR_ATtiny25__)
-#else
-                               pack.page3[pn]=err;
-                               pn=pn+1;if (pn>31) pn=1;
-#endif
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))       {
+                               MCUCR|=(1<<SE)|(1<<SM1);
+                               MCUCR&=~(1<<ISC01);
+                               } else {
+                               MCUCR|=(1<<SE);
+                               MCUCR&=~(1<<SM1);
                        }
-                       SENSOFF
-                       am2302_mode=3;
-               }
-               if (am2302_mode>=8) {
-                       am2302_mode=0;
-                       SENSON
-               }
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
-#endif                 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
-#endif
-                         {
-//                     CLKPR=(1<<CLKPCE);
-       //              CLKPR=(1<<CLKPS2); /*0.5Mhz*/
-                       //PORTB&=~(1<<PINB1);
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
+                       asm("SLEEP");
                }
-               asm("SLEEP");
-   }
 
 
-}
\ No newline at end of file
+       }
\ No newline at end of file
index cc45178..3fadddd 100644 (file)
@@ -1,10 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
   <PropertyGroup>
     <SchemaVersion>2.0</SchemaVersion>
     <ProjectVersion>7.0</ProjectVersion>
     <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>{91468d4f-8ae2-4c59-8a35-549c49e00934}</ProjectGuid>
+    <ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
     <avrdevice>ATtiny84A</avrdevice>
     <avrdeviceseries>none</avrdeviceseries>
     <OutputType>Executable</OutputType>
     <OverrideVtorValue>exception_table</OverrideVtorValue>
     <BootSegment>2</BootSegment>
     <eraseonlaunchrule>1</eraseonlaunchrule>
+    <ExternalProgrammingToolCommand />
     <AsfFrameworkConfig>
       <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.26.0" />
-        </dependencies>
-      </framework-data>
+  <options />
+  <configurations />
+  <files />
+  <documentation help="" />
+  <offline-documentation help="" />
+  <dependencies>
+    <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.27.3" />
+  </dependencies>
+</framework-data>
     </AsfFrameworkConfig>
     <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
+    <avrtoolserialnumber>J41800000789</avrtoolserialnumber>
+    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>
     <com_atmel_avrdbg_tool_atmelice>
       <ToolOptions>
         <InterfaceProperties>
         <InterfaceName>debugWIRE</InterfaceName>
       </ToolOptions>
       <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000779</ToolNumber>
+      <ToolNumber>J41800000789</ToolNumber>
       <ToolName>Atmel-ICE</ToolName>
     </com_atmel_avrdbg_tool_atmelice>
     <avrtoolinterface>debugWIRE</avrtoolinterface>
-    <ExternalProgrammingToolCommand />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
     <ToolchainSettings>
@@ -65,7 +67,7 @@
   <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
   <avrgcc.compiler.symbols.DefSymbols>
     <ListValues>
-      <Value>DEBUG</Value>
+      <Value>NDEBUG</Value>
     </ListValues>
   </avrgcc.compiler.symbols.DefSymbols>
   <avrgcc.compiler.directories.IncludePaths>
       <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
     </ListValues>
   </avrgcc.compiler.directories.IncludePaths>
-  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+  <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
   <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
   <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
   <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
   <avrgcc.linker.libraries.Libraries>
     <ListValues>
       <Value>libm</Value>
     </ListValues>
   </avrgcc.linker.libraries.Libraries>
-  <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
 </AvrGcc>
     </ToolchainSettings>
   </PropertyGroup>
     </ToolchainSettings>
   </PropertyGroup>
   <ItemGroup>
-    <Compile Include="DS2438_DHT22.c">
+    <Compile Include="..\common\OWDS2438.S">
       <SubType>compile</SubType>
+      <Link>OWDS2438.S</Link>
     </Compile>
-    <Compile Include="OWDS2438.S">
+    <Compile Include="DS2438_DHT22.c">
       <SubType>compile</SubType>
     </Compile>
   </ItemGroup>
diff --git a/DS2438_SHT2X/DS2438_SHT2X.atsln b/DS2438_SHT2X/DS2438_SHT2X.atsln
new file mode 100644 (file)
index 0000000..1a91fb0
--- /dev/null
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Atmel Studio Solution File, Format Version 11.00
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2438_SHT2X", "DS2438_SHT2X.cproj", "{91468D4F-8AE2-4C59-8A35-549C49E00934}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|AVR = Debug|AVR
+               Release|AVR = Release|AVR
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.ActiveCfg = Debug|AVR
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.Build.0 = Debug|AVR
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.ActiveCfg = Release|AVR
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.Build.0 = Release|AVR
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/DS2438_SHT2X/DS2438_SHT2X.c b/DS2438_SHT2X/DS2438_SHT2X.c
new file mode 100644 (file)
index 0000000..00345f6
--- /dev/null
@@ -0,0 +1,210 @@
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//  * Redistributions of source code must retain the above copyright
+//    notice, this list of conditions and the following disclaimer.
+//  * Redistributions in binary form must reproduce the above copyright
+//    notice, this list of conditions and the following disclaimer in the
+//    documentation and/or other materials provided with the
+//    distribution.
+//  * All advertising materials mentioning features or use of this
+//    software must display the following acknowledgement: This product
+//    includes software developed by tm3d.de and its contributors.
+//  * Neither the name of tm3d.de nor the names of its contributors may
+//    be used to endorse or promote products derived from this software
+//    without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+#define F_CPU 8000000UL
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include <avr/wdt.h>
+#include <avr/sleep.h>
+#include <avr/pgmspace.h>
+#include "../common/I2C/USI_TWI_Master.h"
+#include "../common/I2C/MAX44009.h"
+#include "../common/I2C/SHT2x.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};
+       
+
+extern uint8_t mode;
+extern uint8_t gcontrol;
+extern uint8_t reset_indicator;
+extern uint8_t alarmflag;
+
+volatile uint8_t wdcounter;
+
+
+typedef union {
+
+       volatile uint8_t bytes[64];
+       struct {
+               uint8_t status;  //1
+               int16_t temp;  //2
+               uint16_t voltage;  //4
+               uint16_t current;  //6
+               uint8_t threshold; //8
+               
+               uint8_t page1[8]; //9
+               uint8_t page2[8]; //17
+               uint8_t page3[8]; //25
+               uint8_t page4[8];  //33
+               uint8_t page5[8];  //41
+               uint8_t page6[8];  //49
+               uint8_t page7[8];  //57
+               //uint8_t crc;  //65
+       };
+} pack_t;
+volatile pack_t pack;
+
+
+
+volatile int16_t am2302_temp;
+volatile uint16_t am2302_hum;
+
+uint8_t userRegister[1];
+int16_t sRH,sT;
+volatile 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__)
+ISR(WATCHDOG_vect) {
+#else
+ISR(WDT_vect) {
+#endif 
+       wdcounter++;
+       if (reset_indicator==1) reset_indicator++;
+       else if (reset_indicator==2) mode=0;
+
+
+}
+
+int testSW(void) {
+       uint8_t r;
+       DDRB&=~(1<<PORTB0);  //Eingang
+        __asm__ __volatile__ ("nop"); 
+        PORTB|=(1<<PORTB0); //Pullup
+        __asm__ __volatile__ ("nop"); 
+        __asm__ __volatile__ ("nop"); 
+        __asm__ __volatile__ ("nop"); 
+        __asm__ __volatile__ ("nop"); 
+        __asm__ __volatile__ ("nop"); 
+        r=PINB&(1<<PORTB0);
+        __asm__ __volatile__ ("nop"); 
+        PORTB&=~(1<<PORTB0); 
+        __asm__ __volatile__ ("nop"); 
+       DDRB|=(1<<PORTB0);  //Eingang
+       return (r==0);
+        
+        
+}
+
+int main(void){
+     PRR|=(1<<PRADC);  // adc for save Power
+       PORTA=0xFF;
+       PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
+       DDRB|=(1<<PORTB0); //Als Ausgang und 0
+       
+       
+       OWINIT();
+
+       ACSR|=(1<<ACD);  //Disable Comparator
+       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
+       MCUCR &=~(1<<PUD); //All Pins Pullup...
+       MCUCR |=(1<<BODS);
+
+       
+       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
+       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
+       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds
+        if (testSW()) {
+               config_info[5]=8;
+       }else{
+               config_info[5]=7;
+        }
+       
+    uint8_t i;
+    for(i=0;i<64;i++) pack.bytes[i]=0;
+       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);
+       
+       sei();
+       
+        while(1)   {
+                if (gcontrol) {
+                        wdcounter=3;
+                        gcontrol=0;
+                }
+                if (wdcounter>2) {
+                        //PORTB|=(1<<PINB1); //Dauer 440ms
+                        SHT2x_MeasurePoll(HUMIDITY, &sRH);
+                        // --- measure temperature with "Polling Mode" (no hold master) ---
+                        SHT2x_MeasurePoll(TEMP, &sT);
+                        //-- calculate humidity and temperature --
+                        temperatureC = SHT2x_CalcTemperatureC(sT)*10.0;
+                        humidityRH = SHT2x_CalcRH(sRH)*10.0;
+                        if (testSW()) {
+                                am2302_hum= humidityRH*10.0;
+                                am2302_temp=temperatureC*25.6;
+                                am2302_temp=am2302_temp-45;
+                                config_info[5]=8;      
+                                
+                        }else{
+                                
+                               double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
+                               //am2302_hum=0.318*hhum +76.0;
+                               am2302_hum=0.31*hhum +80;
+                               am2302_temp=temperatureC*25.6;
+                               am2302_temp=am2302_temp-45;
+                               config_info[5]=7;
+                        }
+                        //PORTB&=~(1<<PINB1);
+                        wdcounter=0;
+                }
+
+               if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))       {
+                       MCUCR|=(1<<SE)|(1<<SM1);
+                       MCUCR&=~(1<<ISC01);
+               } else {
+                       MCUCR|=(1<<SE);
+                       MCUCR&=~(1<<SM1);
+               }
+               asm("SLEEP");
+       }
+
+
+}
\ No newline at end of file
diff --git a/DS2438_SHT2X/DS2438_SHT2X.cproj b/DS2438_SHT2X/DS2438_SHT2X.cproj
new file mode 100644 (file)
index 0000000..7262f23
--- /dev/null
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectVersion>7.0</ProjectVersion>
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
+    <ProjectGuid>{91468d4f-8ae2-4c59-8a35-549c49e00934}</ProjectGuid>
+    <avrdevice>ATtiny84A</avrdevice>
+    <avrdeviceseries>none</avrdeviceseries>
+    <OutputType>Executable</OutputType>
+    <Language>C</Language>
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
+    <OutputFileExtension>.elf</OutputFileExtension>
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
+    <AssemblyName>DS2438_SHT2X</AssemblyName>
+    <Name>DS2438_SHT2X</Name>
+    <RootNamespace>DS2438_SHT2X</RootNamespace>
+    <ToolchainFlavour>Native</ToolchainFlavour>
+    <KeepTimersRunning>true</KeepTimersRunning>
+    <OverrideVtor>false</OverrideVtor>
+    <CacheFlash>true</CacheFlash>
+    <ProgFlashFromRam>true</ProgFlashFromRam>
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>
+    <UncachedRange />
+    <preserveEEPROM>true</preserveEEPROM>
+    <OverrideVtorValue>exception_table</OverrideVtorValue>
+    <BootSegment>2</BootSegment>
+    <eraseonlaunchrule>1</eraseonlaunchrule>
+    <AsfFrameworkConfig>
+      <framework-data xmlns="">
+        <options />
+        <configurations />
+        <files />
+        <documentation help="" />
+        <offline-documentation help="" />
+        <dependencies>
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.26.0" />
+        </dependencies>
+      </framework-data>
+    </AsfFrameworkConfig>
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
+    <com_atmel_avrdbg_tool_atmelice>
+      <ToolOptions>
+        <InterfaceProperties>
+        </InterfaceProperties>
+        <InterfaceName>debugWIRE</InterfaceName>
+      </ToolOptions>
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
+      <ToolNumber>J41800000779</ToolNumber>
+      <ToolName>Atmel-ICE</ToolName>
+    </com_atmel_avrdbg_tool_atmelice>
+    <avrtoolinterface>debugWIRE</avrtoolinterface>
+    <ExternalProgrammingToolCommand />
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
+    <ToolchainSettings>
+      <AvrGcc>
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+        <avrgcc.compiler.symbols.DefSymbols>
+          <ListValues>
+            <Value>DEBUG</Value>
+          </ListValues>
+        </avrgcc.compiler.symbols.DefSymbols>
+        <avrgcc.compiler.directories.IncludePaths>
+          <ListValues>
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+          </ListValues>
+        </avrgcc.compiler.directories.IncludePaths>
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+        <avrgcc.linker.libraries.Libraries>
+          <ListValues>
+            <Value>libm</Value>
+          </ListValues>
+        </avrgcc.linker.libraries.Libraries>
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+      </AvrGcc>
+    </ToolchainSettings>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+    <ToolchainSettings>
+      <AvrGcc>
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+        <avrgcc.compiler.symbols.DefSymbols>
+          <ListValues>
+            <Value>DEBUG</Value>
+          </ListValues>
+        </avrgcc.compiler.symbols.DefSymbols>
+        <avrgcc.compiler.directories.IncludePaths>
+          <ListValues>
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+          </ListValues>
+        </avrgcc.compiler.directories.IncludePaths>
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+        <avrgcc.linker.libraries.Libraries>
+          <ListValues>
+            <Value>libm</Value>
+          </ListValues>
+        </avrgcc.linker.libraries.Libraries>
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+      </AvrGcc>
+    </ToolchainSettings>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\SHT2x.c">
+      <SubType>compile</SubType>
+      <Link>SHT2x.c</Link>
+    </Compile>
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
+      <SubType>compile</SubType>
+      <Link>USI_TWI_Master.c</Link>
+    </Compile>
+    <Compile Include="D:\oc\dev\owSlave2\common\OWDS2438.S">
+      <SubType>compile</SubType>
+      <Link>OWDS2438.S</Link>
+    </Compile>
+    <Compile Include="DS2438_SHT2X.c">
+      <SubType>compile</SubType>
+    </Compile>
+  </ItemGroup>
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+</Project>
\ No newline at end of file
diff --git a/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.atsln b/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.atsln
new file mode 100644 (file)
index 0000000..ec60614
--- /dev/null
@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Atmel Studio Solution File, Format Version 11.00
+VisualStudioVersion = 14.0.23107.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2450_SHT2X_BMP280_MAX44009", "DS2450_SHT2X_BMP280_MAX44009.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|AVR = Debug|AVR
+               Release|AVR = Release|AVR
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.c b/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.c
new file mode 100644 (file)
index 0000000..3e01956
--- /dev/null
@@ -0,0 +1,318 @@
+
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//  * Redistributions of source code must retain the above copyright
+//    notice, this list of conditions and the following disclaimer.
+//  * Redistributions in binary form must reproduce the above copyright
+//    notice, this list of conditions and the following disclaimer in the
+//    documentation and/or other materials provided with the
+//    distribution.
+//  * All advertising materials mentioning features or use of this
+//    software must display the following acknowledgement: This product
+//    includes software developed by tm3d.de and its contributors.
+//  * Neither the name of tm3d.de nor the names of its contributors may
+//    be used to endorse or promote products derived from this software
+//    without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#define F_CPU 8000000UL
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include <avr/wdt.h>
+#include <avr/sleep.h>
+#include <avr/pgmspace.h>
+#include "../common/I2C/USI_TWI_Master.h"
+#include "../common/I2C/SHT2x.h"
+#include "../common/I2C/BMP280.h"
+#include "../common/I2C/MAX44009.h"
+extern void OWINIT();
+extern void EXTERN_SLEEP();
+
+uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/
+uint8_t config_info[16]={0x01,14,0x04,0x08, 0x03,15, 0x02,16,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+
+#if (owid>128) 
+#error "Variable not correct"
+#endif
+
+extern uint8_t mode;
+extern uint8_t gcontrol;
+extern uint8_t reset_indicator;
+extern uint8_t alarmflag;
+volatile uint8_t wdcounter=10;
+
+
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
+ISR(WATCHDOG_vect) {
+#else
+ISR(WDT_vect) {
+#endif 
+       wdcounter++;
+       if (reset_indicator==1) reset_indicator++;
+       else if (reset_indicator==2) mode=0;
+}
+
+typedef union {
+       volatile uint8_t bytes[0x20];
+       struct {
+               //Page0
+               uint16_t A;  //0
+               uint16_t B;  //2
+               uint16_t C;  //4
+               uint16_t D;  //6
+               //Page1
+               uint8_t CSA1;
+               uint8_t CSA2;
+               uint8_t CSB1;
+               uint8_t CSB2;
+               uint8_t CSC1;
+               uint8_t CSC2;
+               uint8_t CSD1;
+               uint8_t CSD2;
+               //Page2
+               uint8_t LA;
+               uint8_t HA;
+               uint8_t LB;
+               uint8_t HB;
+               uint8_t LC;
+               uint8_t HC;
+               uint8_t LD;
+               uint8_t HD;
+               //Page3
+               uint8_t FC1;
+               uint8_t FC2;
+               uint8_t FC3;
+               uint8_t FC4;
+               uint8_t VCCP;
+               uint8_t FC5;
+               uint8_t FC6;
+               uint8_t FC7;
+               uint8_t convc1;
+               uint8_t convc2;
+               
+               
+       };
+} pack_t;
+volatile pack_t pack;
+
+
+
+volatile int16_t am2302_temp;
+volatile uint16_t am2302_hum;
+
+
+uint8_t userRegister[1];
+int16_t sRH,sT;
+volatile double temperatureC,humidityRH;
+volatile double l;
+uint32_t P;
+int32_t t;
+uint8_t max_adr=0;
+
+
+
+int main(void){
+       pack.A=0;
+       pack.B=0;
+       pack.C=0;
+       pack.D=0;
+       pack.CSA1=0x08;
+       pack.CSA2=0x8C;
+       pack.CSB1=0x08;
+       pack.CSB2=0x8C;
+       pack.CSC1=0x08;
+       pack.CSC2=0x8C;
+       pack.CSD1=0x08;
+       pack.CSD2=0x8C;
+       pack.HA=0xFF;
+       pack.LA=0x00;
+       pack.HB=0xFF;
+       pack.LB=0x00;
+       pack.HC=0xFF;
+       pack.LC=0x00;
+       pack.HD=0xFF;
+       pack.LD=0x00;
+       pack.VCCP=0;
+    PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
+       DDRB|=(1<<PORTB0); //Als Ausgang und 0
+       PORTA=0xFF;  //All Pull up;
+        PRR|=(1<<PRADC);  // adc for save Power
+
+       ACSR|=(1<<ACD);  //Disable Comparator
+       OWINIT();
+
+       MCUCR &=~(1<<PUD); //All Pins Pullup...
+       MCUCR |=(1<<BODS);
+       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
+       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
+       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds
+       
+       gcontrol=1;
+       
+       USI_TWI_Master_Initialise();
+       bmp280Init();
+       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);
+       if (checkMAX44009(0)) max_adr=0; else max_adr=1 ;
+       
+       sei();
+       
+       //DDRB|=(1<<PINB1);
+
+    while(1)   {
+       
+       if (wdcounter>3) {      
+               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);
+               bmp280ConvertInt(&t,&P,1);
+               l=MAX44009getlux(max_adr);
+               if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045
+               //double l=1000;
+               l=(log(l)*1000)+32767.0;
+               wdcounter=0;
+       }
+       
+
+               
+               
+
+
+               if (gcontrol) {
+                       //PORTB|=(1<<PINB1);
+                       uint8_t bb=1;
+                       uint8_t bb1=1;
+                       for(uint8_t i=0;i<4;i++){
+                               if (pack.convc1&bb1) {
+                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0;pack.bytes[i*2+1]=0;}
+                                       bb=bb<<1;
+                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0xFF;pack.bytes[i*2+1]=0xFF;}
+                                       bb=bb<<1;
+                               } else bb=bb<<2;
+                               bb1=bb1<<1;                             
+                       }
+                       //CHanel A
+                       if (pack.convc1&1) {
+                               /*if (pack.CSA2&0x01)   ADMUX=0; else ADMUX=0x80;
+                               _delay_us(100);
+                               ADCSRA|=(1<<ADSC);
+                               while ((ADCSRA&(1<<ADSC)));
+                               cli();pack.A=ADC;sei();*/
+                               uint16_t ct=(temperatureC*100.0)+32767;
+                               cli();pack.A=ct;sei();
+                               wdcounter=10;
+                               alarmflag=0;
+                               
+                               if (pack.CSA2&0x08)  //AEH
+                                       if (pack.bytes[1]>pack.HA) {alarmflag=1;pack.CSA2|=0x20;}
+                               if (pack.CSA2&0x04)  //AEL
+                                       if (pack.bytes[1]<pack.LA) {alarmflag=1;pack.CSA2|=0x10;}
+                       }
+
+                       if (pack.convc1&2) {
+                               /*if (pack.CSB2&0x01)   ADMUX=1; else ADMUX=0x81;
+                               _delay_us(100);
+                               ADCSRA|=(1<<ADSC);
+                               while ((ADCSRA&(1<<ADSC)));
+                               cli();pack.B=ADC;sei();*/
+                               wdcounter=10;
+                               cli();pack.B=humidityRH*100;sei();
+                               if (pack.CSB2&0x08)  //AEH
+                                       if (pack.bytes[1]>pack.HB) {alarmflag=1;pack.CSB2|=0x20;}
+                               if (pack.CSB2&0x04)  //AEL
+                                       if (pack.bytes[1]<pack.LB) {alarmflag=1;pack.CSB2|=0x10;}
+                       }
+
+                       if (pack.convc1&4) {
+                               /*if (pack.CSC2&0x01)   ADMUX=2; else ADMUX=0x82;
+                               _delay_us(100);
+                               ADCSRA|=(1<<ADSC);
+                               while ((ADCSRA&(1<<ADSC)));
+                               cli();pack.C=ADC;sei();*/
+                               wdcounter=10;
+                               cli();pack.C=l;sei();
+                               if (pack.CSC2&0x08)  //AEH
+                                       if (pack.bytes[1]>pack.HC) {alarmflag=1;pack.CSC2|=0x20;}
+                               if (pack.CSC2&0x04)  //AEL
+                                       if (pack.bytes[1]<pack.LC) {alarmflag=1;pack.CSC2|=0x10;}
+                       } 
+                       if (pack.convc1&8) {
+                               /*if (pack.CSD2&0x01)   ADMUX=3; else ADMUX=0x83;
+                               _delay_us(100);
+                               ADCSRA|=(1<<ADSC);
+                               while ((ADCSRA&(1<<ADSC)));
+                               cli();pack.D=ADC;sei();*/
+                               wdcounter=10;
+                               cli();pack.D=P/100.0*32.0;sei();
+                               if (pack.CSD2&0x08)  //AEH
+                                       if (pack.bytes[1]>pack.HD) {alarmflag=1;pack.CSD2|=0x20;}
+                               if (pack.CSD2&0x04)  //AEL
+                                       if (pack.bytes[1]<pack.LD) {alarmflag=1;pack.CSD2|=0x10;}
+                       }
+                       
+                       EXTERN_SLEEP();
+                       //PORTB&=~(1<<PINB1);
+               }
+
+               /*uint8_t bb=1;
+               for(uint8_t i=0;i<4;i++) {
+                       if (pack.bytes[8+i*2]&0x80) {  //Chanel as output
+                               if (pack.bytes[8+i*2]&0x40) {
+                                       DDRA|=bb;
+                               } else {
+                                       DDRA&=~bb;
+                               }
+                       } else {
+                               DDRA&=~bb;
+                       }
+                       bb=bb*2;
+               }*/
+               
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
+                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
+#endif                 
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
+#endif
+                         {
+
+                       MCUCR|=(1<<SE)|(1<<SM1);
+                       MCUCR&=~(1<<ISC01);
+               } else {
+                       MCUCR|=(1<<SE);
+                       MCUCR&=~(1<<SM1);
+               }
+       //      asm("SLEEP");
+   }
+
+
+}
\ No newline at end of file
diff --git a/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.cproj b/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.cproj
new file mode 100644 (file)
index 0000000..cc9be46
--- /dev/null
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
+  <PropertyGroup>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectVersion>7.0</ProjectVersion>
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
+    <ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
+    <avrdevice>ATtiny84A</avrdevice>
+    <avrdeviceseries>none</avrdeviceseries>
+    <OutputType>Executable</OutputType>
+    <Language>C</Language>
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
+    <OutputFileExtension>.elf</OutputFileExtension>
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
+    <AssemblyName>DS2450</AssemblyName>
+    <Name>DS2450_SHT2X_BMP280_MAX44009</Name>
+    <RootNamespace>DS2450</RootNamespace>
+    <ToolchainFlavour>Native</ToolchainFlavour>
+    <KeepTimersRunning>true</KeepTimersRunning>
+    <OverrideVtor>false</OverrideVtor>
+    <CacheFlash>true</CacheFlash>
+    <ProgFlashFromRam>true</ProgFlashFromRam>
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>
+    <UncachedRange />
+    <preserveEEPROM>true</preserveEEPROM>
+    <OverrideVtorValue>exception_table</OverrideVtorValue>
+    <BootSegment>2</BootSegment>
+    <eraseonlaunchrule>1</eraseonlaunchrule>
+    <ExternalProgrammingToolCommand />
+    <AsfFrameworkConfig>
+      <framework-data xmlns="">
+        <options />
+        <configurations />
+        <files />
+        <documentation help="" />
+        <offline-documentation help="" />
+        <dependencies>
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.27.3" />
+        </dependencies>
+      </framework-data>
+    </AsfFrameworkConfig>
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
+    <avrtoolserialnumber>J41800000779</avrtoolserialnumber>
+    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>
+    <com_atmel_avrdbg_tool_atmelice>
+      <ToolOptions>
+        <InterfaceProperties>
+        </InterfaceProperties>
+        <InterfaceName>debugWIRE</InterfaceName>
+      </ToolOptions>
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
+      <ToolNumber>J41800000779</ToolNumber>
+      <ToolName>Atmel-ICE</ToolName>
+    </com_atmel_avrdbg_tool_atmelice>
+    <avrtoolinterface>debugWIRE</avrtoolinterface>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
+    <ToolchainSettings>
+      <AvrGcc>
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+        <avrgcc.compiler.symbols.DefSymbols>
+          <ListValues>
+            <Value>NDEBUG</Value>
+          </ListValues>
+        </avrgcc.compiler.symbols.DefSymbols>
+        <avrgcc.compiler.directories.IncludePaths>
+          <ListValues>
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+          </ListValues>
+        </avrgcc.compiler.directories.IncludePaths>
+        <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+        <avrgcc.linker.libraries.Libraries>
+          <ListValues>
+            <Value>libm</Value>
+          </ListValues>
+        </avrgcc.linker.libraries.Libraries>
+      </AvrGcc>
+    </ToolchainSettings>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+    <ToolchainSettings>
+      <AvrGcc>
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+        <avrgcc.compiler.symbols.DefSymbols>
+          <ListValues>
+            <Value>DEBUG</Value>
+          </ListValues>
+        </avrgcc.compiler.symbols.DefSymbols>
+        <avrgcc.compiler.directories.IncludePaths>
+          <ListValues>
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+          </ListValues>
+        </avrgcc.compiler.directories.IncludePaths>
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+        <avrgcc.linker.libraries.Libraries>
+          <ListValues>
+            <Value>libm</Value>
+          </ListValues>
+        </avrgcc.linker.libraries.Libraries>
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+      </AvrGcc>
+    </ToolchainSettings>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\BMP280.c">
+      <SubType>compile</SubType>
+      <Link>BMP280.c</Link>
+    </Compile>
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\MAX44009.c">
+      <SubType>compile</SubType>
+      <Link>MAX44009.c</Link>
+    </Compile>
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\SHT2x.c">
+      <SubType>compile</SubType>
+      <Link>SHT2x.c</Link>
+    </Compile>
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\TSL256x.c">
+      <SubType>compile</SubType>
+      <Link>TSL256x.c</Link>
+    </Compile>
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
+      <SubType>compile</SubType>
+      <Link>USI_TWI_Master.c</Link>
+    </Compile>
+    <Compile Include="DS2450_SHT2X_BMP280_MAX44009.c">
+      <SubType>compile</SubType>
+    </Compile>
+    <Compile Include="OWDS2450.S">
+      <SubType>compile</SubType>
+    </Compile>
+  </ItemGroup>
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+</Project>
\ No newline at end of file
diff --git a/DS2450_SHT2X_BMP280_MAX44009/OWDS2450.S b/DS2450_SHT2X_BMP280_MAX44009/OWDS2450.S
new file mode 100644 (file)
index 0000000..aec56b7
--- /dev/null
@@ -0,0 +1,247 @@
+
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
+// All rights reserved. 
+// 
+// Redistribution and use in source and binary forms, with or without 
+// modification, are permitted provided that the following conditions are 
+// met: 
+// 
+//  * Redistributions of source code must retain the above copyright 
+//    notice, this list of conditions and the following disclaimer. 
+//  * Redistributions in binary form must reproduce the above copyright 
+//    notice, this list of conditions and the following disclaimer in the 
+//    documentation and/or other materials provided with the 
+//    distribution. 
+//  * All advertising materials mentioning features or use of this 
+//    software must display the following acknowledgement: This product 
+//    includes software developed by tm3d.de and its contributors. 
+//  * Neither the name of tm3d.de nor the names of its contributors may 
+//    be used to endorse or promote products derived from this software 
+//    without specific prior written permission. 
+// 
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+
+#define _CHANGEABLE_ID_
+#define _ZERO_POLLING_
+
+#include "../common/OWConfig.s"
+#include "../common/OWCRC16.s"
+
+.extern pack,8
+.comm addr,1 ;zweites Adressbyte ist unnoetig (Warum auch immer fuer 32 Byte 16 Bit Adressen verwendet werden....)
+.comm crcsave,1 ; zwischenspeicherspeicher fuer crc nur zweites byte....
+//.extern  am2302_temp,2
+
+
+
+.macro CHIP_INIT       
+.endm
+
+.macro COMMAND_TABLE
+               rjmp h_readmemoryaddr
+               rjmp h_readmemory
+               rjmp h_readmemorycrc1
+               rjmp h_readmemorycrc2
+               rjmp h_writememoryaddr
+               rjmp h_writememory
+               rjmp h_writememorycrc1
+               rjmp h_writememorycrc2
+               rjmp h_writememoryreadback
+               rjmp h_convert
+               rjmp h_convertcrc1
+               rjmp h_convertcrc2
+               rjmp h_convert_conv
+.endm
+
+#include "../common/OWRomFunctions.s"
+#include "../common/OWTimerInterrupt.s"
+
+
+
+; Ab hier Geraeteabhaenging
+#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+0
+#define OW_READ_MEMORY OW_FIRST_COMMAND+1
+#define OW_READ_MEMORY_CRC1 OW_FIRST_COMMAND+2
+#define OW_READ_MEMORY_CRC2 OW_FIRST_COMMAND+3
+#define OW_WRITE_MEMORY_ADDR OW_FIRST_COMMAND+4
+#define OW_WRITE_MEMORY OW_FIRST_COMMAND+5
+#define OW_WRITE_MEMORY_CRC1 OW_FIRST_COMMAND+6
+#define OW_WRITE_MEMORY_CRC2 OW_FIRST_COMMAND+7
+#define OW_WRITE_MEMORY_READBACK OW_FIRST_COMMAND+8
+#define OW_CONVERT OW_FIRST_COMMAND+9
+#define OW_CONVERT_CRC1 OW_FIRST_COMMAND+10
+#define OW_CONVERT_CRC2 OW_FIRST_COMMAND+11
+#define OW_CONVERT_CONV OW_FIRST_COMMAND+12
+
+;---------------------------------------------------
+;      READ COMMAND and start operation
+;---------------------------------------------------
+
+
+h_readcommand:
+       clr r_bytep
+#ifndef _DIS_FLASH_
+       FLASH_COMMANDS ; muss zu erst sein....
+#endif
+       cset 0xAA,OW_READ_MEMORY_ADDR
+       cset 0x55,OW_WRITE_MEMORY_ADDR
+       cset 0x3C,OW_CONVERT
+       FW_CONFIG_INFO
+#ifdef _CHANGEABLE_ID_
+       CHANGE_ID_COMMANDS
+#endif
+       ldi r_mode,OW_SLEEP
+       rjmp handle_end
+
+
+h_readmemoryaddr:
+       cpi r_bytep,0  ;erstes Adressbyte ?
+       brne h_readmemory_addr_byte1 ;nein dann weiter
+       andi r_rwbyte,0x1F  ; nur Adressen zwischen 0 und 0x1F zulassen
+       sts addr,r_rwbyte  ;speichern des ersten bytes
+       rjmp handle_end_inc
+h_readmemory_addr_byte1:  ;zweiters Addressbyte wird nicht gespeichert!
+       ldi r_mode,OW_READ_MEMORY ;weiter zu read Memory
+       ;;ldi r_bcount,1 ;ist unten
+       ldi r_sendflag,1 ;jetzt sendet der Slave zum Master
+       clr r_bytep
+       rjmp h_readmemory2
+h_readmemory:
+       lds r_bytep,addr
+       inc r_bytep
+       sts addr,r_bytep
+       andi r_bytep,0x07
+       breq h_readmemory_init_crc
+h_readmemory2:
+       lds r_bytep,addr
+       ;andi r_bytep,0x1F ist oben
+       configZ pack,r_bytep
+       ld   r_rwbyte,Z
+       ;ldi r_bcount,1
+       rjmp handle_end ;sendet das Byte und geht zu h_readmemory
+h_readmemory_init_crc:; init erstes CRC byte
+       lds r_rwbyte,crc
+       com r_rwbyte
+       lds r_temp,crc+1
+       com r_temp
+       sts crcsave,r_temp
+       ldi r_mode,OW_READ_MEMORY_CRC1
+       ;ldi r_bcount,1
+       rjmp handle_end
+h_readmemory_end:
+       ldi  r_mode,OW_SLEEP
+       clr r_sendflag
+       rjmp handle_end
+h_readmemorycrc1:;init zweites CRC Byte
+       lds r_rwbyte,crcsave
+       ;ldi r_bcount,1
+       ldi r_mode,OW_READ_MEMORY_CRC2
+       rjmp handle_end
+h_readmemorycrc2:;weiteres senden..... nach zweitem Byte
+       lds r_temp,addr
+       andi r_temp,0xE0
+       brne h_readmemory_end; ende des speichers
+       ldi r_mode,OW_READ_MEMORY
+       CRCInit1 ;Start with new CRC
+       rjmp h_readmemory2
+
+h_writememoryaddr:
+       cpi r_bytep,0  ;erstes Adressbyte ?
+       brne h_writememory_addr_byte1 ;nein dann weiter
+       andi r_rwbyte,0x1F  ; nur Adressen zwischen 0 und 0x1F zulassen
+       sts addr,r_rwbyte  ;speichern des ersten bytes
+       inc r_bytep
+       ;ldi r_bcount,1
+       rjmp handle_end
+h_writememory_addr_byte1:  ;zweiters Addressbyte wird nicht gespeichert!
+       ldi r_mode,OW_WRITE_MEMORY ;weiter zu read Memory
+       ;ldi r_bcount,1 ;; _________________________________________________in handle_end integrieren.....
+       lds r_bytep,addr
+       rjmp handle_end ;read Memory Byte
+h_writememory:
+       lds r_bytep,addr
+       configZ pack,r_bytep
+       st Z,r_rwbyte
+       ;ldi r_bcount,1
+       ldi r_mode,OW_WRITE_MEMORY_CRC1
+       ldi r_sendflag,1 ;jetzt sendet der Slave zum Master
+       lds r_rwbyte,crc
+       com r_rwbyte
+       lds r_temp,crc+1
+       com r_temp
+       sts crcsave,r_temp
+       rjmp handle_end
+h_writememorycrc1:
+       lds r_rwbyte,crcsave
+       ;ldi r_bcount,1
+       ldi r_mode,OW_WRITE_MEMORY_CRC2
+       rjmp handle_end
+h_writememorycrc2:
+       lds r_temp,addr
+       configZ pack,r_temp
+       ld r_rwbyte,Z
+       ;ldi r_bcount,1
+       ldi r_mode,OW_WRITE_MEMORY_READBACK
+       rjmp handle_end
+h_writememoryreadback:
+       ldi r_temp,0x00
+       sts crc+1,r_temp
+       lds r_temp,addr
+       inc r_temp
+       sts addr,r_temp
+       sts crc,r_temp
+       ldi r_sendflag,0
+       ;ldi r_bcount,1
+       ldi r_mode,OW_WRITE_MEMORY
+       rjmp handle_end
+
+h_convert:
+       cpi r_bytep,0  ;erstes Adressbyte ?
+       brne h_convert_byte1 ;nein dann weiter
+       inc r_bytep
+       sts pack+0x20,r_rwbyte
+       ;ldi r_bcount,1
+       rjmp handle_end
+h_convert_byte1: ;zweies byte glesen go crc#
+       sts pack+0x21,r_rwbyte
+       lds r_rwbyte,crc
+       com r_rwbyte
+       lds r_temp,crc+1
+       com r_temp
+       sts crcsave,r_temp
+       ldi r_mode,OW_CONVERT_CRC1
+       ;ldi r_bcount,1
+       ldi r_sendflag,1
+       rjmp handle_end 
+h_convertcrc1:
+       lds r_rwbyte,crcsave
+       ;ldi r_bcount,1
+       ldi r_mode,OW_CONVERT_CRC2
+       rjmp handle_end
+h_convertcrc2:
+       ldi r_temp,1
+       sts gcontrol,r_temp
+       ;ldi r_bcount,1
+       ldi r_mode,OW_CONVERT_CONV
+       ;clr r_sendflag
+       ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling
+h_convert_conv:
+       ldi r_bcount,0
+       ldi r_rwbyte,0
+       rjmp handle_end_no_bcount       
+
+
+
+
+#include "../common/OWPinInterrupt.s"
+.end
\ No newline at end of file
diff --git a/common/OWDS2423.S b/common/OWDS2423.S
new file mode 100644 (file)
index 0000000..05df87d
--- /dev/null
@@ -0,0 +1,339 @@
+
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
+// All rights reserved. 
+// 
+// Redistribution and use in source and binary forms, with or without 
+// modification, are permitted provided that the following conditions are 
+// met: 
+// 
+//  * Redistributions of source code must retain the above copyright 
+//    notice, this list of conditions and the following disclaimer. 
+//  * Redistributions in binary form must reproduce the above copyright 
+//    notice, this list of conditions and the following disclaimer in the 
+//    documentation and/or other materials provided with the 
+//    distribution. 
+//  * All advertising materials mentioning features or use of this 
+//    software must display the following acknowledgement: This product 
+//    includes software developed by tm3d.de and its contributors. 
+//  * Neither the name of tm3d.de nor the names of its contributors may 
+//    be used to endorse or promote products derived from this software 
+//    without specific prior written permission. 
+// 
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+
+
+#define _CHANGEABLE_ID_
+#define _ZERO_POLLING_
+#include "../common/OWConfig.s"
+#include "../common/OWCRC16.s"
+
+.extern pack,45
+.extern counters,8
+
+.macro CHIP_INIT       
+.endm
+
+.macro COMMAND_TABLE
+               rjmp h_writescratchpad
+               rjmp h_writescratchpad_crc
+               rjmp h_readscratchpad
+               rjmp h_copyscratchpad
+               rjmp h_readmemory_addr
+               rjmp h_readmemory
+               rjmp h_readmemorycounter_addr
+               rjmp h_readmemorycounter
+               rjmp h_readmemorycounter_ex
+.endm
+
+#include "../common/OWRomFunctions.s"
+#include "../common/OWTimerInterrupt.s"
+
+
+
+; Ab hier Geraeteabhaenging
+#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+0
+#define OW_WRITE_SCRATCHPAD_CRC OW_FIRST_COMMAND+1
+#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+2
+#define OW_COPY_SCRATCHPAD OW_FIRST_COMMAND+3
+#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+4
+#define OW_READ_MEMORY OW_FIRST_COMMAND+5
+#define OW_READ_MEMORYCOUNTER_ADDR OW_FIRST_COMMAND+6
+#define OW_READ_MEMORYCOUNTER OW_FIRST_COMMAND+7
+#define OW_READ_MEMORYCOUNTER_EX OW_FIRST_COMMAND+8
+
+;---------------------------------------------------
+;      READ COMMAND and start operation
+;---------------------------------------------------
+
+
+h_readcommand:
+       clr r_bytep
+#ifndef _DIS_FLASH_
+       FLASH_COMMANDS ; muss zu erst sein....
+#endif
+       cset 0x0F,OW_WRITE_SCRATCHPAD
+       cjmp 0xAA,hrc_set_readscratchpad
+       cset 0x5A,OW_COPY_SCRATCHPAD
+       cset 0xF0,OW_READ_MEMORY_ADDR
+       cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR
+       FW_CONFIG_INFO
+#ifdef _CHANGEABLE_ID_
+       CHANGE_ID_COMMANDS
+#endif
+       ldi r_mode,OW_SLEEP
+       rjmp handle_end
+
+hrc_set_readscratchpad:
+       ldi r_mode,OW_READ_SCRATCHPAD
+       ldi r_sendflag,1
+       rjmp h_readscratchpad
+
+h_writescratchpad:
+       configZ pack,r_bytep
+       inc  r_bytep
+       st   Z,r_rwbyte
+       cpi  r_bytep,2
+       breq h_writescratchpad_block
+       brsh h_writescratchpad_set_eoffset ;;33
+       rjmp handle_end  ;handle_end zu weit entfernt fuer br...
+h_writescratchpad_set_eoffset:
+       cpi  r_bytep,35
+       breq h_writescratchpad_setcrc
+       mov r_temp,r_bytep
+       subi r_temp,4
+       sts pack+2,r_temp ;AA und PF cleared
+       rjmp handle_end
+;Start writeing to 32 Byte Block ; skip status byte    
+h_writescratchpad_block:
+       lds r_temp,pack ; Adresse low byte
+       andi r_temp,0x1F ;32 byte
+       add r_bytep,r_temp ;Zur angegebenen Startadresse springen
+       ;ori r_temp,0x20 ; Set PF flag
+       sts pack+2,r_temp  ;E4:E0 vorher setzen
+       ; Byte 3 ueberspringen
+       rjmp handle_end_inc
+
+h_writescratchpad_setcrc:
+       ;copy crc to pack
+       lds r_temp,crc
+       com r_temp
+       sts pack+43,r_temp
+       lds r_temp,crc+1
+       com r_temp ; invertieren , komischer name.....
+       sts pack+44,r_temp
+       ldi  r_mode,OW_WRITE_SCRATCHPAD_CRC
+       ldi r_sendflag,1
+       ldi r_bytep,43
+h_writescratchpad_crc:
+       cpi r_bytep,45
+       breq h_writescratchpad_crc_end
+       configZ pack,r_bytep
+       ld r_rwbyte,Z
+       rjmp handle_end_inc
+h_writescratchpad_crc_end:
+       rjmp handle_end_sleep
+       
+       
+h_readscratchpad:
+       cpi r_bytep,35
+       breq h_readscratchpad_end
+       cpi r_bytep,3
+       brne h_readscratchpad_read_byte
+h_readscratchpad_set_offset:
+       lds r_temp,pack
+       andi r_temp,0x1F
+       ldi r_temp2,3
+       add r_temp,r_temp2
+       mov r_bytep,r_temp
+h_readscratchpad_read_byte:
+       configZ pack,r_bytep
+       ld r_rwbyte,Z
+       rjmp handle_end_inc
+h_readscratchpad_end:
+       rjmp handle_end_sleep
+
+
+
+h_copyscratchpad:
+       cpi  r_bytep,3
+       brsh h_copyscratchpad_ok
+       configZ pack,r_bytep
+       inc  r_bytep
+       ld   r_temp,Z
+       cp r_temp,r_rwbyte
+       brne h_copyscratchpad_nok
+       cpi  r_bytep,3
+       breq h_copyscratchpad_ok
+       ldi  r_bcount,1 
+       rjmp handle_end
+h_copyscratchpad_ok:
+       ldi r_rwbyte,0xAA
+       ldi r_sendflag,1
+       rjmp handle_end
+h_copyscratchpad_nok:
+       lds r_temp,pack+3
+       andi r_temp,~0x80
+       sts pack+3,r_temp
+       rjmp handle_end_sleep
+
+
+h_readmemory_addr:
+       cpi r_bytep,0
+       brne h_readmrmory_addr_byte1
+       sts pack,r_rwbyte
+       rjmp handle_end_inc
+h_readmrmory_addr_byte1:
+       sts pack+1,r_rwbyte
+       ldi r_mode,OW_READ_MEMORY
+       ldi r_sendflag,1
+       clr r_bytep
+       rjmp h_readmemory2
+h_readmemory:
+       lds r_bytep,pack
+       lds r_temp2,pack+1
+       inc r_bytep
+       clr r_temp
+       adc r_temp2,r_temp
+       sbrc r_temp2,1
+       rjmp h_readmemory_end
+       sts pack+1,r_temp
+       sts pack,r_bytep
+h_readmemory2:
+       lds r_bytep,pack
+       andi r_bytep,0x1F
+       configZ pack+3,r_bytep
+       ld   r_rwbyte,Z
+       rjmp handle_end
+h_readmemory_end:
+       rjmp handle_end_sleep
+
+
+
+
+
+
+
+
+h_readmemorycounter_addr:
+       cpi r_bytep,0
+       brne h_readmrmorycounter_addr_byte1
+       sts pack,r_rwbyte
+       inc r_bytep
+       ;ldi r_bcount,1
+       rjmp handle_end
+h_readmrmorycounter_addr_byte1:
+       sts pack+1,r_rwbyte
+       ldi r_mode,OW_READ_MEMORYCOUNTER
+       ;ldi r_bcount,1 
+       ldi r_sendflag,1
+       clr r_bytep
+       rjmp h_readmemorycounter2
+h_readmemorycounter:
+       lds r_bytep,pack
+       lds r_temp2,pack+1
+       ldi r_temp,1  ;inc leider kein c flag
+       add r_bytep,r_temp
+       clr r_temp
+       adc r_temp2,r_temp
+       mov r_temp,r_bytep
+       andi r_temp,0x1F
+       breq h_readmemorycounter_next
+       sts pack+1,r_temp2
+       sts pack,r_bytep
+h_readmemorycounter2:  ;Lesen von dem worauf die erstenzwei bytes zeigen
+       lds r_bytep,pack
+       andi r_bytep,0x1F
+       configZ pack+3,r_bytep
+       ld   r_rwbyte,Z
+       ;ldi r_bcount,1
+       rjmp handle_end
+//h_readmemorycounter_end:
+//     ldi  r_mode,OW_SLEEP
+//     clr r_sendflag
+//     rjmp handle_end
+h_readmemorycounter_next:  ; rest lesen
+       ldi  r_mode,OW_READ_MEMORYCOUNTER_EX
+       ldi r_bytep,34
+       lds r_temp2,pack
+       lds r_temp,pack+1
+       //lsr r_temp
+       //ror r_temp2
+
+       lsl r_temp2
+       rol r_temp
+       cpi r_temp,3
+       brne h_readmemorycounter_cFF
+       andi r_temp2,0xC0
+       swap r_temp2
+
+       ;cpi r_temp,0xE0
+
+       configZ counters,r_temp2
+       ld r_temp,Z+
+       sts pack+35,r_temp      
+       ld r_temp,Z+
+       sts pack+36,r_temp      
+       ld r_temp,Z+
+       sts pack+37,r_temp      
+       ld r_temp,Z+
+       sts pack+38,r_temp      
+       rjmp h_readmemorycounter_ex
+h_readmemorycounter_cFF:
+       ldi r_temp,0xFF
+       sts pack+35,r_temp      
+       sts pack+36,r_temp      
+       sts pack+37,r_temp      
+       sts pack+38,r_temp      
+
+h_readmemorycounter_ex:
+       inc r_bytep
+       cpi r_bytep,45
+       breq h_readmemorycounter_ex_end
+       cpi r_bytep,43
+       brne h_readmemorycounter_ex2
+       lds r_temp,crc
+       com r_temp
+       sts pack+43,r_temp
+       lds r_temp,crc+1
+       com r_temp
+       sts pack+44,r_temp
+h_readmemorycounter_ex2:
+       ;ldi r_bcount,1
+       configZ pack,r_bytep
+       ld   r_rwbyte,Z
+       rjmp handle_end
+h_readmemorycounter_ex_end:
+       lds r_bytep,pack
+       lds r_temp2,pack+1
+       ldi r_temp,1  ;inc leider kein c flag
+       add r_bytep,r_temp
+       clr r_temp
+       adc r_temp2,r_temp
+       sbrc r_temp2,1 ;am ene von allem 
+       rjmp h_readmemorycounter_ex_sleep
+       CRCInit1
+       ldi  r_mode,OW_READ_MEMORYCOUNTER
+       sts pack+1,r_temp2
+       sts pack,r_bytep
+       rjmp h_readmemorycounter2
+h_readmemorycounter_ex_sleep:
+       ldi r_mode,OW_SLEEP
+       clr r_sendflag
+       rjmp handle_end
+
+
+
+       
+
+#include "../common/OWPinInterrupt.s"
+.end
\ No newline at end of file
diff --git a/common/OWDS2438.S b/common/OWDS2438.S
new file mode 100644 (file)
index 0000000..35bc463
--- /dev/null
@@ -0,0 +1,187 @@
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
+// All rights reserved. 
+// 
+// Redistribution and use in source and binary forms, with or without 
+// modification, are permitted provided that the following conditions are 
+// met: 
+// 
+//  * Redistributions of source code must retain the above copyright 
+//    notice, this list of conditions and the following disclaimer. 
+//  * Redistributions in binary form must reproduce the above copyright 
+//    notice, this list of conditions and the following disclaimer in the 
+//    documentation and/or other materials provided with the 
+//    distribution. 
+//  * All advertising materials mentioning features or use of this 
+//    software must display the following acknowledgement: This product 
+//    includes software developed by tm3d.de and its contributors. 
+//  * Neither the name of tm3d.de nor the names of its contributors may 
+//    be used to endorse or promote products derived from this software 
+//    without specific prior written permission. 
+// 
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+
+#define _CHANGEABLE_ID_
+//#define _DIS_FLASH_
+#define _ZERO_POLLING_
+//#define _DB_
+
+#include "../common/OWConfig.s"
+#include "../common/OWCRC8.s"
+
+#if  defined(__AVR_ATtiny25__)
+.extern pack,16
+#else
+.extern pack,64
+#endif
+.extern  am2302_temp,2
+.extern  am2302_hum,2
+.comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad)
+
+
+.macro CHIP_INIT
+.endm
+
+; Ab hier Geraeteabhaenging
+#define OW_READ_SCRATCHPAD_ADR OW_FIRST_COMMAND+0
+#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+1
+#define OW_WRITE_SCRATCHPAD_ADR OW_FIRST_COMMAND+2
+#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+3
+
+
+
+.macro COMMAND_TABLE
+               rjmp h_readscratchpad_adr
+               rjmp h_readscratchpad
+               rjmp h_writescratchpad_adr
+               rjmp h_writescratchpad
+.endm
+
+#include "../common/OWRomFunctions.s"
+#include "../common/OWTimerInterrupt.s"
+
+
+;---------------------------------------------------
+;      READ COMMAND and start operation
+;---------------------------------------------------
+
+
+h_readcommand:
+       clr r_bytep
+#ifndef _DIS_FLASH_
+       FLASH_COMMANDS ; muss zu erst sein....
+#endif
+       cset 0xBE,OW_READ_SCRATCHPAD_ADR
+       cset 0x4E,OW_WRITE_SCRATCHPAD_ADR
+       cjmp 0x44,hrc_set_convertT
+       cjmp 0xB4,hrc_set_convertV
+       FW_CONFIG_INFO
+#ifdef _CHANGEABLE_ID_
+       CHANGE_ID_COMMANDS
+#endif
+       rjmp handle_end_sleep
+
+
+hrc_set_convertT:
+       ldi r_temp,1
+       sts gcontrol,r_temp
+       lds r_temp,am2302_temp
+       sts pack+1,r_temp
+       lds r_temp,am2302_temp+1
+       sts pack+2,r_temp
+       rjmp handle_end_sleep
+hrc_set_convertV:
+       ldi r_temp,2
+       sts gcontrol,r_temp
+       lds r_temp,pack
+       sbrs r_temp,3
+       rjmp hrc_set_convertVV
+       ldi r_temp,0xF4
+       sts pack+3,r_temp
+       ldi r_temp,0x01
+       sts pack+4,r_temp
+       rjmp hrc_set_convertend
+hrc_set_convertVV:
+       lds r_temp,am2302_hum
+       sts pack+3,r_temp
+       lds r_temp,am2302_hum+1
+       sts pack+4,r_temp
+hrc_set_convertend:
+       rjmp handle_end_sleep
+
+
+
+;---------------------------------------------------
+;   READ SCRATCHPAD
+;---------------------------------------------------
+
+h_readscratchpad_adr:
+       lsl r_rwbyte
+       lsl r_rwbyte
+       lsl r_rwbyte
+#if  defined(__AVR_ATtiny25__)
+       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
+#endif
+       sts block,r_rwbyte
+       ldi r_sendflag,1
+       ldi r_mode,OW_READ_SCRATCHPAD
+       CRCInit2
+h_readscratchpad:
+       cpi  r_bytep,8
+       breq h_readscratchpad_crc
+       cpi  r_bytep,9
+       breq h_readscratchpad_all
+       lds  r_temp,block
+       add  r_temp,r_bytep
+       configZ pack,r_temp
+       ld   r_rwbyte,Z
+       rjmp handle_end_inc
+h_readscratchpad_crc:
+       lds  r_rwbyte,crc
+       rjmp handle_end_inc
+h_readscratchpad_all:
+       rjmp handle_end_sleep
+
+
+
+
+;---------------------------------------------------
+;   WRITE SCRATCHPAD
+;---------------------------------------------------
+h_writescratchpad_adr:
+       lsl r_rwbyte
+       lsl r_rwbyte
+       lsl r_rwbyte
+#if  defined(__AVR_ATtiny25__)
+       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
+#endif
+       sts block,r_rwbyte
+       ldi r_mode,OW_WRITE_SCRATCHPAD
+       ldi  r_bcount,1 
+       rjmp handle_end 
+h_writescratchpad:
+       cpi  r_bytep,8
+       breq h_writescratchpad_all
+       lds  r_temp,block
+       add  r_temp,r_bytep
+       configZ pack,r_temp
+       st   Z,r_rwbyte
+       rjmp handle_end_inc
+h_writescratchpad_all:
+       rjmp handle_end_sleep
+
+
+
+
+
+#include "../common/OWPinInterrupt.s"
+.end
\ No newline at end of file