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

Can two master communicate through I2C??

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



Joined: 10 Sep 2003
Posts: 29

View user's profile Send private message

Can two master communicate through I2C??
PostPosted: Tue Aug 03, 2004 12:37 pm     Reply with quote

Does anyone have written any code where two pic18f452 that are configured as master. interacting through I2C?? Is it possible??

Thank you
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 03, 2004 12:54 pm     Reply with quote

Yes, it is called multi-master mode. I have done it with more than 20 devices communicating. Our Synergy line of products do this and works pretty well but I would have choosen a different communication bus.

If you want to check it out:
http://www.lithonia.com/Controls/
karth



Joined: 10 Sep 2003
Posts: 29

View user's profile Send private message

need sample code
PostPosted: Tue Aug 03, 2004 5:57 pm     Reply with quote

Great Mark,

could you show me sample...please
thanks,
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 03, 2004 6:40 pm     Reply with quote

Basically what you do is have the 2 devices sit in slave mode. When one wants to transmit, it switches to master mode and transmits the data. Once it is complete, it goes back to slave mode. I use an ISR for the receive and handle the transmission manually. I actually bit bang the master because the code was written before Microchip implemented firmware master mode. CCS has some examples of the slave code (ex_slave.c) so I won't repost it. What are you trying to do?
kamyip



Joined: 14 Oct 2003
Posts: 10

View user's profile Send private message

PostPosted: Tue Aug 03, 2004 7:10 pm     Reply with quote

Hi Kart,

Like what Mark said, you can have more than 2 master in a I2C bus but be very careful - I2C is deceptively simple. Getting it to run is simple but getting it to run "reliably" without hanging is a nightmare. Below are some of the things you might want to consider:

1) do not use the i2c library provided by the compiler. First we have no idea of what they are doing and second there is no timeout function. Write your own. You can search the web for source code, there are plenty around. For a start you can check out some of the I2C routines in MPLAB C18 library.
2)you must read Microchip errata doc on i2c hardware problem or else you might be wasting precious time on software when the problem is not in the code.
3)put emphasis on bus collision between two masters, to me this is the biggest pain in my i2c bus encounter because if it hangs then your communication channel is gone.
4) to test how robust your code is you could try this: while the bus is running short SCL and SDA repetively. If you have incident that the bus lockup then you will have to go back to your torture chamber for more modification. If this happen in the lab, it will guaranteed to happen in actual site. Trust me, do not that the risk.
5) etc......

good luck :-)
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 03, 2004 7:18 pm     Reply with quote

Quote:

Getting it to run is simple but getting it to run "reliably" without hanging is a nightmare.


After 6 years of testing, trouble shooting, and lots of field experience we have it working pretty reliably Wink I would like to shoot the guys that chose it as our local communication bus!
pat



Joined: 07 Sep 2003
Posts: 40
Location: Adelaide, Australia

View user's profile Send private message

PostPosted: Tue Aug 03, 2004 9:38 pm     Reply with quote

So Mark, given a new design, and the choice of either SPI or I2C, are you saying the preference should be SPI?

The reason I ask is I'm about to design a circuit with a sensor IC that has both SPI and I2C interfaces, and I thought I2C was the way to go as it saves a signal line.

Maybe you mean I2C isn't the best choice for PIC to PIC comms?

Thanks
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Aug 04, 2004 4:47 am     Reply with quote

I am referring to PIC to PIC in a multi-master enviroment. It is too easy for someone to hold a data or clock line low and lock up the bus. Otherwise, I would use I2C.
karth



Joined: 10 Sep 2003
Posts: 29

View user's profile Send private message

PostPosted: Wed Aug 04, 2004 10:42 am     Reply with quote

Great,
Thank you so much for the tips, and warnings.
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