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 slave is not working with 16f1938

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



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

I2C slave is not working with 16f1938
PostPosted: Tue Nov 22, 2011 12:45 am     Reply with quote

I2C slave is working when master requests one byte to read only. Every time when I2C master reads more than one byte, 16F1938 will hold clock line to be low until reset the chip.
Please help.
Howard

Here is slave interrupt:
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]);

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Tue Nov 22, 2011 9:48 am     Reply with quote

Of course it will......
You are not loading any data for the master to read, if it asks for more than one byte. I2C_ISR_STATE, will return 0x81, then 0x82 etc.. For these values the code does nothing, so the clock will be held low, waiting for the buffer to be loaded....

Best Wishes
kongfu1



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

PostPosted: Tue Nov 22, 2011 12:26 pm     Reply with quote

Ttelmah wrote:
Of course it will......
You are not loading any data for the master to read, if it asks for more than one byte. I2C_ISR_STATE, will return 0x81, then 0x82 etc.. For these values the code does nothing, so the clock will be held low, waiting for the buffer to be loaded....

Best Wishes


Thanks for your quick reply. That was my mistake.
Another word is that, is there any hw timeout of PIC to release I2C clock line if the buffer was never loaded? In my case, reset PIC is only way to release I2C clock line.

Thanks,
Howard
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 22, 2011 3:30 pm     Reply with quote

At the end of these threads, Ttelmah discusses how to implement
timeouts in i2c routines:
http://www.ccsinfo.com/forum/viewtopic.php?t=34634
http://www.ccsinfo.com/forum/viewtopic.php?t=43052
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