24LC16b EEPROM explanation, please

nerdegutta

Senior Member
Hi.

Can someone please explain to me how to use the 24LC16b EEPROM?

I need to store 18 bytes as many times as I can.

If I understand correctly:

Block 000 can store 256 bytes
Block 001 can store 256 bytes
Block 010 can store 256 bytes
Block 100 can store 256 bytes
Block 111 can store 256 bytes
Block 110 can store 256 bytes
Block 101 can store 256 bytes
Block 011 can store 256 bytes

8 blocks * 256 bytes = 2048 bytes

I've read the datasheet, and it says 8 * 256 * 8. That would make 16384 bytes. This I don't understand.

How can I use the whole IC,and how do I change between the blocks, after one is full.

Appreciate all help.


- nerdegutta
 

srnet

Senior Member
I've read the datasheet, and it says 8 * 256 * 8. That would make 16384 bytes.
From the datasheet;

"The Microchip Technology Inc. 24AA16/24LC16B (24XX16*) is a 16 Kbit Electrically Erasable PROM. The device is organized as eight blocks of 256 x 8-bit memory"

So 16384 bits or 2048 bytes.
 

nick12ab

Senior Member
I've read it over and over again, but I can't find how to change blocks. Does it start to store in block 000 address 0 and end in block 111 address 256? How would the code look, and how to read back?
As stated in the pdf, the block is selected by the i2c slave address: %1010bbbx

There are 8 blocks and 8 different combinations of 1s and 0s possible for those three bits.
 

Buzby

Senior Member
EDIT *** Ignore this post, it applies to 24LC256 ***

You don't need to worry about 'blocks', you just consider it as 2048 bytes.
The hi2cout and hi2cin instructions handle the 'conversion' for you.

This code writes 32 bytes to the eeprom, starting at byte address 896.
I've no idea what block number it is !.

hi2cout 896, (27, 15, 27, 16, 27, 17, 27, 18, 27, 19, 27, 24, 27, 25, 27, 26, 27, 28, 27, 29, 27, 30, 27, 31, 28, 1, 28, 2, 28, 3, 28, 4)
 
Last edited:

westaust55

Moderator
The 2C16B has a page size of 16 bytes.
This means that:
1. You can write a max if 16 bytes in one write operation (without problems occurring)
2. When writing multiple bytes you can of cross a page boundary witch occurs every 16 bytes (if you get to the end of a page boundary and keep writing as part of a multi byte write the next byte is stored at the first byte in the page block)
Note a page is 1) bytes and a block is 256 bytes
 

MFB

Senior Member
You could use a pin compatible (with the 24LC16b) FRAM chip and forget about input buffer pages and write delays. Pretty much like using a non-volatile RAM device.
 

nerdegutta

Senior Member
So reading the above, would this write code snippet work?

Code:
' Example code to write to 24LC16b EEPROM
' 18 bytes in each storing
' 2048Kb / 18 = 113.77777
' Meaning the EEPROM would hold 112 sets of storing.

symbol counter = b18
symbol addressIndex = b19

symbol MAXCAPACITY = 112

hi2csetup i2cmaster, %10100000, i2cslow, i2cbyte ' configuring the connection to eeprom 24LC16b

init:
	counter = 0		' set counter to zero
	addressIndex = 0	' make sure we start to store at the first addressposition = 0

' write procedure
for counter = 1 to MAXCAPACITY
	hi2cout addressIndex,(b0): pause 10	' addressIndex is zero
	addressIndex = addressIndex + 1: hi2cout addressIndex,(b1): pause 10	'addressIndex is one
'	.
'	.
'	.
	addressIndex = addressIndex + 1: hi2cout addressIndex, (b17):pause 10	'addressIndex is seventeen
next counter
- nerdegutta
 

hippy

Ex-Staff (retired)
You don't need to worry about 'blocks', you just consider it as 2048 bytes. The hi2cout and hi2cin instructions handle the 'conversion' for you.
I don't believe that's correct. You would need to issue a new I2CSETUP command to change between blocks, and each block is only byte addressable; location 256 would be location 0 of the block selected etc.
 

hippy

Ex-Staff (retired)
Untested, to clear an entire 24C16 by writing zero to every location ...

Code:
Symbol address     = w0
Symbol address.lsb = b0
Symbol address.msb = b1
Symbol deviceId    = b2

For address = 0 To 2047
  deviceId = address.msb & %111 * 2 | %10100000
  HI2cSetup I2CMASTER, deviceId, I2CSLOW, I2CBYTE
  HI2cOut address.lsb, (0)
  Pause 10
Next
 

Buzby

Senior Member
Hi hippy,

Sorry, you are right.
I was thinking of the 24LC256. There are no block issues with this chip.

Cheers,

Buzby
 

westaust55

Moderator
@nerdegutta,
Within the programming editor, there is the ability to simulate the operation of a BASIC program.
The simulation (under options toolbar button) allows to to simulate a single EEPROM and you can select a 24LC16B or 24LC256.
Accordingly, you can try some program tests for yourself - in this case writing data to the EEPROM and then read back to see if what you have is what you expect.

Edit: see attached PE screenshot
 

Attachments

Last edited:

nerdegutta

Senior Member
Thanks!

I knew about the EEPROM simulation, but I had no idea you could simulate a 24LC16b.

Thanks alot!

- nerdegutta
 
Top