thanks for your answer.
now I'm doing some project that using I2C interfacing. PIC18F4550 as master and PIC182550 as slave.
I actually can't communicate those IC's yet. Do you know how to use i2c.h library to configure PIC18F2550 as a slave?
for the master configuration I'm already done. The sample code for the master configuration as shown below.
void i2c_start(unsigned char address, unsigned char size, unsigned operation)
{
unsigned char i;
SSPCON2bits.SEN = 1; //send START
while(!SSPIF); //hold program until progress is completed (SSPIF will be set)
SSPIF = 0; //clear flagbit caused by START
SSPBUF = address + operation; //send addres to slave (operation = 1 if read, 0 if write)
while(!SSPIF); //hold program until data is transmitted (SSPIF will be set if completed)
SSPIF = 0; //clear flagbit caused by transmission
if(operation == write) //if write operaion
{
for(i = 0; i < size; i++)
{
SSPBUF = i2c_master_data[i]; //send data[i]
while(!SSPIF); //hold program until transmission is completed
SSPIF = 0; //clear flagbit caused by transmission
}
SSPCON2bits.PEN = 1; //after all data is transmitted, send STOP
while(!SSPIF); //hold program until progress is completed (SSPIF will be set)
SSPIF = 0; //clear flagbit caused by STOP
}
else if(operation == read) //else read operation
{
for(i = 0; i < size; i++)
{
SSPCON2bits.RCEN = 1; //enable reception
while(!SSPIF); //hold program until progress is completed (SSPIF will be set)
SSPIF = 0; //clear flagbit caused by reception
i2c_master_rcvb[i] = SSPBUF; //store data in rcvb[i]
if(i == (size - 1)) //if last byte, send NACK
SSPCON2bits.ACKDT = 1; //successful transfer data
else //else send ACK
SSPCON2bits.ACKDT = 0;
SSPCON2bits.ACKEN = 1; //send acknowledgement
while(!SSPIF); //hold program until progress is completed (SSPIF will be set)
SSPIF = 0; //clear flagbit caused by acknowledgement
}
SSPCON2bits.PEN = 1; //after all data is transmitted, send STOP
while(!SSPIF); //hold program until progress is completed (SSPIF will be set)
SSPIF = 0; //clear flagbit caused by STOP
}
}