Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Nigel's Serial EEPROM I2C code

Status
Not open for further replies.

kcn

New Member
I am using Nigel's I2C code to interface a 16F628A to
a 24LC512, a 512K bit serial EEPROM.

I am doing tut6_2a.asm, and am confused as to what
are the exact possible ranges for

Code:
Data_Page	;EEPROM page
Adr_Lo		;EEPROM Low address
Adr_Hi		;EEPROM Hi address

I am almost certain that Adr_Lo is in the range from 0x00
to 0xFF, but I am not clear about Data_Page and Adr_Hi.

Could somebody please clue me in? Thanks!

kcn
 
kcn said:
I am using Nigel's I2C code to interface a 16F628A to
a 24LC512, a 512K bit serial EEPROM.

I am doing tut6_2a.asm, and am confused as to what
are the exact possible ranges for

Code:
Data_Page	;EEPROM page
Adr_Lo		;EEPROM Low address
Adr_Hi		;EEPROM Hi address

I am almost certain that Adr_Lo is in the range from 0x00
to 0xFF, but I am not clear about Data_Page and Adr_Hi.

Could somebody please clue me in? Thanks!

It's explained in the text of the tutorial, a standard EEPROM can only address a very limited amount of memory, based on a number of 256 byte 'pages'. The tutorials use 'Data_Page' to select the page, and 'Adr_Lo' to select the address in that page. Data_Page also selects the address of the particular EEPROM as well, so it limits the number of EEPROM's you can connect on the same bus.

In order to have larger EEPROM's the manufacturers altered the addressing scheme, by making the address register two bytes long, this is called 'extended addressing' - I named these two registers 'Adr-Lo' and 'Adr_Hi', giving a possible 16 bit address space.

The first couple of turorials have two versions, the one with an 'a' on the end are for larger extended addressing, and the ones without the 'a' for smaller standard EEPROM's.

Adr_Lo and Adr_Hi give enough address range for the entire 64K EEPROM you're using.

If you check the datasheets it's all explained there!.
 
Nigel Goodwin said:
kcn said:
I am using Nigel's I2C code to interface a 16F628A to
a 24LC512, a 512K bit serial EEPROM.

I am doing tut6_2a.asm, and am confused as to what
are the exact possible ranges for

Code:
Data_Page	;EEPROM page
Adr_Lo		;EEPROM Low address
Adr_Hi		;EEPROM Hi address

I am almost certain that Adr_Lo is in the range from 0x00
to 0xFF, but I am not clear about Data_Page and Adr_Hi.

Could somebody please clue me in? Thanks!

It's explained in the text of the tutorial, a standard EEPROM can only address a very limited amount of memory, based on a number of 256 byte 'pages'. The tutorials use 'Data_Page' to select the page, and 'Adr_Lo' to select the address in that page. Data_Page also selects the address of the particular EEPROM as well, so it limits the number of EEPROM's you can connect on the same bus.

In order to have larger EEPROM's the manufacturers altered the addressing scheme, by making the address register two bytes long, this is called 'extended addressing' - I named these two registers 'Adr-Lo' and 'Adr_Hi', giving a possible 16 bit address space.

The first couple of turorials have two versions, the one with an 'a' on the end are for larger extended addressing, and the ones without the 'a' for smaller standard EEPROM's.

Adr_Lo and Adr_Hi give enough address range for the entire 64K EEPROM you're using.

If you check the datasheets it's all explained there!.

Hi Nigel, I'm still confused. I read your tutorial and peeked at the
data sheet and I just don't understand. Sorry for my ignorance.

For my 512K bit EEPROM, it has 512 * 1024 / 256 = 2048 pages.
Correct?

If there are 2048 pages, then this is too large of a value to fit into
Data_Page!

My question was: what are the range of values for Adr_Hi and
Data_Page for a 512K bit EEPROM?

19 bits are required to address 512K bits, and I can't understand
from your tutorial exactly what is being mapped to what. Are the
lower eight bits mapped to Adr_Low? Are the next eight bits
mapped to Adr_Hi? What does Data_Page do exactly?

If you could please tell me the exact ranges of Adr_Hi and Data_Page
and how the bits are assigned, then I will understand better.

Thank you!

kcn
 
I have another question about your I2C code, in particular, in
tut6_2a.
Code:
Fill_Buf					; dummy up the data buffer with 4 values
		movlw 	buf			; presumably this would be the result
This instruction "movlw buf" confuses me. I thought movlw was used
to put a literal value into the W register, but buf is a register and not
some constant, yet, the code compiles just fine!

And it runs fine! I don't understand! Could you please explain this
one statement? Thanks!

kcn
 
kcn said:
I have another question about your I2C code, in particular, in
tut6_2a.
Code:
Fill_Buf					; dummy up the data buffer with 4 values
		movlw 	buf			; presumably this would be the result
This instruction "movlw buf" confuses me. I thought movlw was used
to put a literal value into the W register, but buf is a register and not
some constant, yet, the code compiles just fine!

And it runs fine! I don't understand! Could you please explain this
one statement? Thanks!

It's a question of understanding what the processor and assembler actually 'understand' - ALL the processor 'understands' is numbers, the words are purely to help humans understand what's happening. The assembler takes the words and converts then into numbers for the processor - in this case 'buf' is a register (GPR) which is converted to 0x3A (the address it's at).

All the assembler does in convert every occurance of 'buf' to 0x3A, so the line becomes 'movlw 0x3A', this value (0x3A) is then moved to the FSR register, where it's used as the base address for the indexed addressing using INDF and FSR.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top