2 // Copyright (c) 2018, 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/TWI_Master.h"
\r
42 #include "../common/owSlave_tools.h"
\r
43 #include "../common/I2C/SHT3x.h"
\r
44 #include "../common/calibr.h"
\r
49 extern void OWINIT();
\r
50 extern void EXTERN_SLEEP();
\r
51 extern uint8_t stat_to_sample;
\r
53 uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/
\r
54 uint8_t owid2[8]={0x29, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x01, 0x73};/**/
\r
55 uint8_t config_info1[26]={0x01,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x02,29,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
\r
56 uint8_t config_info2[26]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0,0,0,0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
\r
65 volatile uint8_t bytes[8];
\r
76 volatile pack1_t pack1;
\r
79 volatile uint8_t bytes[0x20];
\r
81 uint8_t PIO_Logic_State; // 0088h
\r
82 uint8_t PIO_Output_Latch_State;
\r
83 uint8_t PIO_Activity_Latch_State;
\r
84 uint8_t Conditional_Search_Channel_Selection_Mask;
\r
85 uint8_t Conditional_Search_Channel_Polarity_Selection;
\r
86 uint8_t Status; //008D
\r
92 volatile pack2_t pack2;
\r
99 for(uint8_t i=0;i<5;i++) {
\r
100 uint8_t v=values[i];
\r
101 //if (v==0) v=0xFF;
\r
104 for(uint8_t j=0;j<8;j++) {
\r
105 if ((v&bit)==bit) lb=1; else lb=0;
\r
106 if ((lscrc&1)!=lb) lscrc=(lscrc>>1)^0x8c; else lscrc=(lscrc>>1);
\r
118 //rh=(T-25)*(0,01+0,00008*x)-2,0468+0,0367*x-0,0000015955*x*x
\r
122 inline uint16_t calcSHT75_T(double real_t) {
\r
123 return (real_t-d1)/d2;
\r
126 inline uint16_t calcSHT75RH_lin(double real_RHlin) {
\r
127 return 11501.1-0.280297*sqrt(1667284153.0-7977500.0*real_RHlin);
\r
130 inline double calcSHT75H_tcorr(double real_t,double real_RHtrue) {
\r
131 return real_RHtrue-(real_t-25)*(0.01+0.00008*calcSHT75RH_lin(real_RHtrue));
\r
143 //0x0E 0x19 0x48 0x00
\r
145 uint16_t lt=calcSHT75_T(T);
\r
146 double lfc=calcSHT75H_tcorr(T,RH);
\r
147 uint16_t lf=calcSHT75RH_lin(lfc);
\r
149 values[1]=lt&0xFF; if (values[1]==0) values[1]=1;
\r
150 values[2]=lt>>8; if (values[2]==0) values[2]=1;
\r
151 values[3]=lf&0xFF; if (values[3]==0) values[3]=1;
\r
152 values[4]=lf>>8; if (values[4]==0) values[4]=1;
\r
156 values[5]=crc8_f();
\r
160 TWI_Master_Initialise();
\r
165 getSHT3xHumTemp(0,&T,&RH);
\r
168 stat_to_sample=0x55;
\r
170 //stat_to_sample=0;
\r
171 if (reset_indicator) {
\r
173 // stat_to_sample=0;
\r
174 // reset_indicator=0;
\r
180 getSHT3xHumTemp(0,&T,&RH);
\r
181 //pack1.temp=T*16.0;
\r
183 lfc=calcSHT75H_tcorr(T,RH);
\r
184 lf=calcSHT75RH_lin(lfc);
\r
186 values[1]=lt&0xFF; if (values[1]==0) values[1]=1;
\r
187 values[2]=lt>>8; if (values[2]==0) values[2]=1;
\r
188 values[3]=lf&0xFF; if (values[3]==0) values[3]=1;
\r
189 values[4]=lf>>8; if (values[4]==0) values[4]=1;
\r
190 values[5]=crc8_f();
\r
191 if (values[5]==0) values[3]=values[3]+1; //CRC darf nicht 0 sein ... warum auch immer
\r
192 values[5]=crc8_f();
\r
194 pack2.Status|=0x80;
\r
197 for(uint8_t i=0;i<8;i++) {
\r
198 if ((pack2.PIO_Logic_State&bb)!=(pack2.PIO_Output_Latch_State&bb)) pack2.PIO_Activity_Latch_State|=bb;
\r
201 pack2.PIO_Logic_State=pack2.PIO_Output_Latch_State;
\r
205 pack2.PIO_Activity_Latch_State=0;
\r
209 stat_to_sample=values[ap];
\r
218 stat_to_sample=values[ap];
\r
223 if ((gcontrol&16)==16) {
\r
229 if (t8>pack1.TH) af=1;
\r
230 if (t8<=pack1.TL) af=1;
\r