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 support@ccsinfo.com

16F886 as an I2C Slave?

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








16F886 as an I2C Slave?
PostPosted: Thu Feb 26, 2009 4:26 pm     Reply with quote

Has anyone gotten this to work? Unfortunately, I was counting on this in my design. I recently discovered the errata sheet, which lists some workarounds. I guess I'll be trying them. I am really wishing I had picked an older chip about now.
Guest








PostPosted: Thu Feb 26, 2009 11:06 pm     Reply with quote

Actually, I have it working now. My compiler is version 4.086. I noticed that the I2C_Read() would return a value even if the slave was stopped at a breakpoint. I then figured that the master might be reading before the slave had time to respond. I put a 1 MS delay before the read and the master gets the proper data.

I believe that the delay is just a workaround, but at least I can make some progress again. I think the master should wait for the slave, maybe the slave is not stretching the clock properly. There is some info in the 16F886 errata sheet, but I haven't digested it completely. I plan to look at it some more in the near future.

Here is the code fragment that worked:

Code:

// Read from the slave board and display the data.
i2c_start();
i2c_write(0xA0);   // send i2c address w/ read bit clear
i2c_write(0x00);    // send data address
i2c_start();      // restart for read
i2c_write(0xA1);   // send i2c address w/ read bit set
delay_ms(1);            // wait for slave to respond
data = i2c_read(0);   // read data w/ no ack
i2c_stop();
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