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

18F2480 I2C problem

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



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Fri Mar 10, 2006 9:10 am     Reply with quote

Well, I've solved it! Sort of.

I tracked the problem down to the line in the slave ISR "incoming = i2c_read();". It was getting stuck in there. Checking the assembly listing revealed just three instructions; it was checking the SSPSTAT "buffer full" flag and waiting until it got set before processing the data in the buffer. The flags must have been clear, but surely it should have been set (otherwise the interrupt wouldn't have been generated)? I couldn't find any code that clears that flag.

The fix was to replace that line with "incoming = *0xFC9;", i.e. ignore the buffer full flag and just read the buffer anyway.

I've checked the code for my previous I2C project (16F88 master and 18F4580 slave) and the code looks the same! Makes me very nervous that what looks like identical code should work in one place and not another!
_________________
Andrew
mpfj



Joined: 09 Sep 2003
Posts: 95
Location: UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Mar 10, 2006 9:42 am     Reply with quote

andrewg wrote:
I tracked the problem down to the line in the slave ISR "incoming = i2c_read();". It was getting stuck in there. Checking the assembly listing revealed just three instructions; it was checking the SSPSTAT "buffer full" flag and waiting until it got set before processing the data in the buffer.

You could use the i2c_poll() function which returns TRUE is there's a received byte waiting in the buffer.

e.g.
Code:
   // if we've received some data ...
   if (i2c_poll()) {
      // read rxed byte
      rx_char = i2c_read();
   }
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Fri Mar 10, 2006 10:47 am     Reply with quote

You're right! Thanks, that looks much better.

I think ex_slave.c could do with an overhaul...
_________________
Andrew
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