From 2490e261a78b2a98ee2a9b8fc19cb3f20225926b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20M=C3=BCller?= Date: Tue, 24 Oct 2017 16:57:54 +0200 Subject: [PATCH] New I2C devices Correction of dual devices --- DS18B20_BMP280/DS18B20_BMP280.cproj | 4 +- DS18B20_CDM7160/DS18B20_CDM7160.atsln | 10 +- DS18B20_CDM7160/DS18B20_CDM7160.c | 27 +- DS18B20_CDM7160/DS18B20_CDM7160.cproj | 85 ++-- DS18B20_MAX44009/DS18B20_MAX44009.cproj | 142 +++--- DS18B20_MAX44009_DS2438_SHT/DS18B20_DS2438.c | 6 +- .../DS18B20_MAX44009_DS2438_SHT.cproj | 22 +- DS18B20_Thermocouble/convthermocouple.py | 27 +- .../DS18B20_DS2438.c | 33 +- .../DS18B20_Thermocouble_DS2438_SHT.cproj | 18 +- .../DS18B20_DS2438.c | 91 +++- DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c | 106 +++-- DS2423_DS2413/Makefile | 6 +- DS2438_SHT3X/DS2438_SHT3X.cproj | 143 +++--- .../DS2438_DS2438.c | 198 ++++---- DS2450/DS2450.c | 7 +- DS2450/DS2450.cproj | 18 +- DS2450/OWDS2450.S | 3 +- DS2450_APDS9960/DS2450_APDS9960.atsln | 22 + DS2450_APDS9960/DS2450_APDS9960.c | 283 ++++++++++++ DS2450_APDS9960/DS2450_APDS9960.cproj | 152 ++++++ DS2450_IAQCORE/DS2450_IAQCORE.atsln | 22 + DS2450_IAQCORE/DS2450_IAQCORE.c | 232 ++++++++++ DS2450_IAQCORE/DS2450_IAQCORE.cproj | 139 ++++++ common/I2C/APDS9960.c | 138 ++++++ common/I2C/APDS9960.h | 45 ++ common/I2C/BME680.c | 436 ++++++++++++++++++ common/I2C/BME680.h | 46 ++ common/I2C/IAQCORE.c | 57 +++ common/I2C/IAQCORE.h | 44 ++ common/I2C/SGP30.c | 228 +++++++++ common/I2C/SGP30.h | 39 ++ common/I2C/USI_TWI_Master.h | 7 +- common/OWDS18B20_DS2438.S | 16 +- common/OWDS2438.S | 1 + common/OWDS2438_DS2438.S | 70 ++- common/OWDS2450.S | 2 +- common/OWSet_ATTINYX4.s | 2 +- 38 files changed, 2503 insertions(+), 424 deletions(-) create mode 100644 DS2450_APDS9960/DS2450_APDS9960.atsln create mode 100644 DS2450_APDS9960/DS2450_APDS9960.c create mode 100644 DS2450_APDS9960/DS2450_APDS9960.cproj create mode 100644 DS2450_IAQCORE/DS2450_IAQCORE.atsln create mode 100644 DS2450_IAQCORE/DS2450_IAQCORE.c create mode 100644 DS2450_IAQCORE/DS2450_IAQCORE.cproj create mode 100644 common/I2C/APDS9960.c create mode 100644 common/I2C/APDS9960.h create mode 100644 common/I2C/BME680.c create mode 100644 common/I2C/BME680.h create mode 100644 common/I2C/IAQCORE.c create mode 100644 common/I2C/IAQCORE.h create mode 100644 common/I2C/SGP30.c create mode 100644 common/I2C/SGP30.h diff --git a/DS18B20_BMP280/DS18B20_BMP280.cproj b/DS18B20_BMP280/DS18B20_BMP280.cproj index 25b04ce..3acd3b5 100644 --- a/DS18B20_BMP280/DS18B20_BMP280.cproj +++ b/DS18B20_BMP280/DS18B20_BMP280.cproj @@ -34,7 +34,7 @@ - + @@ -152,4 +152,4 @@ - + \ No newline at end of file diff --git a/DS18B20_CDM7160/DS18B20_CDM7160.atsln b/DS18B20_CDM7160/DS18B20_CDM7160.atsln index bb4e41c..e205eb6 100644 --- a/DS18B20_CDM7160/DS18B20_CDM7160.atsln +++ b/DS18B20_CDM7160/DS18B20_CDM7160.atsln @@ -3,7 +3,7 @@ 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}") = "DS18B20_CDM7160", "DS18B20_CDM7160.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}" +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_CDM7160", "DS18B20_CDM7160.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,10 +11,10 @@ Global Release|AVR = Release|AVR EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR - {7A5672FE-8226-4158-B931-E1F36B9A8858}.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/DS18B20_CDM7160/DS18B20_CDM7160.c b/DS18B20_CDM7160/DS18B20_CDM7160.c index b46797c..1c18216 100644 --- a/DS18B20_CDM7160/DS18B20_CDM7160.c +++ b/DS18B20_CDM7160/DS18B20_CDM7160.c @@ -47,7 +47,7 @@ extern void EXTERN_SLEEP(); uint8_t owid[8]={0x28, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x77, 0x6B};/**/ -uint8_t config_info[26]={10,13, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x02,16,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; +uint8_t config_info[26]={10,21, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x02,16,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; #if (owid>128) #error "Variable not correct" @@ -76,7 +76,7 @@ uint8_t max_adr=0; typedef union { volatile uint8_t bytes[8]; struct { - uint16_t temp; //0 + int16_t temp; //0 uint8_t TH; //2 uint8_t TL; //3 uint8_t config; //4 @@ -95,6 +95,8 @@ volatile pack_t pack; int main(void){ + PORTB&=~(1<(PBR+1)) { wdcounter=0; //PORTB|=(1<>4; - uint8_t af=0; + volatile int16_t l=(int16_t)CDM7160getCO2()-1280; + int16_t w=l; + int8_t t8=w/16; + int8_t af=0; if (t8>pack.TH) af=1; if (t8<=pack.TL) af=1; cli(); diff --git a/DS18B20_CDM7160/DS18B20_CDM7160.cproj b/DS18B20_CDM7160/DS18B20_CDM7160.cproj index 9ae17e6..228ac1d 100644 --- a/DS18B20_CDM7160/DS18B20_CDM7160.cproj +++ b/DS18B20_CDM7160/DS18B20_CDM7160.cproj @@ -1,10 +1,10 @@  - + 2.0 7.0 com.Atmel.AVRGCC8.C - {7a5672fe-8226-4158-b931-e1f36b9a8858} + dce6c7e3-ee26-4d79-826b-08594b9ad897 ATtiny84A none Executable @@ -12,64 +12,37 @@ $(MSBuildProjectName) .elf $(MSBuildProjectDirectory)\$(Configuration) - DS18B20_MAX44009 + DS18B20_CDM7160 DS18B20_CDM7160 - DS18B20_MAX44009 + DS18B20_CDM7160 Native true false true true - 0x20000000 + true - exception_table + 2 - 1 + 0 - - - - - - - - - + + + + + + + + + - com.atmel.avrdbg.tool.atmelice - - - - - debugWIRE - - com.atmel.avrdbg.tool.atmelice - J41800000789 - Atmel-ICE - - debugWIRE - - - - - - - - com.atmel.avrdbg.tool.simulator - - - Simulator - - - J41800000789 - 0x1E930C - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\gcc\dev\attiny84a" + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\gcc\dev\attiny84a" True True True @@ -79,18 +52,17 @@ True - DEBUG + NDEBUG - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + %24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include - Optimize (-O1) + Optimize for size (-Os) True True - Default (-g2) True @@ -99,17 +71,16 @@ - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + %24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include - Default (-Wa,-g) - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\gcc\dev\attiny84a" + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\gcc\dev\attiny84a" True True True @@ -124,7 +95,7 @@ - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + %24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include Optimize (-O1) @@ -139,7 +110,7 @@ - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + %24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include Default (-Wa,-g) @@ -151,14 +122,14 @@ compile CDM7160.c - - compile - OWDS18B20.S - compile USI_TWI_Master.c + + compile + OWDS18B20.S + compile diff --git a/DS18B20_MAX44009/DS18B20_MAX44009.cproj b/DS18B20_MAX44009/DS18B20_MAX44009.cproj index ae5ad14..a63a3cf 100644 --- a/DS18B20_MAX44009/DS18B20_MAX44009.cproj +++ b/DS18B20_MAX44009/DS18B20_MAX44009.cproj @@ -34,7 +34,7 @@ - + @@ -67,81 +67,81 @@ - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include - - - Default (-Wa,-g) - + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + + + Default (-Wa,-g) + - -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\gcc\dev\attiny84a" - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include - - - Optimize (-O1) - True - True - Default (-g2) - True - - - libm - - - - - %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include - - - Default (-Wa,-g) - + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + + + Default (-Wa,-g) + diff --git a/DS18B20_MAX44009_DS2438_SHT/DS18B20_DS2438.c b/DS18B20_MAX44009_DS2438_SHT/DS18B20_DS2438.c index c7ff34c..4e8d28b 100644 --- a/DS18B20_MAX44009_DS2438_SHT/DS18B20_DS2438.c +++ b/DS18B20_MAX44009_DS2438_SHT/DS18B20_DS2438.c @@ -207,9 +207,9 @@ int main(void){ sei(); //DDRB|=(1<1 - - - - - - - - - + + + + + + + + + com.atmel.avrdbg.tool.atmelice @@ -44,13 +44,13 @@ 125000 - ISP + debugWIRE com.atmel.avrdbg.tool.atmelice J41800000789 Atmel-ICE - ISP + debugWIRE diff --git a/DS18B20_Thermocouble/convthermocouple.py b/DS18B20_Thermocouble/convthermocouple.py index c11c3dd..2d17bde 100644 --- a/DS18B20_Thermocouble/convthermocouple.py +++ b/DS18B20_Thermocouble/convthermocouple.py @@ -1,4 +1,4 @@ -fi=open("Typ-J.csv","r") +fi=open("Typ-K.csv","r") lastv=0 v=0 lastt=0 @@ -7,25 +7,36 @@ rs="" wc=0 for l in fi.readlines(): #print(l) + l=l.replace(",",".") ll=l.split(";") i=0 for n in ll[1:10]: - s=ll[0]+"."+str(i) + s=ll[0][:-1]+""+str(i) lastv=v lastt=t v=float(n) t=float(s) if (int(v)!=int(lastv)): - interp=lastt+(t-lastt)/(v-lastv)*(int(v)-lastv) - print int(v),interp + #print v,lastv + #print t,lastt + if (lastt<0): + interp=lastt+(t-lastt)/(v-lastv)*(int(v-1)-lastv) + #print (t-lastt)/(v-lastv)*(int(v-1)-lastv) + print int(v-1),interp + else: + interp=lastt+(t-lastt)/(v-lastv)*(int(v)-lastv) + #print (t-lastt)/(v-lastv)*(int(v)-lastv) + print int(v),interp rs=rs+", %f" %(interp) wc=wc+1 - if (v==0): + if (v<=-6): interp=lastt+(t-lastt)/(v-lastv)*(int(v)-lastv) print int(v),interp - rs="{0" - wc=1 - + rs="{" + wc=0 + if (v==0): + rs=rs+", %f" %(0) + wc=wc+1; i=i+1 print rs+"};" print wc \ No newline at end of file diff --git a/DS18B20_Thermocouble_DS2438_SHT/DS18B20_DS2438.c b/DS18B20_Thermocouble_DS2438_SHT/DS18B20_DS2438.c index 3cf6053..4927b99 100644 --- a/DS18B20_Thermocouble_DS2438_SHT/DS18B20_DS2438.c +++ b/DS18B20_Thermocouble_DS2438_SHT/DS18B20_DS2438.c @@ -45,13 +45,16 @@ extern void OWINIT(); extern void EXTERN_SLEEP(); -const float k_rs[54] PROGMEM ={0.000000,24.125000,48.585366,72.731707,96.829268,121.097561,145.700000,170.600000,195.650000,220.625000,245.365854,269.853659,294.119048,318.195122,342.166667,366.000000,389.761905,413.428571,437.023810,460.558140,484.047619,507.511628,530.976190,554.418605,577.883721,601.395349,624.952381,648.571429,672.285714,696.073171,719.976190,744.000000,768.146341,792.439024,816.853659,841.414634,866.125000,890.975000,916.000000,941.179487,966.525000,992.025641,1017.717949,1043.589744,1069.657895,1095.945946,1122.432432,1149.184211,1176.189189,1203.472222,1231.083333,1259.000000,1287.285714,1315.941176}; +//const float k_rs[54] PROGMEM ={0.000000,24.125000,48.585366,72.731707,96.829268,121.097561,145.700000,170.600000,195.650000,220.625000,245.365854,269.853659,294.119048,318.195122,342.166667,366.000000,389.761905,413.428571,437.023810,460.558140,484.047619,507.511628,530.976190,554.418605,577.883721,601.395349,624.952381,648.571429,672.285714,696.073171,719.976190,744.000000,768.146341,792.439024,816.853659,841.414634,866.125000,890.975000,916.000000,941.179487,966.525000,992.025641,1017.717949,1043.589744,1069.657895,1095.945946,1122.432432,1149.184211,1176.189189,1203.472222,1231.083333,1259.000000,1287.285714,1315.941176}; +const float k_rs[61] PROGMEM ={ -212.538462, -166.260870, -124.892857, -97.562500, -66.888889, -34.157895, 0.000000, 24.125000, 48.585366, 72.731707, 96.829268, 121.097561, 145.700000, 170.600000, 195.650000, 220.625000, 245.365854, 269.853659, 294.119048, 318.192771, 342.166667, 366.000000, 389.761905, 413.428571, 437.023810, 460.558140, 484.047619, 507.511628, 530.976190, 554.418605, 577.883721, 601.395349, 624.952381, 648.571429, 672.285714, 696.073171, 719.976190, 744.000000, 768.146341, 792.439024, 816.853659, 841.414634, 866.125000, 890.975000, 916.000000, 941.179487, 966.525000, 992.025641, 1017.717949, 1043.589744, 1069.657895, 1095.945946, 1122.432432, 1149.173333, 1176.189189, 1203.472222, 1231.083333, 1259.000000, 1287.285714, 1315.941176, 1344.941176}; +#define k_ofs 6 + //const float j_rs[70] PROGMEM ={0, 18.302913, 34.830476, 50.783019, 70.653704, 90.505455, 110.341818, 130.165455, 149.163636, 160.791071, 180.596364, 200.398214, 220.200000, 240.000000, 250.882883, 270.603636, 290.409091, 310.216364, 330.025455, 342.472727, 360.649091, 380.461818, 400.275000, 420.087273, 435.275676, 450.703636, 470.503636, 490.298214, 510.082456, 523.486726, 540.621053, 560.370175, 580.105172, 591.979487, 610.527119, 630.213559, 644.601653, 660.534426, 680.168852, 690.787097, 710.391935, 729.123810, 740.559375, 760.126562, 770.684615, 790.235385, 800.782812, 820.331250, 834.681250, 850.446032, 870.017460, 880.600000, 900.196774, 911.099187, 930.432787, 950.073333, 960.728333, 980.396667, 1000.078333, 1010.772881, 1030.475862, 1050.187931, 1065.717241, 1080.631034, 1100.358621, 1120.089655, 1131.840000,1150.556897, 1170.294737, 1190.035088}; double gettemp_rs(double V) { - uint8_t iv=(uint8_t)(V); + uint8_t iv=(uint8_t)(V+k_ofs); float t0=pgm_read_float(&(k_rs[iv])); float t1=pgm_read_float(&(k_rs[iv+1])); - return t0+(t1-t0)/1*(V-iv); + return t0+(t1-t0)/1*((V+k_ofs)-iv); } @@ -161,11 +164,17 @@ volatile pack2_t pack2; volatile double V,ktemp; -uint16_t ADmess() { - ADMUX=0b10101101; +double ADmess() { + ADMUX=0b10101101; //PA2 + //PA1 - ADCSRA|=(1<>4; - uint8_t af=0; + int16_t w=htemp; + int8_t t8=w>>4; + int8_t af=0; if (t8>pack1.TH) af=1; if (t8<=pack1.TL) af=1; cli(); diff --git a/DS18B20_Thermocouble_DS2438_SHT/DS18B20_Thermocouble_DS2438_SHT.cproj b/DS18B20_Thermocouble_DS2438_SHT/DS18B20_Thermocouble_DS2438_SHT.cproj index 0fc1554..738bf15 100644 --- a/DS18B20_Thermocouble_DS2438_SHT/DS18B20_Thermocouble_DS2438_SHT.cproj +++ b/DS18B20_Thermocouble_DS2438_SHT/DS18B20_Thermocouble_DS2438_SHT.cproj @@ -28,15 +28,15 @@ 1 - - - - - - - - - + + + + + + + + + com.atmel.avrdbg.tool.atmelice diff --git a/DS18B20_VOC_DS2438_SHT direct/DS18B20_DS2438.c b/DS18B20_VOC_DS2438_SHT direct/DS18B20_DS2438.c index 4448c39..5b3461c 100644 --- a/DS18B20_VOC_DS2438_SHT direct/DS18B20_DS2438.c +++ b/DS18B20_VOC_DS2438_SHT direct/DS18B20_DS2438.c @@ -63,6 +63,7 @@ extern uint8_t gcontrol; extern uint8_t reset_indicator; extern uint8_t alarmflag; volatile uint8_t wdcounter=1; +extern uint8_t cpsp; #if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) @@ -74,8 +75,7 @@ ISR(WATCHDOG_vect) { if (reset_indicator==1) reset_indicator++; else if (reset_indicator==2) mode=0; - - } +} typedef union { @@ -114,11 +114,12 @@ ISR(WATCHDOG_vect) { union{ uint8_t page3[8]; //25 struct { + uint8_t free; uint16_t R0; uint16_t VS; uint8_t cmode; int16_t ip; - uint8_t free; + }; }; union{ @@ -130,7 +131,19 @@ ISR(WATCHDOG_vect) { uint16_t r_week_max; }; }; - uint8_t page5[8]; //41 + union{ + uint8_t page5[8]; //41 + struct { + uint8_t codeVOC; // immer 0x37 nach Neustart + uint8_t days_of_r0; //Anzahl der Tage fuer die r0 ermittelt wird + int8_t corr_VOC_mult; //r0 corr + int8_t corr_VOC_div; + uint16_t vv3; + uint8_t time_corr; //Wiregate; + uint8_t reset_code; + }; + uint16_t page5d[4]; + }; uint8_t page6[8]; //49 uint8_t page7[8]; //57 @@ -152,7 +165,7 @@ ISR(WATCHDOG_vect) { volatile double l; - uint16_t weekmaxarr[8]; + uint16_t weekmaxarr[33]; //Kompensieren der Abhänigkeit von RS/RO von Temperatur und Luftfeuchte inline double interp(double t, double h) { @@ -190,11 +203,15 @@ ISR(WATCHDOG_vect) { } + #define EEPROM_R0 0 #define EEPROM_R0d 2 #define EEPROM_R0w 4 #define EEPROM_dol 6 - + #define EEPROM_CODE_DAYOFR0 8 + #define EEPROM_CORR 10 + #define EEPROM_FREE 12 + #define EEPROM_TCORR_RESET 14 uint16_t readEEPROM(uint8_t addr,uint16_t def) { uint16_t hr; @@ -254,6 +271,7 @@ ISR(WATCHDOG_vect) { pack1.rr00=0; pack1.rr10=0x10; + pack2.page3[0]=0xF1; pack2.cmode=0; pack2.R0=readEEPROM(EEPROM_R0,1); R0=pack2.R0/100.0; @@ -262,10 +280,17 @@ ISR(WATCHDOG_vect) { pack2.r_week_max=readEEPROM(EEPROM_R0w,1); pack2.tol_d=readEEPROM(EEPROM_dol,0); pack2.tol_s8=0; //Tag faengt mit Einschalten an - for(uint8_t i=0;i<7;i++) { + + pack2.page5d[0]=readEEPROM(EEPROM_CODE_DAYOFR0,0x0437); + pack2.page5d[1]=readEEPROM(EEPROM_CORR,0x0101); + pack2.page5d[2]=readEEPROM(EEPROM_FREE,0x0); + pack2.page5d[3]=readEEPROM( EEPROM_TCORR_RESET,0x0005); + + for(uint8_t i=0;i0) { //8s pack2.tol_s8++; @@ -306,8 +359,8 @@ ISR(WATCHDOG_vect) { pack2.tol_s8=0; pack2.tol_d++; //rund 180 Jahre :-) pack2.r_week_max=0; - weekmaxarr[7]=pack2.r_day_max; - for(uint8_t i=0;i<7;i++) { + weekmaxarr[pack2.days_of_r0]=pack2.r_day_max; + for(uint8_t i=0;ipack2.r_week_max) pack2.r_week_max=weekmaxarr[i]; @@ -330,8 +383,10 @@ ISR(WATCHDOG_vect) { getSHT2xHumTemp(&temperatureC,&humidityRH); ip=interp(temperatureC,humidityRH); pack2.ip=ip*1000; - double RH=calibr_hum(temperatureC,-0.2,humidityRH)*10.0; - double TC =temperatureC *10.0-2; + //double RH=calibr_hum(temperatureC,-0.2,humidityRH)*10.0; + //double TC =temperatureC *10.0-2; + double RH=humidityRH*10.0; + double TC=temperatureC*10.0; if (testSW()) { @@ -387,9 +442,17 @@ ISR(WATCHDOG_vect) { pack2.r_day_max=l*100; } } else if (l0) { //8s pack2.tol_s8++; if (pack2.tol_s8>(10000)) {//10800 ist theortisch der Tag aber meistens zu lang pack2.tol_s8=0; pack2.tol_d++; //rund 180 Jahre :-) pack2.r_week_max=0; - weekmaxarr[7]=pack2.r_day_max; - for(uint8_t i=0;i<7;i++) { + weekmaxarr[pack2.days_of_r0]=pack2.r_day_max; + for(uint8_t i=0;ipack2.r_week_max) pack2.r_week_max=weekmaxarr[i]; } - if (pack2.tol_d>7) { + if (pack2.tol_d>pack2.days_of_r0) { pack2.R0=pack2.r_week_max; } else { pack2.R0=pack2.r_day_max; } //R0=//R0-0.5*(pack2.R0/100-R0); - R0=R0-(R0-pack2.R0/100.0)*0.5 ; + R0=pack2.R0/100.0; pack2.R0=R0*100; writeEEPROM(EEPROM_R0,pack2.R0); writeEEPROM(EEPROM_R0d,pack2.r_day_max); //Maximum des Tages @@ -401,9 +441,17 @@ int main(void){ pack2.r_day_max=l*100; } } else if (l1 - - - - - - - - - + + + + + + + + + com.atmel.avrdbg.tool.atmelice @@ -57,71 +57,72 @@ - -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 + + + __4MHZ__ + + + + + %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) - + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + __4MHZ__ + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + Default (-Wa,-g) + @@ -129,9 +130,9 @@ compile calibr.c - + compile - SHT3X.c + SHT3x.c compile diff --git a/DS2438_VOC_DS2438_SHT_Wiregate/DS2438_DS2438.c b/DS2438_VOC_DS2438_SHT_Wiregate/DS2438_DS2438.c index 00a58ef..05b8a28 100644 --- a/DS2438_VOC_DS2438_SHT_Wiregate/DS2438_DS2438.c +++ b/DS2438_VOC_DS2438_SHT_Wiregate/DS2438_DS2438.c @@ -63,6 +63,7 @@ extern uint8_t gcontrol; extern uint8_t reset_indicator; extern uint8_t alarmflag; volatile uint8_t wdcounter=1; +extern uint8_t cpsp2; typedef union { @@ -125,23 +126,50 @@ 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 - uint8_t page5[8]; //41 - uint8_t page6[8]; //49 + union{ + uint8_t page4[8]; //33 + struct { + uint16_t tol_s8; + uint16_t tol_d; + uint16_t r_day_max; + uint16_t r_week_max; + }; + }; + union{ + uint8_t page5[8]; //41 + struct { + uint8_t codeVOC; // immer 0x37 nach Neustart + uint8_t days_of_r0; //Anzahl der Tage fuer die r0 ermittelt wird + int8_t corr_VOC_mult; //r0 corr + int8_t corr_VOC_div; + uint16_t vv3; + uint8_t time_corr; //Wiregate; + uint8_t reset_code; + }; + uint16_t page5d[4]; + }; + union{ + uint8_t page6[8]; //25 + struct { + uint16_t R0; + uint16_t VS; + uint8_t cmode; + int16_t ip; + uint8_t free; + }; + }; uint8_t page7[8]; //57 - #endif }; } pack2_t; volatile pack2_t pack2; -#define TIME_CORR 5 -volatile int8_t time_corr_count=TIME_CORR; +//#define TIME_CORR 3 +volatile int8_t time_corr_count;//=TIME_CORR; #if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) ISR(WATCHDOG_vect) { @@ -156,7 +184,7 @@ ISR(WATCHDOG_vect) { if (time_corr_count<=0) { //wdcounter++; pack1.etm+=1; - time_corr_count=TIME_CORR; + time_corr_count=pack2.time_corr; } /* if ((pack1.page1[0]&0x0F)==0) { pack1.etm+=2; @@ -174,15 +202,6 @@ ISR(WATCHDOG_vect) { -uint16_t pR0; -uint16_t pVS; -uint8_t pcmode; -int16_t pip; - -uint16_t ptol_s8; -uint16_t ptol_d; -uint16_t pr_day_max; -uint16_t pr_week_max; volatile int16_t DS2438_1_TEMP; @@ -202,7 +221,7 @@ uint8_t max_adr=0; #define CH0_CH1 MAX1164x_C_SCAN0 //|MAX1164x_C_CS0 -uint16_t weekmaxarr[8]; +uint16_t weekmaxarr[33]; //Kompensieren der Abhänigkeit von RS/RO von Temperatur und Luftfeuchte inline double interp(double t, double h) { @@ -243,6 +262,10 @@ int testSW(void) { #define EEPROM_R0d 2 #define EEPROM_R0w 4 #define EEPROM_dol 6 +#define EEPROM_CODE_DAYOFR0 8 +#define EEPROM_CORR 10 +#define EEPROM_FREE 12 +#define EEPROM_TCORR_RESET 14 uint16_t readEEPROM(uint8_t addr,uint16_t def) { @@ -295,18 +318,25 @@ int main(void){ pack1.temp=0x0550; pack2.page3[0]=0xF1; - pcmode=0; - pR0=readEEPROM(EEPROM_R0,1); - R0=pR0/100.0; + pack2.cmode=0; + pack2.R0=readEEPROM(EEPROM_R0,1); + R0=pack2.R0/100.0; - pr_day_max=readEEPROM(EEPROM_R0d,1); - pr_week_max=readEEPROM(EEPROM_R0w,1); - ptol_d=readEEPROM(EEPROM_dol,0); - ptol_s8=0; //Tag faengt mit Einschalten an - for(uint8_t i=0;i<7;i++) { - weekmaxarr[i]=pr_week_max; - } + pack2.r_day_max=readEEPROM(EEPROM_R0d,1); + pack2.r_week_max=readEEPROM(EEPROM_R0w,1); + pack2.tol_d=readEEPROM(EEPROM_dol,0); + pack2.tol_s8=0; //Tag faengt mit Einschalten an + + pack2.page5d[0]=readEEPROM(EEPROM_CODE_DAYOFR0,0x0437); + pack2.page5d[1]=readEEPROM(EEPROM_CORR,0x0101); + pack2.page5d[2]=readEEPROM(EEPROM_FREE,0x0); + pack2.page5d[3]=readEEPROM( EEPROM_TCORR_RESET,0x0005); + time_corr_count=pack2.time_corr; + + for(uint8_t i=0;i0) { //8s - ptol_s8++; + pack2.tol_s8++; //pack1.dis+=8; //pack1.eoc+=8; - if (ptol_s8>(10000)) {//10800 ist theortisch der Tag aber meistens zu lang - ptol_s8=0; - ptol_d++; //rund 180 Jahre :-) - pr_week_max=0; - weekmaxarr[7]=pr_day_max; - for(uint8_t i=0;i<7;i++) { + if (pack2.tol_s8>(10000)) {//10800 ist theortisch der Tag aber meistens zu lang + pack2.tol_s8=0; + pack2.tol_d++; //rund 180 Jahre :-) + pack2.r_week_max=0; + weekmaxarr[pack2.days_of_r0]=pack2.r_day_max; + for(uint8_t i=0;ipr_week_max) pr_week_max=weekmaxarr[i]; + if (weekmaxarr[i]>pack2.r_week_max) pack2.r_week_max=weekmaxarr[i]; } - if (ptol_d>7) { - pR0=pr_week_max; + if (pack2.tol_d>pack2.days_of_r0) { + pack2.R0=pack2.r_week_max; } else { - pR0=pr_day_max; + pack2.R0=pack2.r_day_max; } //R0=//R0-0.5*(pack2.R0/100-R0); - R0=R0-(R0-pR0/100.0)*0.5 ; - pR0=R0*100; - writeEEPROM(EEPROM_R0,pR0); - writeEEPROM(EEPROM_R0d,pr_day_max); //Maximum des Tages - writeEEPROM(EEPROM_R0w,pr_week_max); //Maximum der Letzten 7 Tage - writeEEPROM(EEPROM_dol,ptol_d); //Anzahl der Betriebstage - pr_day_max=0; + //R0=R0-(R0-pack2.R0/100.0)*0.5 ; + R0=pack2.R0/100.0; + pack2.R0=R0*100; + writeEEPROM(EEPROM_R0,pack2.R0); + writeEEPROM(EEPROM_R0d,pack2.r_day_max); //Maximum des Tages + writeEEPROM(EEPROM_R0w,pack2.r_week_max); //Maximum der Letzten 7 Tage + writeEEPROM(EEPROM_dol,pack2.tol_d); //Anzahl der Betriebstage + pack2.r_day_max=0; } if (startup!=0) startup--; getSHT2xHumTemp(&temperatureC,&humidityRH); ip=interp(temperatureC,humidityRH); - pip=ip*1000; + pack2.ip=ip*1000; double RH=calibr_hum(temperatureC,-0.2,humidityRH)*10.0; double TC =temperatureC *10.0-2; @@ -406,27 +445,27 @@ int main(void){ //l=mr/2.0*2.048/4096; // l maximal 2 mr max 4096 //mr 2V=8000 - if (pcmode) { //cmode=0 V 0..2 V cmode=1 V 1.5..3.5V + if (pack2.cmode) { //cmode=0 V 0..2 V cmode=1 V 1.5..3.5V //l+=1.5; //Spannung real mr+=6000; } //if (l>1.8) { if (mr>7200) { - if (pcmode==0) { + if (pack2.cmode==0) { MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_CH1); - pcmode=1; + pack2.cmode=1; } } //if (l<1.6) { if (mr<6400) { - if (pcmode==1) { + if (pack2.cmode==1) { MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M); - pcmode=0; + pack2.cmode=0; } } - pVS=mr*5/2; + pack2.VS=mr*5/2; l=mr/4000.0; l=( 3/l- 1) *30; pack2.current=l*100; @@ -436,17 +475,18 @@ int main(void){ if (startup==0){ if (l>R0) { R0=l; - pR0=R0*100; - writeEEPROM(EEPROM_R0,pR0); + pack2.R0=R0*100; + writeEEPROM(EEPROM_R0,pack2.R0); } - if (l*100>pr_day_max) { - pr_day_max=l*100; + if (l*100>pack2.r_day_max) { + pack2.r_day_max=l*100; } } else if (l - - - - - - - - - + + + + + + + + + diff --git a/DS2450/OWDS2450.S b/DS2450/OWDS2450.S index 1d81abd..61a1dad 100644 --- a/DS2450/OWDS2450.S +++ b/DS2450/OWDS2450.S @@ -1,5 +1,5 @@ -// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de +// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -33,6 +33,7 @@ #define _CHANGEABLE_ID_ #define _ZERO_POLLING_ +#define __4MHZ__ #include "../common/OWConfig.s" #include "../common/OWCRC16.s" diff --git a/DS2450_APDS9960/DS2450_APDS9960.atsln b/DS2450_APDS9960/DS2450_APDS9960.atsln new file mode 100644 index 0000000..06d2247 --- /dev/null +++ b/DS2450_APDS9960/DS2450_APDS9960.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_APDS9960", "DS2450_APDS9960.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_APDS9960/DS2450_APDS9960.c b/DS2450_APDS9960/DS2450_APDS9960.c new file mode 100644 index 0000000..4ded72e --- /dev/null +++ b/DS2450_APDS9960/DS2450_APDS9960.c @@ -0,0 +1,283 @@ + +// Copyright (c) 2017, 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/APDS9960.h" + +extern void OWINIT(); +extern void EXTERN_SLEEP(); + +uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x23, 0x20};/**/ +//uint8_t config_info[26]={0x03,13,0x03,13,0x03,13,0x3,15,0x02,20,20,20,20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; +uint8_t config_info[26]={16,15,17,15,18,15,3,15,0x02,23,23,23,23,0x00,0x00,0x00,0x00,0x00,0x00,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; + + +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; + + +uint16_t light[4]; +double rlight[4]; +uint8_t gain=2; +uint8_t atime=192; +//uint8_t atime=255; +double r_gain; +double r_atime; + +void getLight(uint8_t setparameterr) { + if (setparameterr) { + r_gain=(1<<(2*gain)); + r_atime=(256.0-atime)*2.78; + APDS9960setGain(gain); + APDS9960setATime(atime); + _delay_ms(700); + } + APDS9960getRGBC(&light[0],&light[1],&light[2],&light[3]); +} + + + + +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; + + PORTA=0xFF; + PORTB=0xFF; + + OWINIT(); + + MCUCR &=~(1<0xF000) { + //while (light[3]>900) { + if (gain!=0) { + gain--; + getLight(1); + } else break; + } + if (light[3]<0x2222) { + //if (light[3]<0x22) { + if (gain<3) { + gain++; + getLight(1); + } + + } + for(uint8_t i=0;i<4;i++) { + rlight[i]=(double)light[i]/r_atime/r_gain*70.0; + rlight[i]=(log(rlight[i])*1000)+32767.0; + } + cli();pack.A=rlight[0];sei(); + //cli();pack.A=r_gain;sei(); + 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.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_APDS9960 + DS2450 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice + J41800000789 + 0x1E930C + + + + + debugWIRE + + com.atmel.avrdbg.tool.atmelice + J41800000789 + Atmel-ICE + + debugWIRE + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + + + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + + + Default (-Wa,-g) + + + + + + compile + APDS9960.c + + + compile + USI_TWI_Master.c + + + compile + + + compile + + + + \ No newline at end of file diff --git a/DS2450_IAQCORE/DS2450_IAQCORE.atsln b/DS2450_IAQCORE/DS2450_IAQCORE.atsln new file mode 100644 index 0000000..cd34225 --- /dev/null +++ b/DS2450_IAQCORE/DS2450_IAQCORE.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_IAQCORE", "DS2450_IAQCORE.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_IAQCORE/DS2450_IAQCORE.c b/DS2450_IAQCORE/DS2450_IAQCORE.c new file mode 100644 index 0000000..cee219c --- /dev/null +++ b/DS2450_IAQCORE/DS2450_IAQCORE.c @@ -0,0 +1,232 @@ + +// Copyright (c) 2017, 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/IAQCORE.h" + +extern void OWINIT(); +extern void EXTERN_SLEEP(); + +uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/ +uint8_t config_info[26]={0x06,13,0x06,13,0x06,13,0x06,13,0x02,20,20,20,20,0x00,0x00,0x00,0x00,0x00,0x00,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; + + +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; + + + +IAQCORE_Data_t IAQCORE_Data; + + +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; + OWINIT(); + + MCUCR &=~(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_IAQCORE + DS2450 + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 1 + + + + + + + + + + + + + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + + + + + + + + + -mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\gcc\dev\attiny84a" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATtiny_DFP\1.0.79\include + + + Default (-Wa,-g) + + + + + + compile + IAQCORE.c + + + compile + USI_TWI_Master.c + + + compile + + + compile + + + + \ No newline at end of file diff --git a/common/I2C/APDS9960.c b/common/I2C/APDS9960.c new file mode 100644 index 0000000..92df22e --- /dev/null +++ b/common/I2C/APDS9960.c @@ -0,0 +1,138 @@ +// 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 "USI_TWI_Master.h" +#include "APDS9960.h" + +#define WC 0b01110010 +#define RC 0b01110011 + +int8_t initAPDS9960() { + I2c_StartCondition(); + I2c_WriteByte(WC); + I2c_WriteByte(0x80); + I2c_StartCondition(); + I2c_WriteByte (RC); + uint8_t b1 =I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + if (b1==0xFF) return 0; else { + I2c_StartCondition(); + I2c_WriteByte(WC); + I2c_WriteByte(0x80); + I2c_WriteByte(0x0B); //ALS Enable PowerON + I2c_StopCondition(); + } + return 1; +} +void APDS9960setATime(uint8_t ATime) { + I2c_StartCondition(); + I2c_WriteByte(WC); + I2c_WriteByte(0x81); + I2c_WriteByte(ATime); + I2c_StopCondition(); +} +void APDS9960setGain(uint8_t Gain) { + I2c_StartCondition(); + I2c_WriteByte(WC); + I2c_WriteByte(0x8F); + I2c_WriteByte(Gain&0x03); + I2c_StopCondition(); +} +uint8_t APDS9960getAVALID() {return 0;} +uint8_t APDS9960getASAT() {return 0;} + +void APDS9960getRGBC(uint16_t* R,uint16_t* G,uint16_t* B,uint16_t* C) { + I2c_StartCondition(); + I2c_WriteByte(WC); + I2c_WriteByte(0x94); + I2c_StartCondition(); + I2c_WriteByte (RC); + *C=I2c_ReadByte(ACK)|I2c_ReadByte(ACK)<<8; + *R=I2c_ReadByte(ACK)|I2c_ReadByte(ACK)<<8; + *G=I2c_ReadByte(ACK)|I2c_ReadByte(ACK)<<8; + *B=I2c_ReadByte(ACK)|I2c_ReadByte(NO_ACK)<<8; + I2c_StopCondition(); +} + + +/* +uint8_t checkMAX44009(uint8_t nr) { + volatile uint8_t b1; + nr=(nr<<1)&0x02f; + + I2c_StartCondition(); + I2c_WriteByte(0b10010100|nr); + I2c_WriteByte(0x03); + I2c_StartCondition(); + I2c_WriteByte (0b10010101|nr); + b1 =I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + return b1!=0xFF; + +} + + +double MAX44009getlux(uint8_t nr) { + volatile uint8_t b1,b2; + nr=(nr<<1)&0x02f; + + I2c_StartCondition(); + I2c_WriteByte(0b10010100|nr); + I2c_WriteByte(0x03); + I2c_StartCondition(); + I2c_WriteByte (0b10010101|nr); + b1 =I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + I2c_StartCondition(); + I2c_WriteByte(0b10010100|nr); + I2c_WriteByte(0x04); + I2c_StartCondition(); + I2c_WriteByte (0b10010101|nr); + b2 =I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + uint8_t exponent = (b1 & 0xF0) >> 4;// upper four bits of high byte register + uint8_t mantissa = (b1 & 0x0F) << 4;// lower four bits of high byte register = + // upper four bits of mantissa + mantissa += b2 & 0x0F; // lower four bits of low byte register = + // lower four bits of mantissa + + return (double)mantissa * (double)(1 << (uint16_t)exponent) * 0.045; + + + +} +*/ \ No newline at end of file diff --git a/common/I2C/APDS9960.h b/common/I2C/APDS9960.h new file mode 100644 index 0000000..a6ab18a --- /dev/null +++ b/common/I2C/APDS9960.h @@ -0,0 +1,45 @@ +#ifndef APDS9960_H +#define APDS9960_H +// 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. + +int8_t initAPDS9960(); +void APDS9960setATime(uint8_t ATime); +void APDS9960setGain(uint8_t Gain); +uint8_t APDS9960getAVALID(); +uint8_t APDS9960getASAT(); + +void APDS9960getRGBC(uint16_t* R,uint16_t* G,uint16_t* B,uint16_t* C); + + + +#endif \ No newline at end of file diff --git a/common/I2C/BME680.c b/common/I2C/BME680.c new file mode 100644 index 0000000..3f425ba --- /dev/null +++ b/common/I2C/BME680.c @@ -0,0 +1,436 @@ +// 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. +#ifdef __4MHZ__ +#define F_CPU 4000000UL +#else +#define F_CPU 8000000UL +#endif +#include + + +/** Array Index to Field data mapping for Calibration Data*/ +#define BME680_T2_LSB_REG (1) +#define BME680_T2_MSB_REG (2) +#define BME680_T3_REG (3) +#define BME680_P1_LSB_REG (5) +#define BME680_P1_MSB_REG (6) +#define BME680_P2_LSB_REG (7) +#define BME680_P2_MSB_REG (8) +#define BME680_P3_REG (9) +#define BME680_P4_LSB_REG (11) +#define BME680_P4_MSB_REG (12) +#define BME680_P5_LSB_REG (13) +#define BME680_P5_MSB_REG (14) +#define BME680_P7_REG (15) +#define BME680_P6_REG (16) +#define BME680_P8_LSB_REG (19) +#define BME680_P8_MSB_REG (20) +#define BME680_P9_LSB_REG (21) +#define BME680_P9_MSB_REG (22) +#define BME680_P10_REG (23) +#define BME680_H2_MSB_REG (25) +#define BME680_H2_LSB_REG (26) +#define BME680_H1_LSB_REG (26) +#define BME680_H1_MSB_REG (27) +#define BME680_H3_REG (28) +#define BME680_H4_REG (29) +#define BME680_H5_REG (30) +#define BME680_H6_REG (31) +#define BME680_H7_REG (32) +#define BME680_T1_LSB_REG (33) +#define BME680_T1_MSB_REG (34) +#define BME680_GH2_LSB_REG (35) +#define BME680_GH2_MSB_REG (36) +#define BME680_GH1_REG (37) +#define BME680_GH3_REG (38) + + +#include +#include + +#include "USI_TWI_Master.h" +#include "BME680.h" + +#define WC 0b11101100 +#define RC 0b11101101 +typedef union { + volatile uint8_t d[41]; + struct { + uint8_t fr1; + int16_t t2; + int8_t t3; + uint8_t fr2; //4 + uint16_t p1; + int16_t p2; //7 + int8_t p3; + uint8_t fr3; //10 + int16_t p4; + int16_t p5; + int8_t p7; + int8_t p6; + uint8_t fr4[2]; //17-18 + int16_t p8; + int16_t p9; + uint8_t p10; + uint8_t fr5; //24 + uint16_t h2_; //25 +26 + uint8_t h1_; //halb und halb 26+27 + int8_t h3; + int8_t h4; + int8_t h5; + uint8_t h6; + int8_t h7;//32 + uint16_t t1; + int16_t gh2; + int8_t gh1; + int8_t gh3; //38 + int8_t fr6;// 39; + int8_t fr7; //40; + uint16_t h2; //Berechnung + uint16_t h1; //Berechnung + int32_t t_fine; //Berechnung bei Temperaturmessung + uint8_t res_heat_range;/**bme680_bus_read( + bme680->dev_addr, + BME680_CALIB_I2C_ADDR_2, + (a_data_u8 + + BME680_CALIB_DATA_LENGTH_GAS), + BME680_CALIB_DATA_LENGTH); + + + + */ + + +void setup_read(uint8_t addr) { + I2c_StartCondition(); + I2c_WriteByte(WC); + I2c_WriteByte(addr); //Ctrl hum + I2c_StartCondition(); + I2c_WriteByte (RC); + +} + +void setup_write(uint8_t addr) { + I2c_StartCondition(); + I2c_WriteByte(WC); + I2c_WriteByte(addr); //Ctrl hum +} + + +uint8_t readone(uint8_t addr) { + setup_read(addr); + uint8_t b=I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + return b; +} + +void writeone(uint8_t addr,uint8_t b) { + setup_write(addr); + I2c_WriteByte(b); //Ctrl hum + I2c_StopCondition(); +} + +int8_t initBME680() { + uint8_t b1=readone(0xD0); + setup_read(BME680_CALIB_I2C_ADDR_1); + for(uint8_t i=0;i>4; + calib.res_heat_val=readone(0); + calib.range_switching_error=(readone(0x04)& 0xF0)>>4; + + + calib.h1 = (uint16_t)(((((uint16_t)calib.d[ BME680_H1_MSB_REG])) + << 4) | (calib.d[ BME680_H1_LSB_REG] &0x0F)); + calib.h2 = (uint16_t)(((((uint16_t)calib.d[ BME680_H2_MSB_REG])) + << 4) | ((calib.d[ BME680_H2_LSB_REG]) >> 4)); + + + /* + + I2c_StartCondition(); + I2c_WriteByte(WC); + I2c_WriteByte(0x72); //Ctrl hum + I2c_WriteByte(0x01); //1x oversembling hum + I2c_WriteByte(0x74); //Ctrl hum + I2c_WriteByte(0b01010101); //2x oversembling t - 16x oversemmping p - mode cont + I2c_StopCondition(); + + */ + calib.ltemp=25; + + return b1==0x61; + +} + + +const float lookup_k1_range[16] PROGMEM = { + 1, 1, 1, 1, 1,0.99, 1, 0.992, +1, 1, 0.998, 0.995, 1, 0.99, 1, 1}; +const float lookup_k2_range[16] PROGMEM = { + 8e6, 4e6, 2e6, 1e6,499500.4995, 248262.1648, 125000, 63004.03226, +31281.28128, 15625, 7812.5, 3906.25,1953.125,976.5625, 488.28125, 244.140625}; + +double bme680_compensate_gas_double(uint16_t gas_adc_u16, uint8_t gas_range_u8) +{ + double gas_res_d = 0; + + + + int8_t range_switching_error_val = 0; + + double var1 = 0; + float a1= pgm_read_float(&(lookup_k1_range[gas_range_u8])); + float a2= pgm_read_float(&(lookup_k2_range[gas_range_u8])); + + range_switching_error_val = calib.range_switching_error; + + + var1 = (1340.0 + (5.0 * range_switching_error_val))*a1; + gas_res_d = var1*a2/(gas_adc_u16-512.0+var1); + return gas_res_d; +} + + +void readBMP680(int16_t *T,uint16_t *H,uint32_t *P,uint16_t *G){ + + + + int32_t var1 ; + int32_t var2 ; + int32_t var3 ; + int32_t var4 ; + int32_t var5 ; + int32_t res_heat_x100 = 0; + uint8_t res_heat = 0; + uint16_t heater_temp_u16=350; + int16_t ambient_temp_s16=calib.ltemp; + if ((heater_temp_u16 >= 200) && (heater_temp_u16 <= 400)) { + var1 = (((int32_t)ambient_temp_s16 * + calib.gh3) / 10) << 8; + var2 = (calib.gh1 + 784) * + (((((calib.gh2 + 154009) * + heater_temp_u16 * 5) / 100) + 3276800) / 10); + var3 = var1 + (var2 >> 1); + var4 = (var3 / (calib.res_heat_range + 4)); + + var5 = (131 * calib.res_heat_val) + 65536; + + res_heat_x100 = (int32_t)(((var4 / var5) - 250) * 34); + res_heat = (uint8_t) ((res_heat_x100 + 50) / 100); + } + uint16_t duration=100; + uint8_t factor = 0; + + while ((duration) > 0x3F) { + (duration) = (duration) >> 2; + factor += 1; + } + (duration) = (duration) + (factor * 64); + + //I2c_WriteByte(0x74); //Ctrl hum + //I2c_WriteByte(0b01010101); //2x oversembling t - 16x oversemmping p - mode cont + // [71] <- 10; [72] <- 04; [73] <- 0C; [74] <- 91; [75] <- 00; + // [70] <- 00 [71] <- 10; [72] <- 04; [73] <- 0C; [74] <- 91; [75] <- 00; + setup_write(0x70); + I2c_WriteByte(0x00); + I2c_WriteByte(0x71); + I2c_WriteByte(0x10); + I2c_WriteByte(0x72); + I2c_WriteByte(0x04); + I2c_WriteByte(0x73); + I2c_WriteByte(0x0C); + I2c_WriteByte(0x74); + I2c_WriteByte(0x90); + I2c_WriteByte(0x75); + I2c_WriteByte(0x00); + + I2c_WriteByte(0x5A); + I2c_WriteByte(res_heat); + I2c_WriteByte(0x64); + I2c_WriteByte(duration); + I2c_StopCondition(); + + + writeone(0x74,0x91); + _delay_ms(1000); + + uint8_t bx=0x91; + while ((bx&0x01)==0x01) { + bx=readone(0x74); + _delay_ms(5); + } + + //volatile uint8_t rs=readone(0x2B); + uint32_t Th,Hh,Ph; + setup_read(0x1F); + Ph=I2c_ReadByte(ACK);Ph=Ph<<8; + Ph|=I2c_ReadByte(ACK);Ph=Ph<<4; + Ph|=I2c_ReadByte(ACK)>>4; + Th=I2c_ReadByte(ACK);Th=Th<<8; + Th|=I2c_ReadByte(ACK);Th=Th<<4; + Th|=I2c_ReadByte(ACK)>>4; + Hh=I2c_ReadByte(ACK);Hh=Hh<<8; + Hh|=I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + setup_read(0x2A); + volatile uint8_t g1=I2c_ReadByte(ACK); + volatile uint8_t g2=I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + *G=(((uint16_t)g1)<<2)|(g2>>6); + *P=*G; + *G= bme680_compensate_gas_double(*G,g2&0xF)/10.0; + + int32_t temp_comp = 0; + + var1 = ((int32_t)Th >> 3) - + ((int32_t)calib.t1 << 1); + var2 = (var1 * (int32_t)calib.t2) >> 11; + var3 = ((((var1 >> 1) * (var1 >> 1)) >> 12) * + ((int32_t)calib.t3 << 4)) >> 14; + calib.t_fine = var2 + var3; + temp_comp = ((calib.t_fine * 5) + 128) >> 8; + + int32_t temp_scaled = 0; + int32_t var6 = 0; + int32_t humidity_comp = 0; + + temp_scaled = (((int32_t)calib.t_fine * 5) + 128) >> 8; + var1 = (int32_t)Hh - + ((int32_t)((int32_t)calib.h1 << 4)) - + (((temp_scaled * (int32_t)calib.h3) / + ((int32_t)100)) >> 1); + + var2 = ((int32_t)calib.h2 * + (((temp_scaled * (int32_t)calib.h4) / + ((int32_t)100)) + (((temp_scaled * + ((temp_scaled * (int32_t)calib.h5) / + ((int32_t)100))) >> 6) / ((int32_t)100)) + (int32_t)(1 << 14))) >> 10; + + var3 = var1 * var2; + + var4 = ((((int32_t)calib.h6) << 7) + + ((temp_scaled * (int32_t)calib.h7) / + ((int32_t)100))) >> 4; + + var5 = ((var3 >> 14) * (var3 >> 14)) >> 10; + var6 = (var4 * var5) >> 1; + + humidity_comp = (var3 + var6) >> 12; + if (humidity_comp > BME680_MAX_HUMIDITY_VALUE) + humidity_comp = BME680_MAX_HUMIDITY_VALUE; + else if (humidity_comp < BME680_MIN_HUMIDITY_VALUE) + humidity_comp = BME680_MIN_HUMIDITY_VALUE; + + int32_t pressure_comp = 0;//int -> 5684 + + var1 = (((int32_t)calib.t_fine) >> 1) - (int32_t)64000; + var2 = ((((var1 >> 2) * (var1 >> 2)) >> 11) * + (int32_t)calib.p6) >> 2; + var2 = var2 + ((var1 * (int32_t)calib.p5) << 1); + var2 = (var2 >> 2) + ((int32_t)calib.p4 << 16); + var1 = (((((var1 >> 2) * (var1 >> 2)) >> 13) * + ((int32_t)calib.p3 << 5)) >> 3) + + (((int32_t)calib.p2 * var1) >> 1); + var1 = var1 >> 18; + var1 = (((int32_t)32768 + var1) * (int32_t)calib.p1) >> 15; + pressure_comp = (int32_t)1048576 - Ph; + pressure_comp = (int32_t)((pressure_comp - (var2 >> 12)) * ((uint32_t)3125)); + var4 = ((int32_t)1 << 31); + if (pressure_comp >= var4) + pressure_comp = ((pressure_comp / (uint32_t)var1) << 1); + else + pressure_comp = ((pressure_comp << 1) / (uint32_t)var1); + var1 = ((int32_t)calib.p9 * (int32_t)(((pressure_comp >> 3) * + (pressure_comp >> 3)) >> 13)) >> 12; + var2 = ((int32_t)(pressure_comp >> 2) * + (int32_t)calib.p8) >> 13; + var3 = ((int32_t)(pressure_comp >> 8) * (int32_t)(pressure_comp >> 8) * + (int32_t)(pressure_comp >> 8) * + (int32_t)calib.p10) >> 17; + + pressure_comp = (int32_t)(pressure_comp) + ((var1 + var2 + var3 + + ((int32_t)calib.p7 << 7)) >> 4); + + + + + + *T=(int16_t)temp_comp; + calib.ltemp=temp_comp/100; + //*P=pressure_comp; + *H=(uint16_t)(humidity_comp/10); + //*P=rs; + *T=g1; + *H=g2; + //*P= + + +} + diff --git a/common/I2C/BME680.h b/common/I2C/BME680.h new file mode 100644 index 0000000..159d3f3 --- /dev/null +++ b/common/I2C/BME680.h @@ -0,0 +1,46 @@ +#ifndef BME680_H +#define BME680_H +// 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. + +int8_t initBME680(); +void readBMP680(int16_t *T,uint16_t *H,uint32_t *P,uint16_t *G); +/*void APDS9960setATime(uint8_t ATime); +void APDS9960setGain(uint8_t Gain); +uint8_t APDS9960getAVALID(); +uint8_t APDS9960getASAT(); + +void APDS9960getRGBC(uint16_t* R,uint16_t* G,uint16_t* B,uint16_t* C); +*/ + + +#endif \ No newline at end of file diff --git a/common/I2C/IAQCORE.c b/common/I2C/IAQCORE.c new file mode 100644 index 0000000..357912d --- /dev/null +++ b/common/I2C/IAQCORE.c @@ -0,0 +1,57 @@ +// Copyright (c) 2017, 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 "USI_TWI_Master.h" +#include "IAQCORE.h" + + +uint8_t readIAQCORE(IAQCORE_Data_t *d) { + uint8_t *da=(uint8_t*)d; + I2c_StartCondition(); + I2c_WriteByte(0b10110101); + da[1]=I2c_ReadByte(ACK); + da[0]=I2c_ReadByte(ACK); + da[2]=I2c_ReadByte(ACK); + da[6]=I2c_ReadByte(ACK); + da[5]=I2c_ReadByte(ACK); + da[4]=I2c_ReadByte(ACK); + da[3]=I2c_ReadByte(ACK); + da[8]=I2c_ReadByte(ACK); + da[7]=I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + return 0; +} diff --git a/common/I2C/IAQCORE.h b/common/I2C/IAQCORE.h new file mode 100644 index 0000000..12c538b --- /dev/null +++ b/common/I2C/IAQCORE.h @@ -0,0 +1,44 @@ +#ifndef IAQCORE_H +#define IAQCORE_H +// 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. + +typedef struct { +uint16_t CO2; +int8_t state; +int32_t resistance; +uint16_t TVOC; +} IAQCORE_Data_t; + +uint8_t readIAQCORE(IAQCORE_Data_t *d); + +#endif \ No newline at end of file diff --git a/common/I2C/SGP30.c b/common/I2C/SGP30.c new file mode 100644 index 0000000..ee19d6a --- /dev/null +++ b/common/I2C/SGP30.c @@ -0,0 +1,228 @@ +// Copyright (c) 2017, 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. +#ifdef __4MHZ__ +#define F_CPU 4000000UL +#else +#define F_CPU 8000000UL +#endif +#include + + +#include +#include + +#include "USI_TWI_Master.h" +#include "SGP30.h" +//0x58 +#define WC 0b10110000 +#define RC 0b10110001 +#define CRC8_POLYNOMIAL 0x31 +#define CRC8_INIT 0xFF +#define CRC8_LEN 1 + + +uint8_t sensirion_common_generate_crc(uint8_t *data, uint8_t count) +{ + uint16_t current_byte; + uint8_t crc = CRC8_INIT; + uint8_t crc_bit; + + /* calculates 8-Bit checksum with given polynomial */ + for (current_byte = 0; current_byte < count; ++current_byte) { + crc ^= (data[current_byte]); + for (crc_bit = 8; crc_bit > 0; --crc_bit) { + if (crc & 0x80) + crc = (crc << 1) ^ CRC8_POLYNOMIAL; + else + crc = (crc << 1); + } + } + return crc; +} + +int8_t sensirion_common_check_crc(uint8_t *data, uint8_t count, uint8_t checksum) +{ + if (sensirion_common_generate_crc(data, count) != checksum) + return 0; + return 1; +} + +void readSGPXX(uint16_t com, uint8_t* data, uint8_t len) { + I2c_StartCondition(); + I2c_WriteByte(WC); + I2c_WriteByte(com>>8); //Ctrl hum + I2c_WriteByte(com&0x00FF); //Ctrl hum + _delay_ms(100); + I2c_StartCondition(); + I2c_WriteByte (RC); + for(uint8_t i=0;i>8); //Ctrl hum + I2c_WriteByte(com&0x00FF); //Ctrl hum + for(uint8_t i=0;i>8; + EECR |= (1<>8; //irgendwie werden die Werte vertauscht zwischen lesen und schreiben + b[4]=(uint16_t)b1&0x00FF; + b[5]=sensirion_common_generate_crc(b+3,2); + b[0]=(uint16_t)b2>>8; + b[1]=(uint16_t)b2&0x00FF; + b[2]=sensirion_common_generate_crc(b,2); + writeSGPXX(0x201e,b,6); + bl1S=b1; + bl2S=b2; +} + +int8_t initSGP30() { + uint8_t b[10]; + readSGPXX(0x2032,b,3); + _delay_ms(300); + writeSGPXX(0x2003,0,0); + _delay_ms(10); + uint16_t b1=0,b2=0; + //set_baseline(0x2210,0x3320); + //readSGPXX(0x2015,b,6); + read_baseline(&b1,&b2); + if (b1!=0xFFFF) { + set_baseline(b1,b2); + //readSGPXX(0x2015,b,6); + //uint16_t bl1,bl2; + //check_convert_buf(b,&bl1,&bl2); + + } + return 0x1; + +} + +void runSGP30(uint16_t *CO2,uint16_t *VOC,uint16_t *ETH,uint16_t *H2){ + uint8_t b[10]; + readSGPXX(0x2008,b,6); + check_convert_buf(b,CO2,VOC); + getbl--; + if (getbl==0) { + uint8_t eq=1; + readSGPXX(0x2015,b,6); + uint16_t bl1,bl2; + check_convert_buf(b,&bl1,&bl2); + int8_t bl1d=bl1-bl1S; + int8_t bl2d=bl2-bl2S; + if (bl1d<0) bl1d=-bl1d; + if (bl2d<0) bl2d=-bl2d; + if (bl1d>4) {bl1S=bl1;eq=0;} + if (bl2d>4) {bl2S=bl2;eq=0;} + getbl=200; //Naechste bruefunf in 100 s + if (eq==0) { + *VOC+=1000; + save_baseline(bl1,bl2); + } + } + readSGPXX(0x2050,b,6); + check_convert_buf(b,ETH,H2); + +} + + diff --git a/common/I2C/SGP30.h b/common/I2C/SGP30.h new file mode 100644 index 0000000..c285008 --- /dev/null +++ b/common/I2C/SGP30.h @@ -0,0 +1,39 @@ +#ifndef SGP30_H +#define SGP30_H +// Copyright (c) 2017, 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. + +int8_t initSGP30(); +void runSGP30(uint16_t *CO2,uint16_t *VOC,uint16_t *ETH,uint16_t *H2); + + +#endif \ No newline at end of file diff --git a/common/I2C/USI_TWI_Master.h b/common/I2C/USI_TWI_Master.h index f91c41b..d6b1f85 100644 --- a/common/I2C/USI_TWI_Master.h +++ b/common/I2C/USI_TWI_Master.h @@ -31,8 +31,13 @@ // Defines controlling timing limits #define TWI_FAST_MODE - +#ifdef __4MHZ__ +#define SYS_CLK 4000.0 // [kHz] +#else #define SYS_CLK 8000.0 // [kHz] +#endif + + #ifdef TWI_FAST_MODE // TWI FAST mode timing limits. SCL = 100-400kHz #define T2_TWI ((SYS_CLK *1300) /1000000) +1 // >1,3us diff --git a/common/OWDS18B20_DS2438.S b/common/OWDS18B20_DS2438.S index 109891d..73fd42e 100644 --- a/common/OWDS18B20_DS2438.S +++ b/common/OWDS18B20_DS2438.S @@ -34,6 +34,7 @@ #define _CHANGEABLE_ID_ #define _ZERO_POLLING_ #define _HANDLE_CC_COMMAND_ + //#define _DB_ #include "../common/OWConfig.s" @@ -48,12 +49,15 @@ #else .extern pack2,64 #endif -.extern am2302_temp,2 -.extern am2302_hum,2 +//.extern am2302_temp,2 +//.extern am2302_hum,2 .comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad) +.comm cpsp,1 ; Copy Scratchpad marker .macro CHIP_INIT ;r_temp is pushed other Registers should be saved + ldi r_temp,0 + sts cpsp,r_temp Init_EEPROM_read: push r_bytep push r_rwbyte @@ -79,6 +83,7 @@ Init_EEPROM_read: rjmp h_readscratchpad2 rjmp h_writescratchpad_adr2 rjmp h_writescratchpad2 + rjmp h_copyscratchpad_adr2 .endm #include "../common/OWRomFunctionsDual.s" @@ -94,6 +99,7 @@ Init_EEPROM_read: #define OW_READ_SCRATCHPAD2 OW_FIRST_COMMAND+4 #define OW_WRITE_SCRATCHPAD_ADR2 OW_FIRST_COMMAND+5 #define OW_WRITE_SCRATCHPAD2 OW_FIRST_COMMAND+6 +#define OW_COPY_SCRATCHPAD_ADR2 OW_FIRST_COMMAND+7 ;--------------------------------------------------- @@ -270,6 +276,7 @@ h_readcommand2: cset 0x4E,OW_WRITE_SCRATCHPAD_ADR2 cjmp 0x44,hrc_set_convertT2 cjmp 0xB4,hrc_set_convertV2 + cset 0x48,OW_COPY_SCRATCHPAD_ADR2 FW_CONFIG_INFO2 //cljmp 0x85,hrc_fw_configinfo2 #ifdef _CHANGEABLE_ID_ @@ -367,7 +374,10 @@ h_writescratchpad_all2: rjmp handle_end_sleep - +h_copyscratchpad_adr2: + ori r_rwbyte,0x80 ;hoechstes bit ist 1 zum Testen + sts cpsp,r_rwbyte + rjmp handle_end_sleep diff --git a/common/OWDS2438.S b/common/OWDS2438.S index a7d92fa..e268f53 100644 --- a/common/OWDS2438.S +++ b/common/OWDS2438.S @@ -34,6 +34,7 @@ //#define _DIS_FLASH_ #define _ZERO_POLLING_ //#define _DB_ +//#define __4MHZ__ #include "../common/OWConfig.s" #include "../common/OWCRC8.s" diff --git a/common/OWDS2438_DS2438.S b/common/OWDS2438_DS2438.S index 3c00e1b..2d2c891 100644 --- a/common/OWDS2438_DS2438.S +++ b/common/OWDS2438_DS2438.S @@ -33,7 +33,7 @@ #define _CHANGEABLE_ID_ #define _ZERO_POLLING_ -//#define _HANDLE_CC_COMMAND_ +#define _HANDLE_CC_COMMAND_ //#define _DB_ #include "../common/OWConfig.s" @@ -52,9 +52,11 @@ .extern DS2438_2_TEMP,2 .extern DS2438_2_VAD,2 .comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad) - +.comm cpsp2,1 ; Copy Scratchpad marker .macro CHIP_INIT ;r_temp is pushed other Registers should be saved + ldi r_temp,0 + sts cpsp2,r_temp .endm .macro COMMAND_TABLE @@ -66,6 +68,7 @@ rjmp h_readscratchpad2 rjmp h_writescratchpad_adr2 rjmp h_writescratchpad2 + rjmp h_copyscratchpad_adr2 .endm #include "../common/OWRomFunctionsDual.s" @@ -82,6 +85,7 @@ #define OW_READ_SCRATCHPAD2 OW_FIRST_COMMAND+5 #define OW_WRITE_SCRATCHPAD_ADR2 OW_FIRST_COMMAND+6 #define OW_WRITE_SCRATCHPAD2 OW_FIRST_COMMAND+7 +#define OW_COPY_SCRATCHPAD_ADR2 OW_FIRST_COMMAND+8 ;--------------------------------------------------- @@ -91,7 +95,8 @@ #ifdef _HANDLE_CC_COMMAND_ h_readcommand12: clr r_bytep - cset 0x44,hrc_set_convertT12 + cljmp 0x44,hrc_set_convertT12 + cljmp 0xB4,hrc_set_convertV12 ldi r_mode,OW_SLEEP rjmp handle_end #endif @@ -114,14 +119,23 @@ h_readcommand1: hrc_set_convertT1: + rcall chrc_set_convertT1 + rjmp handle_end_sleep + +chrc_set_convertT1: ldi r_temp,1 sts gcontrol,r_temp lds r_temp,DS2438_1_TEMP sts pack1+1,r_temp lds r_temp,DS2438_1_TEMP+1 sts pack1+2,r_temp - rjmp handle_end_sleep + ret + hrc_set_convertV1: + rcall chrc_set_convertV1 + rjmp handle_end_sleep + +chrc_set_convertV1: lds r_temp,pack1 sbrs r_temp,3 rjmp hrc_set_convertVV1 @@ -131,14 +145,14 @@ hrc_set_convertV1: sts pack1+4,r_temp rjmp hrc_set_convertend1 hrc_set_convertVV1: - ldi r_temp,3 + ldi r_temp,2 sts gcontrol,r_temp lds r_temp,DS2438_1_VAD sts pack1+3,r_temp lds r_temp,DS2438_1_VAD+1 sts pack1+4,r_temp hrc_set_convertend1: - rjmp handle_end_sleep + ret @@ -210,16 +224,13 @@ h_writescratchpad_all1: #ifdef _HANDLE_CC_COMMAND_ hrc_set_convertT12: - ldi r_temp,3 - sts gcontrol,r_temp - lds r_temp,DS2438_2_TEMP - sts pack2+1,r_temp - lds r_temp,DS2438_2_TEMP+1 - sts pack2+2,r_temp - lds r_temp,DS2438_1_TEMP - sts pack1+1,r_temp - lds r_temp,DS2438_1_TEMP+1 - sts pack1+2,r_temp + rcall chrc_set_convertT1 + rcall chrc_set_convertT2 + rjmp handle_end_sleep + +hrc_set_convertV12: + rcall chrc_set_convertV1 + rcall chrc_set_convertV2 rjmp handle_end_sleep #endif @@ -243,6 +254,7 @@ h_readcommand2: cset 0x4E,OW_WRITE_SCRATCHPAD_ADR2 cjmp 0x44,hrc_set_convertT2 cjmp 0xB4,hrc_set_convertV2 + cset 0x48,OW_COPY_SCRATCHPAD_ADR2 FW_CONFIG_INFO2 //cljmp 0x85,hrc_fw_configinfo2 #ifdef _CHANGEABLE_ID_ @@ -250,16 +262,25 @@ h_readcommand2: #endif rjmp handle_end_sleep - hrc_set_convertT2: - ldi r_temp,2 + rcall chrc_set_convertT2 + rjmp handle_end_sleep + +hrc_set_convertV2: + rcall chrc_set_convertV2 + rjmp handle_end_sleep + + +chrc_set_convertT2: + ldi r_temp,3 sts gcontrol,r_temp lds r_temp,DS2438_2_TEMP sts pack2+1,r_temp lds r_temp,DS2438_2_TEMP+1 sts pack2+2,r_temp - rjmp handle_end_sleep -hrc_set_convertV2: + ret + +chrc_set_convertV2: lds r_temp,pack2 sbrs r_temp,3 rjmp hrc_set_convertVV2 @@ -269,14 +290,14 @@ hrc_set_convertV2: sts pack2+4,r_temp rjmp hrc_set_convertend2 hrc_set_convertVV2: - ldi r_temp,3 + ldi r_temp,4 sts gcontrol,r_temp lds r_temp,DS2438_2_VAD sts pack2+3,r_temp lds r_temp,DS2438_2_VAD+1 sts pack2+4,r_temp hrc_set_convertend2: - rjmp handle_end_sleep + ret @@ -341,7 +362,10 @@ h_writescratchpad_all2: - +h_copyscratchpad_adr2: + ori r_rwbyte,0x80 ;hoechstes bit ist 1 zum Testen + sts cpsp2,r_rwbyte + rjmp handle_end_sleep diff --git a/common/OWDS2450.S b/common/OWDS2450.S index 40e3907..9a8d50f 100644 --- a/common/OWDS2450.S +++ b/common/OWDS2450.S @@ -31,7 +31,7 @@ // (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 _CHANGEABLE_ID_ #define _ZERO_POLLING_ #include "../common/OWConfig.s" diff --git a/common/OWSet_ATTINYX4.s b/common/OWSet_ATTINYX4.s index 1810047..b50fde5 100644 --- a/common/OWSet_ATTINYX4.s +++ b/common/OWSet_ATTINYX4.s @@ -67,7 +67,7 @@ //#define OWT_READ 4 #ifdef __4MHZ__ #define OWT_MIN_RESET 80 -#define OWT_RESET2 17 +#define OWT_RESET2 30 #define OWT_RESET_PRESENT 15 #define OWT_PRESENT 60 #define OWT_WRITE 16 -- 2.34.1