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

I2C slave in EX_SLAVE.C

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



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

I2C slave in EX_SLAVE.C
PostPosted: Wed Nov 01, 2006 4:33 am     Reply with quote

Hello
Given the following code [16F88] (extracted from EX_SLAVE.C):
Code:

#INT_SSP
void ssp_interupt ()
{
   BYTE incoming, state;

   state = i2c_isr_state();

   if(state < 0x80)                     //Master is sending data
   {
      incoming = i2c_read();
      if(state == 1)                     //First received byte is address
         address = incoming;
      if(state == 2)                     //Second received byte is data
         buffer[address] = incoming;
   }
   if(state == 0x80)                     //Master is requesting data
   {
      i2c_write(buffer[address]);
   }
}

I tried to simulate it on PROTEUS - ISIS.
I had to replace
Code:
if(state == 1)
to
Code:
if(state == 0)

and
Code:
if(state == 2)
to
Code:
if(state == 1)
to make it work.
Where's the bug? CCS or PROTEUS?
(I didnt try it physically)

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 02, 2006 1:07 am     Reply with quote

The i2c_isr_state() function looks at the DA and RW bits in the SSP
control registers. If Proteus emulates those bits incorrectly, then
you will have a problem.

If you want to research it further, here is some more information
on the i2c_isr_state() function:

This post shows the ASM listing of the i2c_isr_state() function:
http://www.ccsinfo.com/forum/viewtopic.php?t=28531&start=10

This post shows C code which does the same thing as i2c_isr_state():
http://www.ccsinfo.com/forum/viewtopic.php?t=26477&start=3
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Thu Nov 02, 2006 1:17 am     Reply with quote

Thank you
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