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

SHT11 hELP ME

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



Joined: 29 Jun 2004
Posts: 5

View user's profile Send private message

SHT11 hELP ME
PostPosted: Tue Jun 29, 2004 4:03 am     Reply with quote

I am undergraduate.
I am currently planning to work on a Project which uses SHT11 humidity sensor.
I hope to modify simple FreeBSD program(DOWN LOADED FROM vitsch.net) with a Sensirion SHT11 to windows platform.
i modify it, but it not work as soon as possible. I sent program with this letter. Please consider my program and explain
Errors of it.(what is the purpose of using (FILE * IO file pointer)).
I got ""Device timed out!!!" error.
Yours,
Yasas


/*
* sensor.c
*
* Interfacing routines for the Sensirion SHT11 Temperature & Humidity sensor
*
* Written by Daan Vreeken
* Danovitsch@hotmail.com
* (or Danovitsch@Danovitsch.dnsq.org)
*
* Published under the terms of the GNU Public License 2.0
* (or any later version)
*/


#include <stdio.h>
#include <dos.h>
//#include <unistd.h>
//#include <err.h>



#define DeviceTimeout 20
#define ReadTimeout 200


/*
void outportb(unsigned short Port, unsigned char Data)
{
unsigned char D = Data;

__asm __volatile("outb %0,%%dx" : : "a" (D), "d" (Port) );
}

unsigned char inportb(unsigned short Port)
{
unsigned char Data = 0;

__asm __volatile("inb %%dx,%0" : "=a" (Data) : "d" (Port) );

return Data;
}
*/
//pin 14 : out: bit 2 of 0x27a
//pin 15 : in: bit 8 of 0x279
//pin 16 : out: bit 4 of 0x27a

int Data(int Level) {
outportb(0x37a,(inportb(0x37a)&4) + 2*(!Level));
delay(1*1000);

return (inportb(0x379)&8)==8;
}

void Clock(int Level) {
outportb(0x37a,(inportb(0x37a)&2) + 4*Level);
delay(1*1000);
}



void Bus_Init(void) {
int Cnt;

//Initiate bus
outportb(0x378,0xff);
Data(1);
Clock(1);

//Connection reset sequence
for (Cnt=0; Cnt<9; Cnt++) {
Clock(0);
Clock(1);
}
}



int Bus_Read(unsigned char Command) {
int Cnt;
int Time;
int ReadData;


//Transmission start
Clock(1);
Data(0);
Clock(0);
Clock(1);
Data(1);
Clock(0);


//Send address & command
for (Cnt=0; Cnt<8; Cnt++) {
if (((Command >> (7-Cnt))&1)==1)
Data(1);
else
Data(0);

Clock(1);
Clock(0);
}


//ACK
Data(1);
Clock(1);

Time=0;
while ((Data(1)==1) && (Time++<DeviceTimeout))
delay(1*1000);
if (Time>DeviceTimeout)
printf("Device timed out!!!%c\n",0x07);

Clock(0);


//Wait for the SHT11 to get it's data ready
Time=0;
while ((Data(1)==1) && (Time++<ReadTimeout))
delay(1*1000);
if (Time>ReadTimeout)
printf("Measurement timed out!!!%c\n",0x07);


//Now clock 2 bytes of data in...
ReadData=0;

for (Cnt=0; Cnt<8; Cnt++) {
Clock(1);

ReadData<<=1;
if (Data(1)==1)
ReadData|=1;

Clock(0);
}
//ACK
Data(0);
Clock(1);
Clock(0);
Data(1);

for (Cnt=0; Cnt<8; Cnt++) {
Clock(1);

ReadData<<=1;
if (Data(1)==1)
ReadData|=1;

Clock(0);
}
//!ACK
Data(1);
Clock(1);
Clock(0);

return ReadData;
}



#define Cmd_ReadTemp 0x03
#define Cmd_ReadHum 0x05




int main(void)
{
//FILE *IO = fopen("G:\progport\a\io.txt","r");

int TempData;
int HumData;

float Temp;
float Humidity;


/*if (IO==NULL) {
printf("could not open /dev/io");
}*/


Bus_Init();

TempData=Bus_Read(Cmd_ReadTemp);
HumData=Bus_Read(Cmd_ReadHum);

Temp=TempData*0.01-40.0;
Humidity=-4.0 + 0.0405*HumData - 2.8*HumData*HumData/1000000;

printf("temp: %.2f hum: %.2f\n",Temp,Humidity);

//fclose(IO);


return 0;
}
Paolino



Joined: 19 Jan 2004
Posts: 42

View user's profile Send private message

PostPosted: Tue Jun 29, 2004 5:04 am     Reply with quote

Someone did it:
http://www.ccsinfo.com/forum/viewtopic.php?t=17108&highlight=sht11
http://www.ccsinfo.com/forum/viewtopic.php?t=17349&highlight=sht11

Maybe you will find more ideas.

Best wishes.

Paolo.
YASAS



Joined: 29 Jun 2004
Posts: 5

View user's profile Send private message

Re: SHT11 hELP ME
PostPosted: Tue Jun 29, 2004 8:42 pm     Reply with quote

Hi all

But I'm try to conectect SHT11 to computer parallel port. I'm never try to connect it to Microcontroller or any athor interface.

so how I generate SCK ,DATA using parallel port

Thank you
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

PostPosted: Tue Jun 29, 2004 9:20 pm     Reply with quote

is there a method by which we can request that these types of threads be moved out of the code library forum and into the general discussion forum, where they belong?

otherwise, before long the code library forum is going to be filled up with posts like this made by people too lazy to read the the Forum Policy post, which is permanently affixed to the top of the thread listing:
http://www.ccsinfo.com/forum/viewtopic.php?t=19215

jds-pic
YASAS



Joined: 29 Jun 2004
Posts: 5

View user's profile Send private message

PostPosted: Tue Jun 29, 2004 9:33 pm     Reply with quote

Sorry about that mistake,

I need some help to connet SHT11 to computer parallel port.

so some one can help me.


yasas
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

PostPosted: Tue Jun 29, 2004 9:52 pm     Reply with quote

YASAS wrote:
Sorry about that mistake,
I need some help to connet SHT11 to computer parallel port.
so some one can help me.
yasas


you are on the wrong forum (this is a code library forum) on the wrong board (this board is for C programming on Microchip PIC embedded microcontrollers), so your chances of getting the assistance you need for connecting this widget to a PC parallel port with a program operating under Windows are exactly nil.

ADMINS -- please move this thread to General!

jds-pic
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