PDA

View Full Version : 12cwrite not working with 24LC08 SEEPROM ??



tekart
- 27th July 2010, 00:08
I'm trying to fill a SEEPROM with a data lookup table so I can read it later. I'm using a 24LC08 and writing a series of word constants to it. As a test I'm just using a loop to write a sequence of numbers equivalent to the addresses, but that is not working. The loop tries to write values 0-20 to locations 0-20 (actually 0-40 for word vars) but it's only writing the 1st 3 bytes in the EEPROM.

I can take the LC08 out of the circuit and read it with a prom burner to verify the results and it verifies that all I'm writing is the 1st 3 bytes - and those values do not reflect what I'm trying to write.

Here's my code loop:

for temp = 0 to 20
i2cwrite eedat,eeclk,$A0,Temp,[temp] ' write
pause 400 ' hold for display
i2cread eedat,eeclk,$A0,temp,[Mode] ' read it back
lcdout lcdcmd,lcdline2,#temp," ",#Mode ' display it
pulsout piezo,10 ' diagnostic "tic" sound
next temp

My LCD shows reads of 0 (zero), but the chip reads as:
10 00 10 FF FF FF FF...
I'm really frustrated, nothing is adding up here. Am I doing something dumb?

Darrel Taylor
- 27th July 2010, 01:24
tekart,

With the 24LC08, the address needs to be a BYTE.
There are also 4 "blocks" of 256 bytes that can be selected in the "control" byte.
And the address should increment (STEP) by 2 for word sized data.

I ran this in Proteus ... seems to work.

Temp VAR BYTE
Mode VAR WORD

for temp = 0 to 38 STEP 2
Mode = temp
i2cwrite ee_dat,ee_clk,$A0,Temp,[Mode] ' write
pause 400 ' hold for display
i2cread ee_dat,ee_clk,$A0,temp,[Mode] ' read it back
lcdout lcdcmd,lcdline2 ,#temp," ",#Mode ' display it
pulsout piezo,10 ' diagnostic "tic" sound
next temp

http://dt.cambs.net/files/EEPROM_tekart.bmp

tekart
- 27th July 2010, 02:30
Thanks Darrel,
I had mis-read the manual and assumed that the compiler took care of the stepping by 2 bytes. I was aware of the 4 blocks, and planned to break my data into 128 word chunks for fit into each block.

I tried your revised code and the LCD shows a correct read-back, but when I read the EEPROM in my PROM reader all I get is the 1st 3 bytes changed and the rest remains FF.
It's as if the address increment is not working and I'm just overwriting the same data. I just can't see why that would happen.

I have checked the hardware over carefully - not much to screw up there. Data and clock are pulled up with 10K and the WP line (pin 7) is wired to GND. Power is good, filtered, clean 5V. Signals all look "textbook".



[QUOTE=Darrel Taylor;91895]tekart,

With the 24LC08, the address needs to be a BYTE.
There are also 4 "blocks" of 256 bytes that can be selected in the "control" byte.
And the address should increment (STEP) by 2 for word sized data.

Darrel Taylor
- 27th July 2010, 04:29
Are you sure you changed the temp variable to a BYTE?

By changing the temp var back to a WORD, and no other changes to my previous code.
I get the same results you do ... only writes to the first 3 bytes.

http://dt.cambs.net/files/EEPROM_tekart_2.bmp

tekart
- 27th July 2010, 16:48
Oh Duh! Now I see the problem. That never occurred to me to use a byte variable for the address counter. It's all so obvious now. I really appreciate your help Darrel! :)



Are you sure you changed the temp variable to a BYTE?

By changing the temp var back to a WORD, and no other changes to my previous code.
I get the same results you do ... only writes to the first 3 bytes.

http://dt.cambs.net/files/EEPROM_tekart_2.bmp

tekart
- 27th July 2010, 17:18
So Darrell,

My ultimate goal is to get 256 word variables into the EEPROM chip from a comma delimited text file in decimal. My plan was to put them into on-chip EPROM first in 128 word chunks then read them out in a loop and write them to the external EEPROM chip. This is pretty tedious though. So I'm wondering if you have any thoughts on a way to simplify the process?

Once I have the chip programmed, I can then read it out to create a file for burning them in production. Wish I could just get the data directly into my PROM burner...

BTW This is a temperature look-up table for a thermostat type device. The values are ADC readings for the degrees F from 0 to 255.

Guy

Darrel Taylor
- 27th July 2010, 20:25
Temperature lookup table?
Can't that be done in Math?

Which PIC are you using?
You may be able to use something like this to store the values in the PIC before writing to EEPROM.
http://www.picbasic.co.uk/forum/showthread.php?t=3891#LAB

tekart
- 27th July 2010, 21:32
It's a 10K thermistor curve that can't be defined in integer math. Been there tried that.
I'm fine with the lookup table in EEPROM, it's getting it in there is the hassle.

I'm using a 16F88 for low cost and the ADCs.

That EXT thing is weird. Not sure how to apply it. My plan at present is to load the 256 bytes in the PIC with 128 words, then write that to the external EEPROM and repeat. Just have to pay attention to the addresses and data file index. I can manage that but was looking for a simpler way out.

Guy


Temperature lookup table?
Can't that be done in Math?

Which PIC are you using?
You may be able to use something like this to store the values in the PIC before writing to EEPROM.
http://www.picbasic.co.uk/forum/showthread.php?t=3891#LAB

Darrel Taylor
- 27th July 2010, 21:44
It's a 10K thermistor curve that can't be defined in integer math.
One day, you will learn not to say things like that. :)
Can I see your data table?


That EXT thing is weird. Not sure how to apply it.
If I can't "Curve Fit" it, I'll show you how to put the table in Code Memory.
Then you can either use the table from there, or take the data and write it to EEPROM.

If I can fit the curve, you won't need a table.

tekart
- 27th July 2010, 22:04
Darrel,
Your offer sounds too good to be true. Therefore it must be! ;)

We're getting into my proprietary info at this point. How can we continue the dialog outside the Forum? This is for a product that I'm developing for my own company so I can pay for your time - if you're willing.
Guy


One day, you will learn not to say things like that. :)
Can I see your data table?


If I can't "Curve Fit" it, I'll show you how to put the table in Code Memory.
Then you can either use the table from there, or take the data and write it to EEPROM.

If I can fit the curve, you won't need a table.

malc-c
- 28th July 2010, 14:26
BTW This is a temperature look-up table for a thermostat type device.

Guy

LOL - Darrel has a lot of experience of thermostat type devices :) :)