EEPROM write delay

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

datasheet of 24C512(EEPROM) have this information about write operation:

"Write Operations
BYTE WRITE: A write operation requires two 8-bit data
word addresses following the device address word and
acknowledgment. Upon receipt of this address, the
EEPROM will again respond with a zero and then clock in
the first 8-bit data word. Following receipt of the 8-bit data
word, the EEPROM will output a zero. The addressing
device, such as a microcontroller, then must terminate the
write sequence with a stop condition. At this time the
EEPROM enters an internally-timed write cycle, tWR, to the
nonvolatile memory. All inputs are disabled during this write
cycle and the EEPROM will not respond until the write is
complete."
--------------------------------

internally-timed write cycle, tWR=10ms(max) is also mentioned in that datasheet.

That means after write one byte in a particular address I have to give 10ms delay, then write another address and so on...

like this:
EEPROM_write_byte(address,data);
_delay_ms(10);
EEPROM_write_byte(address,data);
_delay_ms(10);

But if i need to write 20K Byte data then it will take a long time.

If it is then how can I reduce the write operation time???

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

harunduet wrote:
If it is then how can I reduce the write operation time???

Use the page write operation.

Also, the write cycle time has a max of about 10ms, but can be shorter. Instead of using a fixed delay, you can poll for the completion of a write. See the section titled "acknowledge polling".

- S

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In practice, the page-write is about 3ms with polling. So 512 pages (64kB) will take about 1.5 seconds.

Contrast 1.5 secs with worst case single-byte writing e.g. 64kB @ 10ms is 655 seconds.

This is not much problem especially when you consider the convenience of I2C bus.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
like this:
EEPROM_write_byte(address,data);
_delay_ms(10);
EEPROM_write_byte(address,data);
_delay_ms(10);

The _delay_ms() in there suggests you might be talking about avr-gcc yet the EEPROM functions suggest some other compiler as in avr-gcc the functions are eeprom_write_byte() not EEPROM_write_byte()?

If it is avr-gcc you are talking about then you do not need to insert additional delays. The eewr_ functions block on the EEPROM being ready for a write operation anyway. From the source off eewr_byte.S:

1:	sbic	_SFR_IO_ADDR (EECR), EEWE
	rjmp	1b

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

IS this the code(below) for acknowledge polling ?
---------------------------------------------
TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);

while (!(TWCR & (1<<TWINT)));

if ((TWSR & 0xF8) == 0x18 )
return(0);
else
return(1);
----------------------------------------------
if it is then may I use that inside a function like

unsigned char acknowledge_polling()
{
}

And if I use this function instead of _delay_ms(10) is it works?
like this:
EEPROM_write_byte(address,data);
acknowledge_polling();
EEPROM_write_byte(address,data);
acknowledge_polling();

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh my apologies (I should learn to read). You are talking about an external EEPROM. While you may be able to do this with 10ms delays I'm kind of surprised that the device itself does not have some mechanism to say when it is ready for the next command. Many memory devices have some mechanism to poll their busy state. This may well involve you waiting as long as 10ms for completion but very often won't so the code will run quicker than hard coded 10ms delays allow.

EDIT: yup the datasheet has this:

Quote:
ACKNOWLEDGE POLLING:
Once the internally-timed write cycle has started and the EEPROM inputs are disabled, acknowledge polling can be initiated. This involves sending a start condition followed by the device address word. The Read/Write bit is representative of the operation desired. Only if the internal write cycle has completed will the EEPROM respond with a “0”, allowing the read or write sequence to continue.

So don't use hard delays - write a EEPROM_wait_complete() style function and use that in place of the _delay_ms() calls. Or actually it sounds like you just incorporate this in to the start of the EEPROM_write_byte() function so it simply doesn't start the write until the last operation has completed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No. You have not understood. If you write one byte at a time, it will take a very long time. e.g. 20kB * 3ms = 6 seconds even if you poll.

You tend to write large chunks of data at any one occasion. So you fill the page buffer, and write the page as required.

Regarding polling. Use a respected library. e.g.

while (i2c_open(0xA0) != GOOD) ;  // wait while busy
i2c_write(data0);                 // fill buffer
i2c_write(data1);                 // ditto
...
i2c_stop();                       // write the page

If you create a i2c_writeblock() function, you can send an arbitrary number of bytes. Writing each page as required.

Your acknowledge_polling() function simply tests whether the bus is free. You need to ask if your eeprom is ACKing its slave_address.

David.