Continue to Site

24LC512 memory help please

Status
Not open for further replies.

latecomer

Member level 4
Member level 4
Joined
Jun 6, 2001
Messages
77
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,288
Location
USA
Activity points
642
Hello all,
I'm trying to use a 24LC512 memory connected to a PIC16F877.
Can someone post some HTPIC code for accessing the memory ? I'm unable to figure out how to use the 16 bit addressing for the memory as the library file(i2c.c) included in the HTPIC is supporting 8-bit address compatible for 24LC04 and similar stuff.

Thanks in advance.
 

UINT offset;(16 bit adress value)
unsigned char highByte = offset>>8;
unsigned char lowByte = offset&0xff;
sample write sequence for 16 bit
I2CStart();
I2CWrite(m_eepromWriteAddress);
I2CGetAck I2CWrite(lowByte);
iI2CGetAck }
I2CWrite(highByte);

I2CWrite(data);
iI2CGetAck();
I2CStop();

.........................

following read or write sequence
 

void write_ext_eeprom( int address, char data)
{
chart status;
i2c_start();
i2c_write(0xa0);
i2c_write(address>>8);
i2c_write(address);
i2c_write(data);
i2c_stop();
i2c_start();
status=i2c_write(0xa0);
while(status==1)
{
i2c_start();
status=i2c_write(0xa0);
}
}


char read_ext_eeprom(int address) {
char data;
i2c_start();
i2c_write(0xa0);
i2c_write(address>>8);
i2c_write(address);
i2c_start();
i2c_write(0xa1);
data=i2c_read(0);
i2c_stop();
return(data);
}
 

Thanks to "bilgekaan" and "TheHungry" . THe bug has been fixed and the data is being written and read from the chip. Now I have a new problem. Unless I use a delay of 15msec between each byte being written to the chip, junk data appears in the chip. Is this normal or is there some problem in my code. I'm using a PIC16F877 at 20Mhz. Previously 24LC04 in the same socket worked well without any 15msec delays. Any suggestions ?
 

latecomer ,

you dont need to wait for such a long time for as you told. generaly 2ms is enough per every page write sequence.

check your power supply to 24LC512 memory , is it noisey? i2c memory devices
are very fragile to noise.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top