1,8 → 1,8 |
/////////////////////////////////////////////////////////////////////////////// |
// // |
// Driver file for SHT1x Temperature & Humidity Sensor // |
// Driver file for SHT75 Temperature & Humidity Sensor // |
// // |
// ***** To initialise SHT1x sensor upon power up ***** // |
// ***** To initialise SHT75 sensor upon power up ***** // |
// // |
// Function : sht_init() // |
// Return : none // |
20,13 → 20,8 |
|
|
//***** Function to alert SHT75 ***** |
// generates a transmission start |
// _____ ________ |
// DATA: |_______| |
// ___ ___ |
// SCK : ___| |___| |______ |
|
void sht_comstart (void) |
void comstart (void) |
{ |
output_float(sht_data_pin); //data high |
output_low(sht_clk_pin); //clk low |
47,7 → 42,7 |
|
//***** Function to write data to SHT75 ***** |
|
int1 sht_comwrite (int8 iobyte) |
int1 comwrite (int8 iobyte) |
{ |
int8 i, mask = 0x80; |
int1 ack; |
78,7 → 73,7 |
|
//***** Function to read data from SHT75 ***** |
|
int16 sht_comread (void) |
int16 comread (void) |
{ |
int8 i; |
int16 iobyte = 0; |
131,7 → 126,7 |
|
//***** Function to wait for SHT75 reading ***** |
|
void sht_comwait (void) |
void comwait (void) |
{ |
int16 sht_delay; |
|
138,21 → 133,17 |
output_float(sht_data_pin); //data high |
output_low(sht_clk_pin); //clk low |
delay_us(2); |
for(sht_delay=0; sht_delay<350; sht_delay++) // wait for max 350ms (for 14bit measurement) |
for(sht_delay=0; sht_delay<30000; sht_delay++) // wait for max 300ms |
{ |
if (!input(sht_data_pin)) break; //if sht_data_pin low, SHT75 ready |
delay_ms(1); |
delay_us(10); |
} |
} |
|
|
//***** Function to reset SHT75 communication ***** |
// communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart |
// _____________________________________________________ ________ |
// DATA: |_______| |
// _ _ _ _ _ _ _ _ _ ___ ___ |
// SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______ |
void sht_comreset (void) |
|
void comreset (void) |
{ |
int8 i; |
|
166,7 → 157,7 |
output_low(sht_clk_pin); |
delay_us(5); |
} |
sht_comstart(); |
comstart(); |
} |
|
|
174,8 → 165,8 |
|
void sht_soft_reset (void) |
{ |
sht_comreset(); //SHT75 communication reset |
sht_comwrite(0x1e); //send SHT75 reset command |
comreset(); //SHT75 communication reset |
comwrite(0x1e); //send SHT75 reset command |
delay_ms(15); //pause 15 ms |
} |
|
182,16 → 173,16 |
|
//***** Function to measure SHT75 temperature ***** |
|
int16 sht_measuretemp (void) |
int16 measuretemp (void) |
{ |
int1 ack; |
int16 iobyte; |
|
sht_comstart(); //alert SHT75 |
ack = sht_comwrite(0x03); //send measure temp command and read ack status |
comstart(); //alert SHT75 |
ack = comwrite(0x03); //send measure temp command and read ack status |
if(ack == 1) return; |
sht_comwait(); //wait for SHT75 measurement to complete |
iobyte = sht_comread(); //read SHT75 temp data |
comwait(); //wait for SHT75 measurement to complete |
iobyte = comread(); //read SHT75 temp data |
return(iobyte); |
} |
|
198,16 → 189,16 |
|
//***** Function to measure SHT75 RH ***** |
|
int16 sht_measurehumid (void) |
int16 measurehumid (void) |
{ |
int1 ack; |
int16 iobyte; |
|
sht_comstart(); //alert SHT75 |
ack = sht_comwrite(0x05); //send measure RH command and read ack status |
comstart(); //alert SHT75 |
ack = comwrite(0x05); //send measure RH command and read ack status |
if(ack == 1) return; |
sht_comwait(); //wait for SHT75 measurement to complete |
iobyte = sht_comread(); //read SHT75 temp data |
comwait(); //wait for SHT75 measurement to complete |
iobyte = comread(); //read SHT75 temp data |
return(iobyte); |
} |
|
216,7 → 207,7 |
|
void calculate_data (int16 temp, int16 humid, float & tc, float & rhlin, float & rhtrue) |
{ |
float rh; |
float truehumid1, rh; |
|
//calculate temperature reading |
tc = ((float) temp * 0.01) - 40.0; |
239,8 → 230,8 |
float realhumid; |
restemp = 0; truehumid = 0; |
|
restemp = sht_measuretemp(); //measure temp |
reshumid = sht_measurehumid(); //measure RH |
restemp = measuretemp(); //measure temp |
reshumid = measurehumid(); //measure RH |
calculate_data (restemp, reshumid, temp, realhumid, truehumid); //calculate temp & RH |
} |
|
249,6 → 240,6 |
|
void sht_init (void) |
{ |
sht_comreset(); //reset SHT75 |
comreset(); //reset SHT75 |
delay_ms(20); //delay for power-up |
} |