View previous topic :: View next topic |
Author |
Message |
Bill_Smith
Joined: 06 Feb 2004 Posts: 26 Location: Curitiba, Brazil
|
TWO I2C BUSSES WITH ONE MICRO |
Posted: Wed Nov 16, 2005 2:31 pm |
|
|
I am trying to setup two separate I2C busses using the same PIC16F819.
For the primary buss, I am using the PIC's hardware SSP module as a I2C SLAVE and this works fine.
#use I2C(SLAVE, SDA=PIN_B1, SCL=PIN_B4, address=0x22, FORCE_HW)
To talk on the secondary I2C buss the PIC16F819 needs to be a software MASTER, so I was thinking of adding a second #use statement after the one above.
#use I2C(MASTER, SDA=PIN_B0, SCL=PIN_B5)
Then I started thinking about it. Won't the second #use statement overwrite the first? When you call the I2C read and write functions, how do they know which port to use? It's a shame that the #use i2c statement doesn't offer a STREAM parameter like the #use rs232 does.
I suppose that I will need to bit-bang the second I2C port unless someone knows a better way.
Thank You.
Bill |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 16, 2005 2:57 pm |
|
|
Here is how I used two i2c busses in a project. I placed the #include
statements for the driver source files at the end of my main project file.
Each driver file is preceded by the #use i2c() statement for its i2c bus.
Code: |
#use i2c(Master, SDA=DS1621_SDA_PIN, SCL=DS1621_SCL_PIN, SLOW)
#include "ds1621.c"
#use i2c(Master, SDA=DS1307_SDA_PIN, SCL=DS1307_SCL_PIN, SLOW)
#include "ds1307.c" |
|
|
|
Bill_Smith
Joined: 06 Feb 2004 Posts: 26 Location: Curitiba, Brazil
|
|
Posted: Wed Nov 16, 2005 4:09 pm |
|
|
Thanks for the quick reply PCM.
So this forces the compiler to marry the PIN and I2C parameters from the #use i2c statement with the i2c_read() and i2c_write() functions within the driver?
When you say that you placed these statements at the end of your main project file, do you mean they are the last statements in your main source file?
Could I not place the the #use i2c() statement in the driver.c file and acheive the same thing?
Anyway, I'll give it a try.
Thanks again.
Bill |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 16, 2005 4:34 pm |
|
|
Quote: | So this forces the compiler to marry the PIN and I2C parameters from the #use i2c statement with the i2c_read() and i2c_write() functions within the driver? |
That's right.
Quote: |
When you say that you placed these statements at the end of your main
project file, do you mean they are the last statements in your main
source file? |
Yes, they are placed right down at the bottom, below main() and below
all other functions that are in that source file. Of course, I have .h files
#included above main(), with function prototypes for the driver files.
Quote: | Could I not place the #use i2c() statement in the driver.c file and acheive the same thing? |
Yes, you could. I just wanted to be able to browse my main source file
and see how everything was configured at a glance. |
|
|
Bill_Smith
Joined: 06 Feb 2004 Posts: 26 Location: Curitiba, Brazil
|
|
Posted: Wed Nov 16, 2005 5:28 pm |
|
|
PCM, I incorporated your changes and everything works fine. Cool Stuff!
Thanks again for all your help.
Bill |
|
|
|