View previous topic :: View next topic |
Author |
Message |
Joan
Joined: 29 May 2004 Posts: 41 Location: Barcelona, Spain
|
i2c Multi-Slave |
Posted: Sun Jun 20, 2004 4:33 am |
|
|
Hi:
anybody knows how many PIC's can I connect into the i2c bus in multi-slave mode ?
Which Output Capacitance has a PIC in i2c mode ( with and without hardare implementations ) ?
Regads;
Joan. _________________ I Came. I Saw. I Won. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
Numer of I2C devices |
Posted: Sun Jun 20, 2004 7:44 am |
|
|
According to the Phillips I2C bus specification at:
http://www.semiconductors.philips.com/buses/i2c/
I quote:
The number of devices that can be connected to the same
bus is limited only by a maximum bus capacitance of
400 pF.
But the distance is very limited compared to RS232 or RS422.
Capacitance of each device is determined by a number factors and can vary:
1. What type of connections, PC trace, discrete wiring, ribbon cable or ...
2. distance between SDA and SCL conductors
3. distance between devices
4. size of conductors etc. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Sun Jun 20, 2004 9:48 am |
|
|
If you were to utilize bus expanders(buffers) you could probably have devices up to the number of addresses available. |
|
|
Guest
|
|
Posted: Sun Jun 20, 2004 10:17 am |
|
|
Hi:
the exact case is the following. I have 3 PIC16F88 ( 1 Master, 2 Slaves [adress_slave_1=0xa0], [adress_slave_2=0xa1] ).
I'm trying to
write to Slave_1;
delay_ms (500);
write to Slave_2;
dalay_ms (500);
But I can't.
If I only connect Slave_1 to bus all works. If I only conect Slave_2 to bus all works. But if I connect both Slave_1 & Slave_2 to bus it doesn't works. I thought it was possible to be the total bus capacitance.
I had seen that line SCL=1 and SDA=0 when It is delaying_ms(500).
Any Ideas?
Joan. |
|
|
Joan
Joined: 29 May 2004 Posts: 41 Location: Barcelona, Spain
|
|
Posted: Sun Jun 20, 2004 10:23 am |
|
|
Anonymous wrote: | Hi:
the exact case is the following. I have 3 PIC16F88 ( 1 Master, 2 Slaves [adress_slave_1=0xa0], [adress_slave_2=0xa1] ).
I'm trying to
write to Slave_1;
delay_ms (500);
write to Slave_2;
dalay_ms (500);
But I can't.
If I only connect Slave_1 to bus all works. If I only conect Slave_2 to bus all works. But if I connect both Slave_1 & Slave_2 to bus it doesn't works. I thought it was possible to be the total bus capacitance.
I had seen that line SCL=1 and SDA=0 when It is delaying_ms(500).
Any Ideas?
Joan. |
I don't remember to Log-in
Joan _________________ I Came. I Saw. I Won. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
I2C slaves |
Posted: Sun Jun 20, 2004 10:43 am |
|
|
How far apart are they and how are they connected to the master? |
|
|
Guest
|
|
Posted: Sun Jun 20, 2004 1:05 pm |
|
|
Hi:
about your questions, one Slave is connected on the same protoboard that Master is ( about 5cm ). The Second Master is at 15 cm aprox.
in another protoboard.
Both are connected with 2 pull-up resistors of 2k7 Ohms in the SDA and SCL lines. ( I also try with 10k Ohm but doesn't works ).
Regards;
Joan |
|
|
Joan
Joined: 29 May 2004 Posts: 41 Location: Barcelona, Spain
|
|
Posted: Sun Jun 20, 2004 3:25 pm |
|
|
Hi:
I've inserted a little code into the interrupt i2c routine that send to RS-232 the data that pic is receiving from i2c bus. That's the result:
With 2 Slaves connected to bus instead the command I'd send
write_i2c (0x0a);
write_i2c(5);
delay_ms(500);
write_i2c(0xa1);
write_i2c(5);
delay_ms(500)
The Slave_1 [adress_slave_1=0xa0] receive
0x41
0x0b
0x43
0x0b
When I disconnect one of the 2 PIC's the data received by the Slave is:
0xa0
0x05
0xa1
0x05
Obviously the connection of the second slave loads the bus changing the data that master transmits, but why?
Regards;
Joan _________________ I Came. I Saw. I Won. |
|
|
Joan
Joined: 29 May 2004 Posts: 41 Location: Barcelona, Spain
|
|
Posted: Sun Jun 20, 2004 4:08 pm |
|
|
Hi:
Problem solved. The question is about delay_cycles():
Next to interpreting the bad results versus the good results:
[0xa0] -> 10100000 [0x41] -> 01000000
[0x05] -> 00000101 [0x0b] -> 00001011
[0xa1] -> 10100001 [0x43] -> 01000011
[0x05] -> 00000101 [0x0b] -> 00001011
I thought that the questions is a bit shifting .. so I've inserted the red lines:
i2c_start(); // Start condition
delay_cycles( 24 );
i2c_write(0xa0); // Device address
delay_cycles( 24 );
i2c_write(5); // Write Command
i2c_stop();
And that's all. I don't know why this aditional delay is needed when there are more that 1 slave conneted into the i2c bus. But it works for me.
The problem is solved, but anybody knows why this occurs?
Best Regards;
Joan. _________________ I Came. I Saw. I Won. |
|
|
akiashiba
Joined: 20 Jun 2004 Posts: 2
|
|
Posted: Mon Jun 21, 2004 7:53 am |
|
|
Code: | the exact case is the following. I have 3 PIC16F88 ( 1 Master, 2 Slaves [adress_slave_1=0xa0], [adress_slave_2=0xa1] ). |
Perhaps, you make some wrong add here.
The first bit0 is R/W bit of each slave address. So, each time you send the address of slave2, it will know that it's the slave1 at READ mode. And you cannot write to the slave 2
Try with slave1_add = 0xa0 and slave2_add = 0xb0
I'm not familiar with CCS C, but I know it is wrong addresses for 2 slave. I'm sure. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Mon Jun 21, 2004 8:53 am |
|
|
You can't have an address of 0xA1. The LSB of the address bit is the R/W bit for the command word. You need to have 0xA0, 0xA2, 0xA4, 0xA6 and so on for addresses. The Slave that is at address 0xA0 will have the command 0xA0 sent to it indicating that data will be written to it. An address of 0xA1 will tell the Slave that data will be read from it.
So, if the second Slave is at address 0xA2, sending a 0xA2 will be writing data to it and an address of 0xA3 will be reading data from it.
Clear as mud?
Ronald |
|
|
Joan
Joined: 29 May 2004 Posts: 41 Location: Barcelona, Spain
|
|
Posted: Mon Jun 21, 2004 11:20 am |
|
|
Hi guys:
I'd proved with these 2 options:
slave_adress_1=0xa0;
slave_adress_2=0xa2;
and next with
slave_adress_1=0xa0;
slave_adress_2=0xb0;
and woks too. But if I delete the lines with delay_cycles(); they don't work.
Yes, the slave_adress_2 can't be 0xa1, but changing it by 0xa2 or 0xb0 I can't solve the thing that the info I've send to i2s bus change misteriously.
Regards;
Joan _________________ I Came. I Saw. I Won. |
|
|
falleaf
Joined: 23 May 2004 Posts: 48
|
|
Posted: Tue Jun 22, 2004 1:49 pm |
|
|
hi,
I also don't understand about this. I tried with mike's i2c examples, and I can tx to the slave with ease, but I cannot read from it. I don't know why.
I simply get start condition and call i2c_read(). It's good if I use only one buffer, but as I use more than 1 byte buffers, the results get wrong.
see in "Need i2c examples" thread.
Thanks muchie. |
|
|
|