CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

error with sensor SHT15

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jrafa



Joined: 13 Dec 2012
Posts: 9

View user's profile Send private message

error with sensor SHT15
PostPosted: Sat Jul 20, 2013 10:15 am     Reply with quote

hi,

i am using a dspic30f6015 and a sensirion sht15. The pic is using the internal rc oscillator of 7.370.000 Hz, the interface is PIN_D6 & D5 for DATA & CLK. The data line has a 10k resistor pullup, and there is a 0.1uF capacitor for power supply the sensor like datasheet recommends. All the system is powered from 5V. I am using mplab 8.88, ccs 4.138 and pickit2 (also as power supply).

I can see the activity of the lines with a oscilloscope, but only when the microcontroller writes. The sensor doesn't response, there is not ACK or data from the SHT. The power of the sensor is ok.

The code is based on the sensirion example and libraries from this forums:
Code:

#include <30F6015.h>

#FUSES WPSA8                   //Watch Dog Timer PreScalar A 1:64
#FUSES WPSB1                   //Watch Dog Timer PreScalar B 1:16
#FUSES FRC                      //Internal Fast RC Oscillator
#FUSES NOPUT                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOBROWNOUT               //No brownout reset
#fuses NOWDT,NOPROTECT

#use delay(clock=7370000)

#include "temp.h"

void main(){

   delay_ms(1000);
   initTemp();
   delay_ms(1000);
   while(1){
      readTemp();
      delay_ms(1000);
   }
}

temp.h is:
Code:

#include <math.h>

typedef union {
   long i;
   float f;
   unsigned int8 b[4];
} t_value;

enum {TEMP, HUMI};

#define DATA PIN_D6
#define SCK PIN_D5

#define noACK 0
#define yesACK 1

#define STATUS_REG_W 0x06 //000 0011 0
#define STATUS_REG_R 0x07 //000 0011 1
#define MEASURE_TEMP 0x03 //000 0001 1
#define MEASURE_HUMI 0x05 //000 0010 1
#define RESET 0x1e //000 1111 0

t_value humi_val, temp_val;

char s_write_byte(char value){
   char i, error = 0;
   
   for (i = 0x80; i > 0; i /= 2){
      if (i & value){
         output_high(DATA); // DATA=1; //masking value with i , write to SENSI-BUS
      }else{
         output_low(DATA); //DATA=0;
      }
      delay_us(2);
      output_high(SCK); //SCK=1; //clk for SENSI-BUS
      delay_us(6); //_nop_();_nop_();_nop_(); //pulswith approx. 5 us
      output_low(SCK); //SCK=0;
      delay_us(2);
   }//fin for
   output_high(DATA); //DATA=1; //release DATA-line
   delay_us(2);
   output_high(SCK); //SCK=1; //clk #9 for ack
   output_float(DATA);
   error = input(DATA); //DATA; //check ack (DATA will be pulled down by SHT11)
   output_low(SCK); //SCK=0;
   return(error); //error=1 in case of no acknowledge
}

char s_read_byte(char ack){
   char i, val=0;
   
   output_high(DATA); //DATA=1; //release DATA-line
   for (i = 0x80; i > 0; i /= 2){
      output_high(SCK); //SCK=1; //clk for SENSI-BUS
      if (input(DATA)){
         val = (val | i); //read bit
      }
      output_low(SCK); //SCK=0;
   }
   output_bit(DATA, !ack);   //in case of "ack==1" pull down DATA-Line
   delay_us(2);         //observe setup time
   output_high(SCK);      //clk #9 for ack
   delay_us(6);         //pulswith approx. 5 us
   output_low(SCK);
   delay_us(2);         //observe hold time
   output_high(DATA);
   return val;
}

void s_transstart(void){
   output_high(DATA); // DATA=1;
   output_low(SCK); // SCK=0; //Initial state
   delay_us(2); // _nop_();
   output_high(SCK); // SCK=1;
   delay_us(2); // _nop_();
   output_low(DATA); // DATA=0;
   delay_us(2); // _nop_();
   output_low(SCK); // SCK=0;
   delay_us(6); // _nop_(); _nop_();_nop_();
   output_high(SCK); // SCK=1;
   delay_us(2); // _nop_();
   output_high(DATA); // DATA=1;
   delay_us(2); // _nop_();
   output_low(SCK); // SCK=0;
}

void s_connectionreset(void) {
   char i;
   
   output_high(DATA); // DATA=1;
   output_low(SCK);
   
   for(i = 0; i < 9; i++){ // 9 SCK cycles
      output_high(SCK); // SCK=1;
      delay_us(2);
      output_low(SCK); // SCK=0;
      delay_us(2);
   }
   s_transstart(); //transmission start
}

char s_measure(char *p_value, char *p_checksum, char mode){
   char error = 0;
   long i;
   
   s_transstart(); //transmission start
   
   switch(mode){ //send command to sensor
      case TEMP:
         error += s_write_byte(MEASURE_TEMP);
      break;
      case HUMI:
         error += s_write_byte(MEASURE_HUMI);
      break;
      default:
      break;
   }
   output_float(DATA);
   for (i = 0; i < 65535; i++){
      delay_us(2);
      if(input(DATA) == 0){
         break; //wait until sensor has finished the measurement
      }   
   }
   if(input(DATA)){
      error += 1; // or timeout (~2 sec.) is reached
   }   
   *(p_value) = s_read_byte(yesACK); //read the first byte (MSB)
   *(p_value+1) = s_read_byte(yesACK); //read the second byte (LSB)
   *p_checksum = s_read_byte(noACK); //read checksum
   
   return(error);
}

void initTemp(){
   humi_val.f = 0.0;
   temp_val.f = 0.0;
   output_float(DATA);
   output_float(SCK);
   s_connectionreset();
}
void readTemp(){
   char checksum, error = 0;
   
   error += s_measure((char*) &humi_val.i, &checksum, TEMP); //measure humidity
   error += s_measure((char*) &temp_val.i, &checksum, HUMI); //measure temperature
   if(error!=0){
      s_connectionreset(); //in case of an error: connection reset
   }else{
      humi_val.f = (float)humi_val.i; //converts integer to float
      temp_val.f = (float)temp_val.i; //converts integer to float
      //calc_sth11(&humi_val.f, &temp_val.f); //calculate humidity, temperature
      //dew_point=calc_dewpoint(humi_val.f,temp_val.f); //calculate dew point
   }//fin if else
}


The first error is at the s_write_byte() function because there is not ACK from the sensor.

Can someone help me solve this problem?

Thanks.
Best regards.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jul 20, 2013 11:25 am     Reply with quote

The driver 'temp.h' has a comment about the sht11 device, yet you're using an sht15.

Have you carefully read the datasheets for both devices, and noted ANY differences with respect to timing, configuration, commands,electrical specs.,etc.?

You may have a 'compatibilty' problem as it appears the driver was written for the SHT11 device.

hth
jay
jrafa



Joined: 13 Dec 2012
Posts: 9

View user's profile Send private message

PostPosted: Sat Jul 20, 2013 11:47 am     Reply with quote

Thank you for your quick response.

The datasheet only shows differences on accuracy and packaging between sht10, sht11 and sht15. The inferface specifications are equivalents.

Best regards.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sat Jul 20, 2013 12:32 pm     Reply with quote

Two things in the data sheet might be worth noting.

1) Comment that wires/connections longer than 10cm (4"), may result in loss of communication, if Sck, and Sdata are close together.
2) Requirement that the power rail must rise faster than 1v/msec.

Best Wishes
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Jul 22, 2013 7:38 am     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=28564

That driver works with the SHT15... I tested it with a 16f886...

works just fine. i just modified the output to my needs...

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
jrafa



Joined: 13 Dec 2012
Posts: 9

View user's profile Send private message

PostPosted: Mon Jul 22, 2013 8:57 am     Reply with quote

Ttelmah, i appreciate your interest. The traces are 55.92 mm (CLK) and 54.09 mm (DATA). The power supply needs over 300us for rising 5V.

Gabriel, I saw this thread, but did not use it because it was for the sht71. I've tried and it works!.

thank you very much
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Jul 22, 2013 10:07 pm     Reply with quote

glad to help..

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group