Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem in i2c communication using pic 16f886

Not open for further replies.


Member level 1
Apr 19, 2015
Reaction score
Trophy points
Activity points
Hey guys ....

I am using 1 pic16f886 as a master and another pic16f886 as a slave communicating each other by means of an i2c bus..

The idea is to send a simple text from 1 master to many slaves but I have limited my code to test for just a single slave only.
The message is first recieved by a data reg through UART from the PC.From this data register the data is sent bit by bit via a i2c bus

The Problem i think is with the write function of i2c in my master code but I am not able to debug properly.

Also I am using UART along with i2c for message printing etc.

Pls check in my master and my slave code disregarding the functionality of UART since it works fine,but my i2c is a no-go.(also forget the switch case used to send to many slaves).

The 2 master and slave C files are attached .

View attachment

Also I forgot to mention that the c code is written for xc8 compiler.


I tried checking your code(though i dont code in C but atleast i can read some of it) but what i can see though i might be wrong, in your code for the slave i cant see where an address is defined for the slave, and how its going to know that its the one to receive the message and act on it.

i think you check very well and act on it.

and again since you did not post any circuit here i hope you attached pullup resistors on the lines (sclk and sdata).

Hope this helps


Hey ,

I tinkered a bit about i2c and changed my code .
Also I changed the addressing part of my slave as u had pointed out.
I have attached my code in a zipped file and also the image of the circuit.



    5.9 KB · Views: 111
  • MCBoard1.pdf
    26.5 KB · Views: 138

Please zip and post your complete MPLAB X XC8 project files for master and slave.

I check that already. It contains only .c files. I nned the complete MPLAB X projects for master and slave so that I can make changes to the code and make it work. I have done I2C master and slave comm in CCS C and mikroC PRO PIC.

Hey guys thanks but I got this ...I resolved the errors in my code bow it's working as expected.

Ok good.

Can you share the result of your success? so that I and everyone can also benefit?

@Milan please can you post a sample code for this a pic - pic i2c communication, thanks


sure il do that ..i am kinda busy for 2 days getting things done here but ill upload by tomorrow :)

@Milan, great work you ve done out there. I dont write codes in C. I use protonbasic but i sure will try porting it to basic.


Here is the attached zipped code containing all the codes etc.Sorry for the delay :)


    35.3 KB · Views: 94

Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to