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

How does the #use i2c change the pin used for SDA SCL?

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



Joined: 15 Jun 2005
Posts: 2

View user's profile Send private message

How does the #use i2c change the pin used for SDA SCL?
PostPosted: Wed Jun 15, 2005 9:43 am     Reply with quote

I don't understand how the #use command changes the pin mappings associated with SDA and SCL as in below:

Code:
#use i2c(Slave,Slow,sda=PIN_A1,scl=PIN_A2,force_hw,address=0xa0)


I'm using a 16F87x PIC

Tully
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 15, 2005 3:23 pm     Reply with quote

The #use i2c() statement configures the CCS i2c library code that
is inserted into your program. If you look at the .LST file, you'll
see that the pins, and the TRIS bits for those pins, are accessed
with several BCF and BSF instructions.

I think your real question may be this:

Does the compiler insert only one instance of the i2c library code, and
is this code re-configurable "on the fly", with respect to changing the
pins that are used ? Or does the compiler insert a separate instance
of code for each #use i2c() statement ?

Answer:
A separate instance of the library code is inserted for each #use i2c
statement.
Ttelmah
Guest







PostPosted: Thu Jun 16, 2005 9:03 am     Reply with quote

Also it is perhaps important to realise that there are two 'core' libraries associated with the I2C operation (as with serial). So if you use the pins that are assigned to the internal hardware port, the compiler automatically uses this hardware. If you use any other pins, _software_ emulations are used instead. These have limitations (master only, no address recognition etc.). So the compiler does not remap SDA, and SCL, but generates software to emulate the function of these.

Best Wishes
tully



Joined: 15 Jun 2005
Posts: 2

View user's profile Send private message

PostPosted: Thu Jun 16, 2005 12:24 pm     Reply with quote

Ok. So the CCS uses a library function code to emulate the I2C slave in software and this can't be as efficient as the hardware version.

My application runs unattended as a slave with occasional prompts from a busy I2C bus - I'll need to use pins RC3 & RC4 or another PIC to do the I2C interface.

Thanks for your help.
Ttelmah
Guest







PostPosted: Thu Jun 16, 2005 2:16 pm     Reply with quote

The software I2C, only supports _master_.
The problem is that for 'slave', the code would have to sit like an RS232 getc, constantly polling the lines. If you look at the manual, and th entry for '#use I2C', you will see that it says that "The slave mode should only be used with the built in SSP". Several of the functions will not even work with the software implementation (I2C_poll for example).
If you want a slave, you have to use the hardware pins.

Best Wishes
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