hi2cout limited to 16 bytes at a time?

Memran

Member
Hi all :)
I've come across an anomaly with my project. I'm using an eeprom (24LC16B) and was having difficulty reading from it.

For my test, I was writing a string of characters, and then sertxd-ing it to the terminal.

Code:
#picaxe 08m2
#no_data

pause 1000

'setup eeprom
hi2csetup i2cmaster, %10100000, i2cfast, i2cbyte
pause 100

'reset first 32 bytes to $FF
for b0 = 0 to 255
	hi2cout b0,($FF)
	pause 10
next
pause 100

'write data
hi2cout 0,("01234567ABCDEFGHI")'17 bytes
pause 100

'read eeprom and output to terminal
for b0 = 0 to 16
	hi2cin b0,(b1)
	sertxd (b1)
next
The output is
Code:
I1234567ABCDEFGHÿ
The 17th byte is not written in address 16, but instead it has overwritten address 0.
Is this normal behavior, so that I have to write in 16byte chunks (which does work, by the way) or am I missing something?

Thanks :)
 

nick12ab

Senior Member
You need to put in a short delay between each 16 bytes because of the page write buffer.
All EEPROM memory chips require a ‘write time’ to save the data in the chip. This is
typically 5 or 10ms. When writing lots of data, this can cause a significant delay. To help
overcome this issue, many ICs have a page write buffer that can accept more than one
byte at once (typically 8, 16 or 32 bytes) so that all these bytes can be programmed at
once. This means, for instance, in the case of 8 bytes you only have one 10ms delay, rather
than 80ms of delay. Important Note: One of the biggest mistakes made by beginners is
that they don’t realise that page writes can only ‘start’ at a multiple of the buffer size, and
cannot overflow the page buffer size. In effect this means (for an 8 byte buffer) you can
write 8 bytes up from address 0 (or 8 or 16 etc.) but only up 6 bytes from address 2 (10,
18 etc.), or else you would overflow the 8 byte page write boundary.
ADDED: The fast writing could be causing the circular buffer to overflow so that 17th byte gets written over the first byte.
 

Memran

Member
Thank you, that certainly explains it.

By the way, where did that quoted text come from? I'd like to read more about it. :)
 

westaust55

Moderator
The page size and wrap around effect is also described in the datasheets for all EEPROMs (those I have read).
The page size differs and tends to be bigger as the overall EEPROM capacity increases.

It is always worth reading the Datasheet for any new IC/chip you start using.
 
Top