View previous topic :: View next topic |
Author |
Message |
tully
Joined: 15 Jun 2005 Posts: 2
|
How does the #use i2c change the pin used for SDA SCL? |
Posted: Wed Jun 15, 2005 9:43 am |
|
|
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
|
|
Posted: Wed Jun 15, 2005 3:23 pm |
|
|
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
|
|
Posted: Thu Jun 16, 2005 9:03 am |
|
|
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
|
|
Posted: Thu Jun 16, 2005 12:24 pm |
|
|
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
|
|
Posted: Thu Jun 16, 2005 2:16 pm |
|
|
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 |
|
|
|