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 owid[8]={0x29, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x01, 0x73};/**/
\r
54 uint8_t config_info[26]={0x06,0x09,0x06,0x09,0x06,0x09,0x06,0x09,0x02,20,20,20,20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
\r
61 volatile uint8_t bytes[0x20];
\r
63 uint8_t PIO_Logic_State; // 0088h
\r
64 uint8_t PIO_Output_Latch_State;
\r
65 uint8_t PIO_Activity_Latch_State;
\r
66 uint8_t Conditional_Search_Channel_Selection_Mask;
\r
67 uint8_t Conditional_Search_Channel_Polarity_Selection;
\r
68 uint8_t Status; //008D
\r
74 volatile pack_t pack;
\r
81 for(uint8_t i=0;i<5;i++) {
\r
82 uint8_t v=values[i];
\r
86 for(uint8_t j=0;j<8;j++) {
\r
87 if ((v&bit)==bit) lb=1; else lb=0;
\r
88 if ((lscrc&1)!=lb) lscrc=(lscrc>>1)^0x8c; else lscrc=(lscrc>>1);
\r
99 //rh=(T-25)*(0,01+0,00008*x)-2,0468+0,0367*x-0,0000015955*x*x
\r
103 inline uint16_t calcSHT75_T(double real_t) {
\r
104 return (real_t-d1)/d2;
\r
107 inline uint16_t calcSHT75RH_lin(double real_RHlin) {
\r
108 return 11501.1-0.280297*sqrt(1667284153.0-7977500.0*real_RHlin);
\r
111 inline double calcSHT75H_tcorr(double real_t,double real_RHtrue) {
\r
112 return real_RHtrue-(real_t-25)*(0.01+0.00008*calcSHT75RH_lin(real_RHtrue));
\r
124 //0x0E 0x19 0x48 0x00
\r
126 uint16_t lt=calcSHT75_T(T);
\r
127 double lfc=calcSHT75H_tcorr(T,RH);
\r
128 uint16_t lf=calcSHT75RH_lin(lfc);
\r
130 values[1]=lt&0xFF; if (values[1]==0) values[1]=1;
\r
131 values[2]=lt>>8; if (values[2]==0) values[2]=1;
\r
132 values[3]=lf&0xFF; if (values[3]==0) values[3]=1;
\r
133 values[4]=lf>>8; if (values[4]==0) values[4]=1;
\r
145 TWI_Master_Initialise();
\r
150 getSHT3xHumTemp(0,&T,&RH);
\r
153 stat_to_sample=0x55;
\r
155 //stat_to_sample=0;
\r
156 if (reset_indicator) {
\r
158 // stat_to_sample=0;
\r
159 // reset_indicator=0;
\r
165 getSHT3xHumTemp(0,&T,&RH);
\r
167 lfc=calcSHT75H_tcorr(T,RH);
\r
168 lf=calcSHT75RH_lin(lfc);
\r
170 values[1]=lt&0xFF; if (values[1]==0) values[1]=1;
\r
171 values[2]=lt>>8; if (values[2]==0) values[2]=1;
\r
172 values[3]=lf&0xFF; if (values[3]==0) values[3]=1;
\r
173 values[4]=lf>>8; if (values[4]==0) values[4]=1;
\r
184 for(uint8_t i=0;i<8;i++) {
\r
185 if ((pack.PIO_Logic_State&bb)!=(pack.PIO_Output_Latch_State&bb)) pack.PIO_Activity_Latch_State|=bb;
\r
188 pack.PIO_Logic_State=pack.PIO_Output_Latch_State;
\r
192 pack.PIO_Activity_Latch_State=0;
\r
196 stat_to_sample=values[ap];
\r
205 stat_to_sample=values[ap];
\r