sequence for writing to and reading from I2C EEPROM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

sequence for writing to and reading from I2C EEPROM

841 Views
mehdikarimibiuk
Contributor V

My chip is MK60DN512VLL10 and I am using I2C1 for writing to and reading from an external EEPROM that we have on our board. I checked with the datasheet of the EEPROM and it gives the following sequence. My I2C is isr based such that when sent and received are true I come out of the following while loops. The datasheet for the EEPROM is located at: http://www.xilinx.com/products/boards/ml505/datasheets/6485.pdf

My I2C device 7-bit address is 0x57.

 

main () {

UINT8 Data[10];

UINT8 passin;

UINT16 addr16;

UINT8 putin[5];

 

//1-WRITING (look at page 9 of the EEPROM link I provide):

passin = 0x57;

I2C1_SelectSlaveDevice(I2C1ptr, LDD_I2C_ADDRTYPE_7BITS, passin);

 

addr16 = 0x0000; //select address 0x0000 in EEPROM

Sent = 0;

I2C1_MasterSendBlock(I2C1ptr, &passin , 2, LDD_I2C_NO_SEND_STOP);

while (Sent == 0){}

 

passin = 0xAA; //write value 0xAA to that address

Sent = 0;

I2C1_MasterSendBlock(I2C1ptr, &passin , 1, LDD_I2C_NO_SEND_STOP);

while (Sent == 0){}

 

//2-READING (look at page 11 of the datasheet I provided):

passin = 0x57;

I2C1_SelectSlaveDevice(I2C1ptr, LDD_I2C_ADDRTYPE_7BITS, passin);

 

addr16 = 0x0000; //select address 0x0000 in EEEPROM

Sent = 0;

I2C1_MasterSendBlock(I2C1ptr, &passin , 2, LDD_I2C_NO_SEND_STOP);

while (Sent == 0){}

 

  passin = 0x57;

  I2C1_SelectSlaveDevice(I2C1ptr, LDD_I2C_ADDRTYPE_7BITS, passin);

 

  Received = 0;

  I2C1_MasterReceiveBlock(I2C1ptr, putin, 5, LDD_I2C_SEND_STOP);

  while (Received == 0){}

  printf("E2PRM reading: 0x%x 0x%x 0x%x 0x%x 0x%x\n", putin[0], putin[1],putin[2],putin[3],putin[4]); //READING VALUES

 

}

 

But I do not get the 0xAA back. Why? Is there any other way to do this? Or am I making any mistakes here?

 

I am reading all 0xff back!

"E2PRM reading: 0xff 0xff 0xff 0xff 0xff"

Labels (1)
Tags (4)
0 Kudos
0 Replies