dnsc
Newbie level 1
odcbbits
Hello guys,
I have been working on SHT11(Sensirion Temperature/Humidity Sensor) for a long time now and using PIC24FJ16GA002. I am still stuck on the first step as the sensor is not responding. I thought i burned the sensor and tried a new one but i am having the same problem.
At the moment i am just trying to get an acknowledgement from the sensor when i sent it a command but its not responding. Following is my code in oder to recieve this acknowledgement. Please help.
#include "p24fj16ga002.h"
#include "math.h"
#include "stdio.h"
#include "string.h"
_CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & FWDTEN_OFF )
_CONFIG2(IESO_OFF & FNOSC_FRC & FCKSM_CSDCMD & OSCIOFNC_OFF)
// DATA AND SCK set to 1 or 0
#define DATA_SET_1 LATBbits.LATB3=1
#define DATA_SET_0 LATBbits.LATB3=0
#define DRAIN ODCBbits.ODB3 = 1
#define SCK_SET_1 LATBbits.LATB2=1
#define SCK_SET_0 LATBbits.LATB2=0
#define DATA_OUT TRISBbits.TRISB3 = 0
#define DATA_IN TRISBbits.TRISB3 = 1
#define SCK_OUT TRISBbits.TRISB2 = 0
#define READ_DATA PORTBbits.RB3
#define MEASURE_TEMP 0x03 // 000 00011
#define MEASURE_HUMI 0x05 // 000 00101
#define TEMP 0
#define HUMI 1
#define NOACK 0
#define ACK 1
// FUNCTION USED TO CREATE THE DESIRED DELAY IN THE PROGRAM
void delay(unsigned int delay_count )
{
int i, j;
for(i=0;i<delay_count;i++)
{
for(j=0;j<delay_count;j++)
{
asm volatile("nop");
}
}
}
void connection_reset()
{
DATA_SET_1;
delay(5);
int i;
for (i=0;i<10;i++)
{
SCK_SET_1;
delay(50);
SCK_SET_0;
delay(50);
}
}
void main()
{
AD1PCFG = 0xff;
DRAIN;
int test = 1;
unsigned int i =0;
//unsigned char value=0;
//unsigned int error;
//unsigned char value=0;
//trans_start();
delay(400); // 11 ms after start up
SCK_OUT;
DATA_OUT;
connection_reset();
delay(50);
//DATA_SET_1;
delay(50);
SCK_SET_0;
delay(50);
DATA_SET_1;
delay(50);
SCK_SET_1;
delay(50);
DATA_SET_0;
delay(50);
SCK_SET_0;
delay(50);
SCK_SET_1;
delay(50);
DATA_SET_1;
delay(50);
SCK_SET_0;
delay(50);
for (i=0x80;i>0;i/=2) //Transmitting the command
{
if (i & MEASURE_HUMI)
DATA_SET_1;
else
DATA_SET_0;
delay(50);
SCK_SET_1;
delay(50);
SCK_SET_0;
}
DATA_IN;
while (READ_DATA==1)
{
}
test=0;
}
According to the datasheet the maximum frequency is 1 Mhz if power supply is less than 4.5V. I am using a power supply of 3.3 V and my frquency is very low about 8 Hz.
Any help is greatly appreciated.
Hello guys,
I have been working on SHT11(Sensirion Temperature/Humidity Sensor) for a long time now and using PIC24FJ16GA002. I am still stuck on the first step as the sensor is not responding. I thought i burned the sensor and tried a new one but i am having the same problem.
At the moment i am just trying to get an acknowledgement from the sensor when i sent it a command but its not responding. Following is my code in oder to recieve this acknowledgement. Please help.
#include "p24fj16ga002.h"
#include "math.h"
#include "stdio.h"
#include "string.h"
_CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & FWDTEN_OFF )
_CONFIG2(IESO_OFF & FNOSC_FRC & FCKSM_CSDCMD & OSCIOFNC_OFF)
// DATA AND SCK set to 1 or 0
#define DATA_SET_1 LATBbits.LATB3=1
#define DATA_SET_0 LATBbits.LATB3=0
#define DRAIN ODCBbits.ODB3 = 1
#define SCK_SET_1 LATBbits.LATB2=1
#define SCK_SET_0 LATBbits.LATB2=0
#define DATA_OUT TRISBbits.TRISB3 = 0
#define DATA_IN TRISBbits.TRISB3 = 1
#define SCK_OUT TRISBbits.TRISB2 = 0
#define READ_DATA PORTBbits.RB3
#define MEASURE_TEMP 0x03 // 000 00011
#define MEASURE_HUMI 0x05 // 000 00101
#define TEMP 0
#define HUMI 1
#define NOACK 0
#define ACK 1
// FUNCTION USED TO CREATE THE DESIRED DELAY IN THE PROGRAM
void delay(unsigned int delay_count )
{
int i, j;
for(i=0;i<delay_count;i++)
{
for(j=0;j<delay_count;j++)
{
asm volatile("nop");
}
}
}
void connection_reset()
{
DATA_SET_1;
delay(5);
int i;
for (i=0;i<10;i++)
{
SCK_SET_1;
delay(50);
SCK_SET_0;
delay(50);
}
}
void main()
{
AD1PCFG = 0xff;
DRAIN;
int test = 1;
unsigned int i =0;
//unsigned char value=0;
//unsigned int error;
//unsigned char value=0;
//trans_start();
delay(400); // 11 ms after start up
SCK_OUT;
DATA_OUT;
connection_reset();
delay(50);
//DATA_SET_1;
delay(50);
SCK_SET_0;
delay(50);
DATA_SET_1;
delay(50);
SCK_SET_1;
delay(50);
DATA_SET_0;
delay(50);
SCK_SET_0;
delay(50);
SCK_SET_1;
delay(50);
DATA_SET_1;
delay(50);
SCK_SET_0;
delay(50);
for (i=0x80;i>0;i/=2) //Transmitting the command
{
if (i & MEASURE_HUMI)
DATA_SET_1;
else
DATA_SET_0;
delay(50);
SCK_SET_1;
delay(50);
SCK_SET_0;
}
DATA_IN;
while (READ_DATA==1)
{
}
test=0;
}
According to the datasheet the maximum frequency is 1 Mhz if power supply is less than 4.5V. I am using a power supply of 3.3 V and my frquency is very low about 8 Hz.
Any help is greatly appreciated.