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

pic18F4550 I2C with HYT-271

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



Joined: 21 Oct 2010
Posts: 85

View user's profile Send private message

pic18F4550 I2C with HYT-271
PostPosted: Tue Dec 03, 2013 1:35 pm     Reply with quote

Hello,

I try to get values from a HYT-271 sensor. The sensor is connected with I2C.
But the sensor will not send data! Crying or Very sad

Has anybody experience with this or similar sensors?

The protocol description is here:
http://www.ist-ag.com/eh/ist-ag/resource.nsf/imgref/Download_AHHYT-I2C_E1.2.pdf/$FILE/AHHYT-I2C_E1.2.pdf

thanks


Last edited by Prefekt on Tue Dec 17, 2013 11:43 pm; edited 2 times in total
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Dec 03, 2013 2:47 pm     Reply with quote

Hi,

Yes, in line 37 of your code replace the '=' with a '==', and that should solve the problem. Also, add 'Errors' to your #use rs232 declaration. Wink

John

PS how are we supposed to offer any constructive suggestions if you don't post your code?
Prefekt



Joined: 21 Oct 2010
Posts: 85

View user's profile Send private message

PostPosted: Wed Dec 04, 2013 1:18 pm     Reply with quote

Very Happy

Ok, in the protocol datasheet are two different commands, DF 'Data Fetch' and MR 'Measuring Request'

The sensor address is 0x28:

first step: send MR with address and last bit = 0 as write
next: send DF with address and last bit =1 as read
next: read Data
next: read Data
next: read Data
next: read Data

I have no experience with i2c... here' a code snippet:

Code:

      i2c_start();
      status = i2c_write(0b01010000);
      if(status != 0)
      {
         printf("MR: no sensor found\n\r");
         continue;
      }
      else
      {
      printf("MR: ok\n\r");
      }
      i2c_stop();
      delay_ms(50);
      i2c_start();
      status = i2c_write(0b01010001);
      if(status != 0)
      {
         printf("DF: no sensor found\n\r");
         continue;
      }
      else
      {
      printf("DF: ok\n\r");
      }
      i[0] = i2c_read();
      i[1] = i2c_read();
      i[2] = i2c_read();
      i[3] = i2c_read();
      i2c_stop();
      printf("%x # %x # %x # %x \n\r", i[0], i[1], i[2], i[3]);
      delay_ms(500);


the output is:

MR: ok
DF: ok
ff # ff # ff # ff
MR: ok
DF: ok
ff # ff # ff # ff
MR: ok
DF: ok
ff # ff # ff # ff
MR: ok
DF: ok
ff # ff # ff # ff
Prefekt



Joined: 21 Oct 2010
Posts: 85

View user's profile Send private message

PostPosted: Tue Dec 17, 2013 11:49 pm     Reply with quote

Now, the sensor is working - sometimes.

The read values are wrong. At the first read / write the sensors answers, but the than ' status = i2c_write(AddressWrite);' failed.

Code:

void GetSensorData(char AddressWrite, char AddressRead)
{
   int status=0;
   int i=4;
   
   i2c_start();
   status = i2c_write(AddressWrite);
   if(status != 0)
   {
      printf("MR: no sensor found at:%x \n\r", AddressWrite);
      continue;
   }
   else
   {
      printf("MR: ok\n\r");
   }
   i2c_stop();   
   delay_ms(100);
   i2c_start();
   status = i2c_write(AddressRead);
   if(status != 0)
   {
      printf("DF: no sensor found at: %x \n\r", AddressRead);
      continue;
   }
   else
   {
      printf("DF: ok\n\r");
   }
   
   for (i=0;i<4;i++)
   {
      messageBuf[i] = i2c_read();
   }
   i2c_stop();
   printf("%x # %x # %x # %x \n\r", messageBuf[0], messageBuf[1], messageBuf[2], messageBuf[3]);
}
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