Pic to pic communication with i2c

Thread Starter

franklin75

Joined Jun 11, 2016
14
Hi everyone! I have just studied at i2c so i write some codes to pic to pic communication use ccsc .my project is soo basic and it is about master pic communicate the another slave pic and the led Which is contact with slave pic blink,but led does not blink.i didn't solve this problem.I am a new in electronic,the forum,and english.I need some suggestion about i2c communication.thanks for helps.
My codes:
MASTER
C:
#include <I2_C_MASTER.h>
#fuses HS,NOWDT,PROTECT,NOLVP,BROWNOUT,PUT
#use delay(clock=20Mhz)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
void main(){
 while(1){
  int data=1;
  i2c_start();
  delay_ms(50);
  i2c_write(0b00001111);//slave adresi
  delay_ms(50);
  i2c_write(data);//veri
 delay_ms(50);
 i2c_stop();
 }//while
}
SLAVE
C:
#include <I2C_SLAVE.h>
#fuses HS,NOWDT,PROTECT,NOLVP,BROWNOUT,PUT
#use delay(clock=20Mhz)
#use i2c(slave, sda=pin_c4, scl=pin_c3,address=0x15)
int data;
void main(){
set_tris_a(0x00);
while(TRUE)
   {
    if(i2c_poll()) {
      data=i2c_read();
      output_toggle(pin_a0);
      delay_ms(50);
      }
   }
}
Mod edit: code tags
 
Last edited by a moderator:

AlbertHall

Joined Jun 4, 2014
12,626
You do have pull-ups on the clock and data lines?
I don't know that compiler so can't really comment on the code, except that I am not keen on all those 50mS delays. Put one delay in the master while loop, say 200mS, and no delays in the slave.
 

Thread Starter

franklin75

Joined Jun 11, 2016
14
You do have pull-ups on the clock and data lines?
I don't know that compiler so can't really comment on the code, except that I am not keen on all those 50mS delays. Put one delay in the master while loop, say 200mS, and no delays in the slave.
Thanks for your suggestion.ı use pullup.
 

ErnieM

Joined Apr 24, 2011
8,415
Hello franklyn, welcome to the forums.

A long time ago I got pic to pic I2C working where read data was sent back and fourth. Getting the master to work was fairly straightforward, but the slave end was difficult working with two pic18f4550 devices and the C18 compiler. I spent an enTire Saturday with a debugger and a scope working out what the slave was doing. My slave code was mostly interrupt code working each part of a transaction.

Without knowing what compiler and library you are using I cannot comment on your method. Also knowing what pic device you are using will help us help you.

Good luck.

(I will be on vacation tomorrow and will not have any access to my previous work or informant as I am leaving my PC home. I might have some suggestions posting thru my tablet.)
 

Thread Starter

franklin75

Joined Jun 11, 2016
14
Hello franklyn, welcome to the forums.

A long time ago I got pic to pic I2C working where read data was sent back and fourth. Getting the master to work was fairly straightforward, but the slave end was difficult working with two pic18f4550 devices and the C18 compiler. I spent an enTire Saturday with a debugger and a scope working out what the slave was doing. My slave code was mostly interrupt code working each part of a transaction.

Without knowing what compiler and library you are using I cannot comment on your method. Also knowing what pic device you are using will help us help you.

Good luck.

(I will be on vacation tomorrow and will not have any access to my previous work or informant as I am leaving my PC home. I might have some suggestions posting thru my tablet.)
thanks for your answer.please send me a some algorithms or codes about i2c communication,also i use interrupt to slave but it didn't work.i find same examples in youtube and i used the same codes which are works properly on proteus but in my pc they did not work.please help me.I interested in communication so i study at electronic and communication engineering in Yıldız technical university in İstanbul.
 

ErnieM

Joined Apr 24, 2011
8,415
Hey Franklin, can you answer what PIC you are using and what compiler?

My flight leaves in 23 hours so I don't have any time to search and post my previous work (which was really just a hack job anyway, not something even I could follow today. But it did work.)
 

Thread Starter

franklin75

Joined Jun 11, 2016
14
Hey Franklin, can you answer what PIC you are using and what compiler?

My flight leaves in 23 hours so I don't have any time to search and post my previous work (which was really just a hack job anyway, not something even I could follow today. But it did work.)
I am using pic16f877 and ccsc complier.have a nice journey.thank you for your help
 
Top