|
|
View previous topic :: View next topic |
Author |
Message |
Saff Guest
|
I2C Multimaster |
Posted: Thu May 22, 2008 7:58 am |
|
|
Apologies to those who feel this question has already been asked, I have run a search of this forum on the topic but I can't see anything that I feel answers my question.
I currently have 3 PIC16F87 chips (but this has the potential to vary in the future) communicating over I2C. Each chip starts out in slave mode and when it needs to transmit/request data from another then it attempts to become the master. Before any chip can become the master of the I2C bus it must check a second custom data bus to see if the I2C bus is currently occupied. Assuming the I2C bus is available, the chip locks the custom bus and then switches to master. After it's finished with the I2C bus it switches back to slave and frees the custom bus.
e.g.
Code: |
//...
#define I2C_ADDRESS ...
#define REMOTE_ADDRESS ...
#use I2C(slave, sda=PIN_B1, scl=PIN_B4, address=I2C_ADDRESS, FORCE_HW)
//...
// Send Data
while(!lock_bus());
#use I2C(master, sda=PIN_B1, scl=PIN_B4)
i2c_start();
i2c_write(remote_node);
i2c_write(data);
i2c_stop();
#use I2C(slave, sda=PIN_B1, scl=PIN_B4, address=I2C_ADDRESS, FORCE_HW)
free_bus();
// ...
// Receive Data
#INT_SSP
void ssp_interupt () {
// Do some i2_read() calls to match writes
// Or transmit data using i2c_write if requested
}
|
It works Which is great. However, it relies on that extra control bus to prevent collisions on the I2C bus. Can I avoid this using multimaster mode - is this an appropriate/correct use? If so, what sort of changes are required?
I'd greatly appreciate help with this because it seems like multimaster I2C is what's wanted but the general consensus among the I2C information sites I can find with Google is that noone uses multimaster so there's no need to suggest how one would use it.
Apologies if I've missed out some crucial information but if you can spare the time to give me some pointers I'll gladly fill in any gaps.
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 22, 2008 2:40 pm |
|
|
Multi-master mode is described in the i2c specification, and in the PIC
data sheet, and in various Microchip Appnotes (with code), and in
Mark's multi-master routines in the CCS Code Library forum. |
|
|
Saff Guest
|
|
Posted: Sat May 24, 2008 5:21 am |
|
|
I've looked at the datasheet for my PIC along with the relevant section of the mid-range mcu family reference manual and the application note regarding use of the SSP module in the I2C™ multimaster environment. All of those were helpful to an extent but mostly in getting me to a position where I felt multimaster was potentially something I should be exploring in preference to wasting pins on the custom bus.
The code in those publications is extrememely useful in determining the low-level exchanges that need to take place for I2C multimaster to work but I'm still unsure as to whether there are higher level C functions to make this task a little easier. Mark's code seems to perform the same exchanges but wrapped up in C.
I may have missed something obvious here, but other posts (e.g. topic 32855) seem to suggest I'd be able to use compiler provided library fuunctions similar to my existing code (e.g #use i2c(MULTI_MASTER, SCL=PIN_C3, SDA=PIN_C4, FAST, FORCE_HW)). Equally, some people say this is a bad idea (e.g. topic 20101).
From what I can find on the 'Net CCS provides 5 library functions for I2C
* I2C_START
* I2C_STOP
* I2C_WRITE
* I2C_READ
* I2C_POLL
How are/Can these be used for multimaster communication? What are the usage differences. Does it actually work or am I wasting precious time looking for an easy solution when I should be writing a library to do this?
Also, am I correct in thinking that multimaster is the correct solution for this? It seems a shame to be wasting pins as I'm doing presently. |
|
|
Saff Guest
|
|
Posted: Fri Jul 18, 2008 5:28 am |
|
|
For anyone who wanted to know...
Later versions of the CCS compiler do seem to provide some support for multimaster - once I found the documentation it does diffrentiate in the return values for some functions (e.g. i2c_write) whether a collision occured.
I've no idea how good the functions are as we don't have that compiler version anyway |
|
|
|
|
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
|