Thank you people for helping me. I finally managed to complete the project. There is now one small issue but it is not related to i2c but to LCD. If anybody can help me then I would really appreciate it.
Maybe it is a bug of mikroC.
Even though datas of slaves are printed on different lines of masters' LCD in code the datas are printing on the same line.
Regarding I2C comm I used the example from here.
ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2003/158
Eady-158.zip
I used the same ISR code but added a dummy i2c read after write and it solved the problem of code not working with more than 1 slave PICs.
I tested it in both Proteus and hardware and it is working fine in both. The signals on my Saleae Logic Analyzer is good but the LCD problem remains in hardware also.
broken link removed
- - - Updated - - -
I had done a silly mistake while copy pasting a part of the masters' code. I fixed it and LCD works fine. Here is the fix.
This completes my project.
Code C - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| // Read from the slave 1
I2C1_Start();
I2C1_Wr(0xA0);
I2C1_Repeated_Start();
I2C1_Wr(0xA1);
value1.b[0] = I2C1_Rd(1);
I2C1_Repeated_Start();
I2C1_Wr(0xA1);
value1.b[1] = I2C1_Rd(1);
I2C1_Repeated_Start();
I2C1_Wr(0xA1);
value1.b[2] = I2C1_Rd(1);
I2C1_Repeated_Start();
I2C1_Wr(0xA1);
value1.b[3] = I2C1_Rd(0u);
I2C1_Stop();
Delay_ms(1000);
// Read from the slave 1
I2C1_Start();
I2C1_Wr(0xA6);
I2C1_Repeated_Start();
I2C1_Wr(0xA7);
value2.b[0] = I2C1_Rd(1);
I2C1_Repeated_Start();
I2C1_Wr(0xA7);
value2.b[1] = I2C1_Rd(1);
I2C1_Repeated_Start();
I2C1_Wr(0xA7);
value2.b[2] = I2C1_Rd(1);
I2C1_Repeated_Start();
I2C1_Wr(0xA7);
value2.b[3] = I2C1_Rd(0u);
I2C1_Stop(); |
broken link removed
- - - Updated - - -
Please don't bang your head like me. See this image.
broken link removed