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

TWO I2C BUSSES WITH ONE MICRO

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



Joined: 06 Feb 2004
Posts: 26
Location: Curitiba, Brazil

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

TWO I2C BUSSES WITH ONE MICRO
PostPosted: Wed Nov 16, 2005 2:31 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 16, 2005 2:57 pm     Reply with quote

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

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

PostPosted: Wed Nov 16, 2005 4:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 16, 2005 4:34 pm     Reply with quote

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

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

PostPosted: Wed Nov 16, 2005 5:28 pm     Reply with quote

PCM, I incorporated your changes and everything works fine. Cool Stuff!

Thanks again for all your help.

Bill
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