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

I2C PCF8574 READ

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







I2C PCF8574 READ
PostPosted: Mon May 21, 2007 2:46 pm     Reply with quote

Hello,
I have a question about the code posted in the code forum about reading a PCF8574.
The code is ( a little simplified ) :
int IN8574(int device_addr)
{
int io_field;
i2c_write(0x40 | device_addr<<1 | I2CREAD);
io_field=i2c_read(); /* this byte contains the prior conversion result. */
io_field=i2c_read(0); /* returned data is big-endian (msbit first) */
i2c_stop();
return(io_field);
}
But, I alway have 255 for io_field.

So, I use my old code :

byte IN(byte adr)
{
byte datain;
I2C_start();
I2C_write((adr<<1)|0x41);
datain=I2C_read();
I2C_write((adr<<1)|0x41);
I2C_write(0xff);
I2C_stop();
return(datain);
}
And it is working.

Can someone help me to understand where is the problem ?
I use PIC16F877
#use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3,SLOW)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 21, 2007 2:54 pm     Reply with quote

Quote:
int IN8574(int device_addr)
{
int io_field;
i2c_write(0x40 | device_addr<<1 | I2CREAD);
io_field=i2c_read(); /* this byte contains the prior conversion result. */
io_field=i2c_read(0); /* returned data is big-endian (msbit first) */
i2c_stop();
return(io_field);
}

Don't simplify the code. You have left out the i2c_start() from
the driver code that was posted.
Guest








PostPosted: Mon May 21, 2007 3:20 pm     Reply with quote

Embarassed
It's working now
Thanks for the quick answer Smile
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