From: Tobias Date: Tue, 9 Feb 2016 18:52:22 +0000 (+0100) Subject: - New Device compinations X-Git-Url: https://git.smho.de/?a=commitdiff_plain;h=0f5b4d994ac87afdd294f6fc79692bcf92e337de;p=owSlave2.git - New Device compinations - ASM-files for Device in common. Only in C files are the specific function --- diff --git a/DS18B20_BMP280_DS2438_SHT/DS18B20_DS2438.c b/DS18B20_BMP280_DS2438_SHT/DS18B20_DS2438.c index 5b98b1c..b4b62d0 100644 --- a/DS18B20_BMP280_DS2438_SHT/DS18B20_DS2438.c +++ b/DS18B20_BMP280_DS2438_SHT/DS18B20_DS2438.c @@ -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<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__) diff --git a/DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c b/DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c index d455f89..5a0094e 100644 --- a/DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c +++ b/DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c @@ -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<>8)&0xFF; + + while(EECR & (1<>8; + EECR |= (1<0) { if (startup!=0) startup--; - //PORTB|=(1<>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; } diff --git a/DS2423/DS2423.cproj b/DS2423/DS2423.cproj index 24adaf9..d86cc1e 100644 --- a/DS2423/DS2423.cproj +++ b/DS2423/DS2423.cproj @@ -2,7 +2,7 @@ 2.0 - 6.2 + 7.0 com.Atmel.AVRGCC8.C {26106a5a-6618-4774-943f-65c46ddb610b} ATtiny84A @@ -50,61 +50,76 @@ Atmel-ICE debugWIRE + - True - True - True - True - False - True - True - - - NDEBUG - - - Optimize for size (-Os) - True - True - True - - - libm - - - + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + - True - True - True - True - False - True - True - - - DEBUG - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - Default (-Wa,-g) - + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + diff --git a/DS2423_BMP280/DS2423_BMP280.atsln b/DS2423_BMP280/DS2423_BMP280.atsln new file mode 100644 index 0000000..3b8bc1f --- /dev/null +++ b/DS2423_BMP280/DS2423_BMP280.atsln @@ -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 index 0000000..8ec5432 --- /dev/null +++ b/DS2423_BMP280/DS2423_BMP280.c @@ -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 +#include +#include +#include +#include +#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<2) { + bmp280ConvertInt(&t,&P,1); + while (mode!=0) ; + cli(); + counters.c32[3]=P; + counters.c32[2]=t; + sei(); + + wdcounter=0; + } + + if (((TIMSK0 & (1< + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + {26106a5a-6618-4774-943f-65c46ddb610b} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS2423_BMP280 + DS2423_BMP280 + DS2423_BMP280 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800024445 + Atmel-ICE + + debugWIRE + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + BMP280.c + + + compile + USI_TWI_Master.c + + + compile + OWDS2423.S + + + compile + + + + \ No newline at end of file diff --git a/DS2438_DHT22/DS2438_DHT22.atsln b/DS2438_DHT22/DS2438_DHT22.atsln index 77e7763..1c780e5 100644 --- a/DS2438_DHT22/DS2438_DHT22.atsln +++ b/DS2438_DHT22/DS2438_DHT22.atsln @@ -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 diff --git a/DS2438_DHT22/DS2438_DHT22.c b/DS2438_DHT22/DS2438_DHT22.c index 6d4a5a0..a182bed 100644 --- a/DS2438_DHT22/DS2438_DHT22.c +++ b/DS2438_DHT22/DS2438_DHT22.c @@ -32,19 +32,21 @@ #define F_CPU 8000000UL -//#define FP_CALC #include #include #include #include #include +#include -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< 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< 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<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<=8) { - am2302_mode=0; - SENSON - } -#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - if (((TIMSK & (1< - + 2.0 7.0 com.Atmel.AVRGCC8.C - {91468d4f-8ae2-4c59-8a35-549c49e00934} + dce6c7e3-ee26-4d79-826b-08594b9ad897 ATtiny84A none Executable @@ -26,19 +26,22 @@ exception_table 2 1 + - - - - - - - - - + + + + + + + + + com.atmel.avrdbg.tool.atmelice + J41800000789 + 0x1E930C @@ -46,11 +49,10 @@ debugWIRE com.atmel.avrdbg.tool.atmelice - J41800000779 + J41800000789 Atmel-ICE debugWIRE - @@ -65,7 +67,7 @@ True - DEBUG + NDEBUG @@ -73,17 +75,15 @@ %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include - Optimize (-O1) + Optimize for size (-Os) True True - Default (-g2) True libm - Default (-Wa,-g) @@ -123,10 +123,11 @@ - + compile + OWDS2438.S - + compile diff --git a/DS2438_SHT2X/DS2438_SHT2X.atsln b/DS2438_SHT2X/DS2438_SHT2X.atsln new file mode 100644 index 0000000..1a91fb0 --- /dev/null +++ b/DS2438_SHT2X/DS2438_SHT2X.atsln @@ -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 index 0000000..00345f6 --- /dev/null +++ b/DS2438_SHT2X/DS2438_SHT2X.c @@ -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 +#include +#include +#include +#include +#include +#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<2) { + //PORTB|=(1< + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + {91468d4f-8ae2-4c59-8a35-549c49e00934} + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS2438_SHT2X + DS2438_SHT2X + DS2438_SHT2X + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000779 + Atmel-ICE + + debugWIRE + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + SHT2x.c + + + compile + USI_TWI_Master.c + + + compile + OWDS2438.S + + + compile + + + + \ 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 index 0000000..ec60614 --- /dev/null +++ b/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.atsln @@ -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 index 0000000..3e01956 --- /dev/null +++ b/DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.c @@ -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 +#include +#include +#include +#include +#include +#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<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<pack.HA) {alarmflag=1;pack.CSA2|=0x20;} + if (pack.CSA2&0x04) //AEL + if (pack.bytes[1]pack.HB) {alarmflag=1;pack.CSB2|=0x20;} + if (pack.CSB2&0x04) //AEL + if (pack.bytes[1]pack.HC) {alarmflag=1;pack.CSC2|=0x20;} + if (pack.CSC2&0x04) //AEL + if (pack.bytes[1]pack.HD) {alarmflag=1;pack.CSD2|=0x20;} + if (pack.CSD2&0x04) //AEL + if (pack.bytes[1] + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + dce6c7e3-ee26-4d79-826b-08594b9ad897 + ATtiny84A + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + DS2450 + DS2450_SHT2X_BMP280_MAX44009 + DS2450 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + J41800000779 + 0x1E930C + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000779 + Atmel-ICE + + debugWIRE + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + + + + + + compile + BMP280.c + + + compile + MAX44009.c + + + compile + SHT2x.c + + + compile + TSL256x.c + + + compile + USI_TWI_Master.c + + + compile + + + compile + + + + \ 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 index 0000000..aec56b7 --- /dev/null +++ b/DS2450_SHT2X_BMP280_MAX44009/OWDS2450.S @@ -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 index 0000000..05df87d --- /dev/null +++ b/common/OWDS2423.S @@ -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 index 0000000..35bc463 --- /dev/null +++ b/common/OWDS2438.S @@ -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