2 // Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
\r
3 // All rights reserved.
\r
5 // Redistribution and use in source and binary forms, with or without
\r
6 // modification, are permitted provided that the following conditions are
\r
9 // * Redistributions of source code must retain the above copyright
\r
10 // notice, this list of conditions and the following disclaimer.
\r
11 // * Redistributions in binary form must reproduce the above copyright
\r
12 // notice, this list of conditions and the following disclaimer in the
\r
13 // documentation and/or other materials provided with the
\r
15 // * All advertising materials mentioning features or use of this
\r
16 // software must display the following acknowledgement: This product
\r
17 // includes software developed by tm3d.de and its contributors.
\r
18 // * Neither the name of tm3d.de nor the names of its contributors may
\r
19 // be used to endorse or promote products derived from this software
\r
20 // without specific prior written permission.
\r
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
\r
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
\r
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
\r
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
\r
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
\r
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
\r
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
34 #define F_CPU 8000000UL
\r
36 #include <avr/interrupt.h>
\r
37 #include <util/delay.h>
\r
38 #include <avr/wdt.h>
\r
39 #include <avr/sleep.h>
\r
40 #include <avr/pgmspace.h>
\r
41 #include "../common/I2C/USI_TWI_Master.h"
\r
42 #include "../common/I2C/MAX44009.h"
\r
43 #include "../common/I2C/SHT2xV2.h"
\r
44 #include "../common/calibr.h"
\r
45 #include "../common/owSlave_tools.h"
\r
50 uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/
\r
51 uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/
\r
52 uint8_t config_info1[26]={0x03,0x04, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x02,15,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
\r
53 uint8_t config_info2[26]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x02,7,0x00,7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
\r
61 volatile uint8_t bytes[8];
\r
72 volatile pack1_t pack1;
\r
77 #if defined(__AVR_ATtiny25__)
\r
78 volatile uint8_t bytes[16];
\r
80 volatile uint8_t bytes[64];
\r
85 uint16_t voltage; //4
\r
86 uint16_t current; //6
\r
87 uint8_t threshold; //8
\r
89 uint8_t page1[8]; //9
\r
90 #if defined(__AVR_ATtiny25__)
\r
92 uint8_t page2[8]; //17
\r
93 uint8_t page3[8]; //25
\r
94 uint8_t page4[8]; //33
\r
95 uint8_t page5[8]; //41
\r
96 uint8_t page6[8]; //49
\r
97 uint8_t page7[8]; //57
\r
102 volatile pack2_t pack2;
\r
105 volatile int16_t DS2438_2_TEMP;
\r
106 volatile uint16_t DS2438_2_VAD;
\r
107 volatile uint16_t DS2438_2_VDD=0x01F4;
\r
109 double temperatureC,humidityRH;
\r
127 config_info2[5]=12;
\r
132 USI_TWI_Master_Initialise();
\r
133 if (checkMAX44009(0)) max_adr=0; else max_adr=1 ;
\r
140 if ((gcontrol&2)==2){
\r
147 getSHT2xHumTemp(&temperatureC,&humidityRH);
\r
148 double RH=calibr_hum(temperatureC,-0.2,humidityRH)*10.0;
\r
149 double TC =temperatureC *10.0-2;
\r
153 DS2438_2_TEMP=TC*25.6;
\r
154 //am2302_temp=am2302_temp-20;
\r
155 config_info2[5]=12;
\r
156 DS2438_2_VDD=0x01F4;
\r
160 double hhum=(1.0546-0.000216*TC)*(RH);
\r
161 //am2302_hum=0.318*hhum +76.0;
\r
162 DS2438_2_VAD=0.31*hhum +80;
\r
163 DS2438_2_TEMP=TC*25.6;
\r
164 //am2302_temp=am2302_temp-20;
\r
166 DS2438_2_VDD=0x01F4;
\r
171 if ((gcontrol&1)==1) {
\r
173 l=MAX44009getlux(max_adr);
\r
174 if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045
\r
180 if (t8>pack1.TH) af=1;
\r
181 if (t8<=pack1.TL) af=1;
\r