Hello, I am new at interfacing I2C. The code posted below is an example I discovered while searching. I am using a PIC16F877a which is on the EasyPic 5 board, communicating with a 24C64 EEPROM. The connection between the RC3 and RC4 pins to the corresponding of 24C64 has a 2K resistor as it illustrated in images i found. The problem is that even if the code seems to be right to me, it doesn't work at all. In fact while trying to find out where the problem occurs i find out that the program "stacks" after the "I2C_Start();" command.. Sorry about my poor english.. Can anyone help me??? Thanks in advance!!
Code: Select all
void main(){
PORTB = 0;
TRISB = 0;
I2C_Init(100000); //Clock 100 Khz
I2C_Start();
I2C_Wr(0xA2);
I2C_Wr(2);
I2C_Wr(22);
I2C_Wr(0x34);
I2C_Stop();
Delay_ms(100);
I2C_Start(); // Issue I2C start signal
I2C_Wr(0xA0);
I2C_Wr(2);
I2C_Wr(22);
I2C_Repeated_Start();
I2C_Wr(0xA1);
PORTB = I2C_Rd(0);
I2C_Stop();
}