View previous topic :: View next topic |
Author |
Message |
karth
Joined: 10 Sep 2003 Posts: 29
|
Can two master communicate through I2C?? |
Posted: Tue Aug 03, 2004 12:37 pm |
|
|
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
|
|
Posted: Tue Aug 03, 2004 12:54 pm |
|
|
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
|
need sample code |
Posted: Tue Aug 03, 2004 5:57 pm |
|
|
Great Mark,
could you show me sample...please
thanks, |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Aug 03, 2004 6:40 pm |
|
|
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
|
|
Posted: Tue Aug 03, 2004 7:10 pm |
|
|
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
|
|
Posted: Tue Aug 03, 2004 7:18 pm |
|
|
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 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
|
|
Posted: Tue Aug 03, 2004 9:38 pm |
|
|
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
|
|
Posted: Wed Aug 04, 2004 4:47 am |
|
|
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
|
|
Posted: Wed Aug 04, 2004 10:42 am |
|
|
Great,
Thank you so much for the tips, and warnings. |
|
|
|