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

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
info@ckmintech.com



Joined: 16 May 2006
Posts: 39

View user's profile Send private message

I2C Slave
PostPosted: Thu Nov 05, 2009 8:13 am     Reply with quote

I need to set up a slave mode I2C. The device need to send out a character according to the character the master device sends

I don't know is the i2c_write() should follow immediate after the i2c_read() or I need to wait under the master device send a read request. I want to know which function is correct.
Code:

#int_SSP
SSP_isr()
{
   int state, n;

   state = i2c_isr_state();

   if(state < 0x80) {  // Master is sending data
      n = i2c_read();
      switch (n) {
         case 0:
            i2c_write( targetID[ 0 ] );
            break;
         case 1:
            i2c_write( targetID[ 1 ] );
            break;
  }

   if(state >= 0x80)  { // Master is requesting data from slave
   }
}

OR
Code:

static int n;
#int_SSP
SSP_isr()
{
   int state;

   state = i2c_isr_state();

   if(state < 0x80) {  // Master is sending data
      n = i2c_read();
  }

   if(state >= 0x80)  { // Master is requesting data from slave
       switch (n) {
         case 0:
            i2c_write( targetID[ 0 ] );
            break;
         case 1:
            i2c_write( targetID[ 1 ] );
            break;
  }
}

Thanks for the help.

Rgds.
epitalon
Guest







PostPosted: Thu Nov 05, 2009 9:35 am     Reply with quote

2nd solution, of course
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