PDA

View Full Version : 24LC256 wrong address at reading



Fanias
- 6th December 2012, 17:58
Hello all,
I wonder if someone can help me with this problem.

I'm storing manualy some values to 24LC256 with an external programmer and editor like this :

:020000040000FA ' THis line was from a blank memory - not changed
:1000000048454C4C4F21FFFF4B4D31375753FF00 'This is the line I edit with my values
:10001000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0 'All zeros
:10002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 'All zeros
...........continues.......
:107FF000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF91 'Last line at address 7FF0
:00000001FF ' THis line was from a blank memory - not changed


This is text "HELLO!" for address 0 - 5 and text "KM17WS" for address 8 - 13.

With the following code I'm trying to read the stored text but it seems the address is wrong :confused:


addr var WORD

For addr = 0 TO 5 '
I2CRead memSDA,memSCL,$A1,addr,[STR TEXT\6] '$A0 does the same as $A1
pause 10
Next addr
serout2 lcdp,lcds,[i,line1,"LOC : ",STR TEXT\6] ' Display TEXT

With the above code i was expecting to see "HELLO!" but instead i see "M__KM1" !!
If i change addr values to 3 - 8 then i can see the whole text "KM17WS", but this is supposed to be at locations 8 - 13.
What am I missing here ?

PS. There are pullup's to both lines and tried all relative DEFINE's, just in case :)

Thank you in advance
Fanis

Dave
- 6th December 2012, 18:47
What does the code look like thyat you are using to write the eeprom memory? I think that may be your problem.

falingtrea
- 6th December 2012, 19:27
Hello all,
I wonder if someone can help me with this problem.

I'm storing manualy some values to 24LC256 with an external programmer and editor like this :


:020000040000FA ' THis line was from a blank memory - not changed
:10000000 48 45 4C 4C 4F 21 FF FF 4B 4D 31 37 57 53 FF 00 'This is the line I edit with my values
> 0 1 2 3 4 5 6 7 8 9 A B C D E F
:10001000 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 'All zeros
> 0 1 2 3 4 5 6 7 8 9 A B C D E F cksum
:10002000 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 'All zeros
...........continues.......
:107FF000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF91 'Last line at address 7FF0
:00000001FF ' THis line was from a blank memory - not changed
Fanis

Looks like you are one byte short on the line you edited. Each line should be 16 bytes plus a checksum. What also looks odd is that the address jumps by
0x1000 (4k) per line and not 0x10 (16).

Most good programmers have an editor built in. You would be better off using the editor to change the data and then save it off in a hex format instead of trying to edit the hex file. That way the per line check sum would be correct.

SteveB
- 6th December 2012, 20:09
One thing I see, is you keep writing over the top of the array "TEXT". Also, you don't need the FOR...NEXT loop to read sequentually.

Try just this:

I2CRead memSDA,memSCL,$A1,addr,[STR TEXT\14] 'Addr is a WORD, with initial value of $0000
This will read the first 14 bytes of the array.
To output try this:

TEXT2 VAR TEXT[8]
serout2 lcdp,lcds,[i,line1,"LOC : ",STR TEXT\6, " ",STR TEXT2\6 ] ' Display

SteveB
- 6th December 2012, 20:22
One other item. You have this comment: '$A0 does the same as $A1

I'm assuming this is a reference to the "Control" byte in the command.

The reason for this, is that the control byte for the EEPROM is $1010XXXR

The high nibble is $A
The low nibble is dependent of how the phyical chip select pins are wired. I'm pretty sure you have those either wired to GND or floating. This leaves the two possible values of $A0 or $A1, depending on the last bit. However, the last bit is dependent on whether you are reading or writing, and is controlled by PBP. So, it won't matter what you use there, as long as the 7 MSBs are correct.

Fanias
- 6th December 2012, 20:35
Thanks for your comments,

right now I'm using the built in editor of my PICKIt2 programmer and I make changes.
It's still the same result, looks to me that I cannot read the first 3 memory addresses (0,1,2) like they don't exist and also I jump 5 addresses ahead, so that address 8 on eeprom can be readed at address 3 with my code.

I'll try to find another editor for EEPROM hex files, do you have any editor in mind ?

Fanis

Fanias
- 6th December 2012, 20:43
6757

I'm trying to upload here a blank hex file for 24LC256. Sorry if I post twice :o
If someone can populate addresses 0-5 and 8-13 with data to test with my code, if there is an editing problem by my side.

6757




Thanks for your comments,

right now I'm using the built in editor of my PICKIt2 programmer and I make changes.
It's still the same result, looks to me that I cannot read the first 3 memory addresses (0,1,2) like they don't exist and also I jump 5 addresses ahead, so that address 8 on eeprom can be readed at address 3 with my code.

I'll try to find another editor for EEPROM hex files, do you have any editor in mind ?

Fanis

Fanias
- 6th December 2012, 21:43
To help you more this is what my programmer shows.
6759

If i try to read addr 3 of EEPROM, I actually read addr 8 and so on....
So the following command :

I2CRead memSDA,memSCL,$A1,3,[text]
should read character "B", but instead reads character "K", located at address 8 :confused:

What a mess :confused:

Fanis

SteveB
- 9th December 2012, 03:26
Fanis,
Did you solve the problem?


I2CRead memSDA,memSCL,$A1,3,[text]

FYI, the "3" here is a constant, and is going to cause problems, since the 24LC256 needs a WORD addr.

try:


addr VAR WORD:addr=3
I2CRead memSDA,memSCL,$A1,addr,[text]

Fanias
- 11th December 2012, 00:07
Hi Steve and thank you for your interest,
I did what you suggested and it works, however it's still not working when "addr" is in a For-next loop.
I get the same results, maybe I'm missing something in front of my eyes.
What i mean is that if i use the code in my first message (for addr = 0 to 5, where addr var word) I jump eeprom positions.
It drives me crazy, so I'll not spend more time on this, I have modified my code and will go that way with some more lines of code.

However, if anyone ever finds why this is happening, I would like to know :)
Thank you all for your answers and interest.

Fanis


Fanis,
Did you solve the problem?


I2CRead memSDA,memSCL,$A1,3,[text]

FYI, the "3" here is a constant, and is going to cause problems, since the 24LC256 needs a WORD addr.

try:


addr VAR WORD:addr=3
I2CRead memSDA,memSCL,$A1,addr,[text]

SteveB
- 11th December 2012, 05:51
addr var WORD

For addr = 0 TO 5 '
I2CRead memSDA,memSCL,$A1,addr,[STR TEXT\6] '$A0 does the same as $A1
pause 10
Next addr


Lets look at what this is doing. First, let's start with what's in the EEPROM. Starting at Address $00 (I put _ as placeholders for the value $FF):



0123456789ABCDEF
$0000-000F: HELLO!__KM17WS__

The 1st time through the loop, addr = 0, the PIC sets the register address in the 24LC256 to $0000, then reads 6 bytes sequentially, and puts them into TEXT = "HELLO!"
The 2nd time through the loop, addr = 1, the PIC sets the register address in the 24LC256 to $0001, then reads 6 bytes sequentially, and puts them into TEXT = "ELLO!_"
The 3rd time through the loop, addr = 2, the PIC sets the register address in the 24LC256 to $0002, then reads 6 bytes sequentially, and puts them into TEXT = "LLO!__"
...
The 6th time through the loop, addr = 5, the PIC sets the register address in the 24LC256 to $0005, then reads 6 bytes sequentially, and puts them into TEXT = "!__KM1"

At least that's the way it should be working. I'm not sure why you got "M__KM1".

However, now hopefully you see why, when you changed the FOR...NEXT loop to count from 3 to 8, it gave you "KM17WS"

It's because on the last loop addr = 8, the register address set in the 24LC256 is $0008, then it reads 6 bytes sequentually, and you end up with TEXT = "KM17WS"

That help?

Fanias
- 11th December 2012, 09:03
addr var WORD

For addr = 0 TO 5 '
I2CRead memSDA,memSCL,$A1,addr,[STR TEXT\6] '$A0 does the same as $A1
pause 10
Next addr


Lets look at what this is doing. First, let's start with what's in the EEPROM. Starting at Address $00 (I put _ as placeholders for the value $FF):



0123456789ABCDEF
$0000-000F: HELLO!__KM17WS__

The 1st time through the loop, addr = 0, the PIC sets the register address in the 24LC256 to $0000, then reads 6 bytes sequentially, and puts them into TEXT = "HELLO!"
The 2nd time through the loop, addr = 1, the PIC sets the register address in the 24LC256 to $0001, then reads 6 bytes sequentially, and puts them into TEXT = "ELLO!_"
The 3rd time through the loop, addr = 2, the PIC sets the register address in the 24LC256 to $0002, then reads 6 bytes sequentially, and puts them into TEXT = "LLO!__"
...
The 6th time through the loop, addr = 5, the PIC sets the register address in the 24LC256 to $0005, then reads 6 bytes sequentially, and puts them into TEXT = "!__KM1"

At least that's the way it should be working. I'm not sure why you got "M__KM1".

However, now hopefully you see why, when you changed the FOR...NEXT loop to count from 3 to 8, it gave you "KM17WS"

It's because on the last loop addr = 8, the register address set in the 24LC256 is $0008, then it reads 6 bytes sequentually, and you end up with TEXT = "KM17WS"

That help?

You make me feel stupid , but I forgive you :) it's always good to learn something new.
My mistake is clear about the use of the STR modifier, however can you help me with the I2cwrite command ?


Addr=0
I2cwrite memsda,memscl, $a0, addr, [str text\5]

The above is not working or maybe STR is only used at "read" commands ?
This works for me instead :


I2cwrite, memsda, memscl, $a0, addr, [text[0], text[1],......, text[4]]

A big thanks
Fanis

SteveB
- 11th December 2012, 14:17
You make me feel stupid , but I forgive you :)

Sorry, didn't mean to come across that way, just wanted to make sure my explanation was clear.;)




Addr=0
I2cwrite memsda,memscl, $a0, addr, [str text\5]

The above is not working or maybe STR is only used at "read" commands ?
This works for me instead :


I2cwrite, memsda, memscl, $a0, addr, [text[0], text[1],......, text[4]]

Not sure why [STR TEXT\5] didn't work, it should have. :confused:

pedja089
- 11th December 2012, 22:49
There must be pause 5ms after writing before next operation.