Autor Tema: SHT11 no responde.  (Leído 1796 veces)

0 Usuarios y 2 Visitantes están viendo este tema.

Desconectado QIQE

  • PIC18
  • ****
  • Mensajes: 335
SHT11 no responde.
« en: 22 de Enero de 2009, 10:17:57 »
Hola llevo unos dias peleandome con este sensor y su datasheet, he probado varias librerias para el pero ninguna funciona, ni simulando ni en la realidad, por lo que se ve han cambiado el protocolo, estoy intentando desarrollarlo de nuevo pero estoy atascado, alguien me puede echar una mano?? muchas gracias, esto es lo que llevo por ahora

Mi libreria

Código: [Seleccionar]
///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Driver para el sensor SHT11 Humedad/temperatura                           //
//                                                                           //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#define DATA   PIN_A4
#define CLOCK    PIN_A3

#define noACK 0
#define ACK 1

#define ESCRIBIR_ESTATUS 0x06 //000 00 11 0
#define LEER_ESTATSUS 0x07    //000 00 11 1
#define TEMPERATURA 0x03      //000 00 01 1
#define HUMEDAD 0x05          //000 00 10 1
#define RESET 0x1E            //000 11 11 0

// Constantes SHT1X

#define C1 -2.0468
#define C2 0.0367
#define C3 -0.0000015

#define D1 -40.1
#define D2 0.01

#define T1 0.01
#define T2 0.00008

int   VALOR1=0;
int   VALOR2=0;
long VALOR;


//***** INICIA EL  SHT11 *****

void sht1x_xmission_start (void)
{
 output_bit(DATA, 1);  //data high
 output_bit(CLOCK, 0);  //clk low
 delay_us(2);
 output_bit(CLOCK, 1);  //clk high
 delay_us(2);
 output_bit(DATA, 0); //data low
 delay_us(2);
 output_bit(CLOCK, 0);  //clk low
 delay_us(5);
 output_bit(CLOCK, 1);  //clk high
 delay_us(2);
 output_bit(DATA, 1);  //data high
 delay_us(2);
 output_bit(CLOCK, 0);  //clk low
}

//***** RESETEA EL SHT11 *****
void sht1x_connection_reset()
{
 int i=0;
 output_bit(DATA, 1);  //data high
 output_bit(CLOCK, 0);  //clk low
 
 for (i=0;i<9;i++)
   {
   output_bit(CLOCK, 1);  //clk high
   delay_us(2);
   output_bit(CLOCK, 0);  //clk low
   delay_us(2);
   }
 sht1x_xmission_start();
}

//*****    ENVIO DE COMANDOS    *****
void sht1x_command_mode(int IMODE)
{
int i=0;
for (i=128; i>0 ; i/=2)
   {
   if (i & IMODE)                     // Saca los 8 bits, con un pluso de clk
      {
      output_bit(DATA, 1);  //data high
      }
      else
      output_bit(DATA, 0);  //data low
 
      //delay_us(2);
      output_bit(CLOCK, 1);  //clk high
      delay_us(2);
      output_bit(CLOCK, 0);  //clk low
      delay_us(2);
   }
   

 delay_us(2);
 output_bit(CLOCK, 1);  //clk high ACK
 delay_us(2);
 output_bit(CLOCK, 0);  //clk low
 delay_us(250);
 
 output_bit(DATA, 0);  //data low8
 output_float(DATA);
 
}


//*****    SOFT RESET    *****
void sht1x_soft_reset()
{
 sht1x_connection_reset();
 sht1x_command_mode(RESET);
 delay_ms(11);
}

//*****    LECTURA DE DATOS    *****

long sht1x_read_data()
{
int i;
int1 Temporal;
//long VALOR1=0;
//long VALOR2=0;
//long VALOR;

 output_float(DATA);

//Recive los 8 primeros bits 4 primeros no son validos
for (i=0;i<8;i++)
{
 VALOR1<<=1;
 output_bit(CLOCK, 1);  //clk high
 Temporal=input(DATA);
 delay_us(2);
 output_bit(CLOCK, 0);  //clk low
 delay_us(2);
 if (Temporal)
   VALOR1 |=1;
}

//Rutina de reconocimiento.

 output_bit(DATA, 0);  //data low
 output_bit(CLOCK, 1);  //clk high

 delay_us(2);
 
 output_bit(CLOCK, 0);  //clk low
 delay_us(2);
 output_float(DATA);  //patilla como entrada
 
   
// Recive los ultimos 8 bits
for (i=0;i<8;i++)
   {
   VALOR2<<=1;
   output_bit(CLOCK, 1);  //clk high
   Temporal=input(DATA);
   delay_us(2);
   output_bit(CLOCK, 0);  //clk low
   delay_us(2);
   if (Temporal)
      VALOR2 |=1;
   }
    output_bit(DATA, 1);  //data low
output_bit(PIN_B4, 1);
}



El código para el micro

Código: [Seleccionar]

#include <16F628A.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8)

#include <F:\CCS\MISHT1X.h>

//#define TEMPERATURA 0x03      //000 00 01 1

// MEDIDA=0;
float MEDIDA;
float SALIDA;
void main()
{

   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillotar Config tab

   sht1x_connection_reset();
   // TODO: USER CODE!!
   while (true)
      {
      //printf("DOS");
      delay_ms(12);
 
      sht1x_xmission_start();

     
/////////////////OK///////////////////////     
     
      sht1x_command_mode(HUMEDAD);
      sht1x_read_data();
      printf("%U  %u \n\r",VALOR1,VALOR2);
      delay_ms(5000);
      }
}


El datasheetDATASHEET

Muchas gracias.
Muchas gracias por vuestro tiempo.

Saludos desde valencia!!!

Desconectado QIQE

  • PIC18
  • ****
  • Mensajes: 335
Re: SHT11 no responde.
« Respuesta #1 en: 24 de Enero de 2009, 12:21:49 »
Hola al final he conseguido un no avance, por decirlo de alguna manera, a ver si alguien me puede explicar, uso una libreria para este micro con el chip pic 16f877A, cambio de patillas, de velocidad de reloj, lo muestro por una pantalla lcd o lo mando por rs 232, todo lo que le quiera hacer lo hace perfectamente sin problemas, compilo lo mismo para un 16f876A y no funciona, para un 16f628 y no funciona!! alguien sabe lo que puede estar pasando??
Muchas gracias por vuestro tiempo.

Saludos desde valencia!!!


 

anything