0

My task is to copy first 255 bytes from external EEPROM (24LC64) to internal (PIC16F877) via i2c bus. I've read AN1488, all datasheets, MikroC gide (oh, yes, I'm using MikroC), but hopeless.. Meaning that my code trys to read smtng but then, reading my PIC's eeprom at programmer (which can't read 24LC64, so I don't even know what's on it, but there is smtng defenately and it is different from what i'm getting), and I'm getting all EEPROM filled by "A2" or "A3". My guess is that it's that first addr, by which I'm addressing to 24LC64. Could you pls inspect my code (it's quite small =)) and point me at my misstakes.

char i;
unsigned short Data;

void main(){
   PORTB = 0;
   TRISB = 0;
   I2C1_Init(100000);
   PORTB = 0b00000010;

   for (i = 0x00; i<0xFF; i++) {
      I2C1_Start();
      I2C1_Wr(0xA2); //being 1010 001 0
      //I'm getting full internal EE filled with what's in brackets from above
      I2C1_Wr(0b00000000);
      I2C1_Wr(i);
      I2C1_Repeated_Start();
      I2C1_Wr(0xA3); //being 1010 001 1
      Data = I2C1_Rd(0);
      I2C1_Stop();

      EEPROM_write(i, Data);  //How could that 1010 001 0 get into here???

      Delay_100ms();
   }

   PORTB = 0b00000000;

   while (1) {

   }
} 

P.S. I've tryed this with sequantial read, but it "reads" (again that "A2"..) only 1st byte.. So i've posted this one..

P.S.S. I`m working in "hardware", no Proteus involved..

P.S.S.S. I can't test writing, because I have only one 24LC64 with important info on it, so it's even pulld up to Vcc on it's WP pin...

Nacky
  • 31
  • 1
  • 9
  • The strangest thing ever happens when i disconnect 24LC64. It still fills all my internal EE with dat "A2". But I can't understand WHY "A2"??? Why not "A3" for example (as it stays after A2) – Nacky May 19 '13 at 13:47

1 Answers1

1

This isn't a specific answer but more of a checklist for I2C comms, since it's difficult to help with your problem without looking at a scope and without delving into the API calls that you've provided.

  1. Check the address of your EEPROM. I2C uses a 7-bit address with a R/W bit appended to the end, so it's easy to make a mistake here.
  2. Check the command sequence that your EEPROM expects to receive for a "data read"
  3. Check how the I2C_ API that you're using deals with acks from the EEPROM. They need to be handled somewhere (usually in an ISR) and it's not obvious where they're dealt with from your example.
  4. Check that you've got the correct pull-ups on SDA and SCL as per the requirements of your design - they're needed for I2C to work.
Ed King
  • 1,833
  • 1
  • 15
  • 32