I2C start operation can not complete

General discussion on mikroC.
Post Reply
Author
Message
vagos_19
Posts: 3
Joined: 18 May 2011 08:34

I2C start operation can not complete

#1 Post by vagos_19 » 31 Aug 2011 23:53

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();
}

Alex17
Posts: 11
Joined: 13 Jul 2010 11:52
Location: Slovenia

Re: I2C start operation can not complete

#2 Post by Alex17 » 03 Sep 2011 21:56

I2C modules in PICs are quite sensitive to improper voltage levels on inputs. Make sure LEDs on SCL and SDA pins are turned off and also check pull-ups. You might want to measure voltage on SCL and SDA before starting program and make sure it is 5V.

Also you are using different slave addresses when writing and reading (0xA2 and 0xA0).

Post Reply

Return to “mikroC General”