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, set a variable address

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



Joined: 04 Dec 2006
Posts: 41

View user's profile Send private message

i2c slave, set a variable address
PostPosted: Tue Dec 18, 2007 8:09 pm     Reply with quote

I've got an application where I'm talking to several identical cards. Each card has a PIC set up as an i2c slave. Each card needs to operate at a different i2c address. For this go 'round, I can get an address off some ID bits from the backplane. Later, I may have to do this again but have some kind of arbitration where the slave talks on address 0 and then switches to its own address.

So I tried putting a variable in the #USE statement and found that to be illegal. This means I will have to stuff the address into SSPADD at some point. What I'm concerned about is having the i2c library changing SSPADD on me. I also have master code on some other pins so I have to put #USE i2c here and there to be sure the right bus is in use.

I also don't want to specify some random address and hope to change it over before accidentally receiving something at that address. I seem to be able to #USE i2c(SLAVE) without specifying an address. Does that really leave it as is?

I know I can examine the LST file and maybe discover where the code is, but I'd rather have some real knowledge about it, and not base my code on some reverse-engineered theories.

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 18, 2007 8:50 pm     Reply with quote

Quote:
I know I can examine the LST file and maybe discover where the code is

That's what we do in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=29557&highlight=sspadd
barryg



Joined: 04 Dec 2006
Posts: 41

View user's profile Send private message

PostPosted: Wed Dec 19, 2007 4:30 pm     Reply with quote

I said I was hoping to find a method I'd have more confidence in, but I guess this is the way for now.

While I'm here, some more findings:

Code:
    #use i2c(SLAVE, SCL=SCL_SLAVE, SDA=SDA_SLAVE, address=0x83, FORCE_HW)

  MOVLW  83
  MOVWF  FC8
An odd address is sort of nonsense, but it does what you tell it...

Code:
    #use i2c(SLAVE, SCL=SCL_SLAVE, SDA=SDA_SLAVE, FORCE_HW)

  CLRF   FC8
Leaving out the address results in it being set to zero, rather than being skipped!

But it does happen only in main (so far).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 19, 2007 4:38 pm     Reply with quote

The address should not be odd. Here is an example of how to change
the slave address in your program:
Code:

#byte SSPADD = 0xFC8

void main()
{
int8 slave_address;


slave_address = 0x80;

SSPADD = slave_address;

while(1);
}
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Dec 20, 2007 9:58 am     Reply with quote

Like PCM stated, your slave address cannot be odd. This is because the LSB is used to determine if the command is a write or read.

Ronald
barryg



Joined: 04 Dec 2006
Posts: 41

View user's profile Send private message

PostPosted: Thu Dec 20, 2007 1:14 pm     Reply with quote

I thought my use of the word "nonsense" would make it clear I knew this was inappropriate. But really, I was testing to see just what the compiler would take.

As far as "cannot", well, I just did. Presumably the odd bit gets stored in SSPADD. Proving that it is, and demonstrating whether it's ignored, or just what it does to address recognition, ...is left to the student Wink
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