Shop OBEX P1 Docs P2 Docs Learn Events
Write & Read to External EEPROM — Parallax Forums

Write & Read to External EEPROM

John KauffmanJohn Kauffman Posts: 653
edited 2006-06-01 19:56 in BASIC Stamp
I bought a Parallax IC 24LC32A EEPROM. I am experimenting with writing and reading data to the chip, basing my experiments on Jon William’s 24LC256.BS2 file.

I am saving samples which consist of two word-sized items of data: 1) the EEPROM address for storage (which works as a crude time stamp) and 2) an RCTime value of about 1,000 in decimal.
·
The I2S interface routines are copied from Jon’s file. I did change the name of the variable holding the address to write to and read from to be dataAddr instead of wrdAddr (see below). Then I·just added the loops to establish the address to write to and generate the data to write. These loops then call Jon's subroutines to use I2S to do the writing and reading. I have limited my data acquisition to 10·samples for these tests.
··
In my code wrdAddr represents the start of one sample. DataAddr represents the location of the first and then (two addressees higher) second values for the sample. The wrdAddr increments by four with each new sample.
·
The WriteData sub routine seems to work, with the diagnostic DEBUGs showing RCTime values of around 1000. When I get to the ReadData·subroutine the first datum of each sample looks fine - the address. But the second shows values bouncing all over from 0 to 255. I expected to see the RCTime values of around 1000, as I thought the program wrote to the EEPROM.
·
I am blaming the read, but I’m not completely sure what I actually wrote. My suspicion is that I am somehow writing or reading to the wrong address. But I haven’t been able to figure it out. Write and read loops go up through the EEPROM addresses with the same start, stop and step values.
·
Another possible problem is that I am not displaying the value properly in DEBUG or that there is some kind of value size over-run for the variable or for the address space.
·
Below is a sample of the output.
·
Thanks.
·
Data Storage test
Writing ...
$0000·· 01060
$0004·· 01053
$0008·· 01049
$000C·· 01045
$0010·· 01040
$0014·· 01035
$0018·· 01032
$001C·· 01027
$0020·· 01022


Reading...
$0000·· 00036
$0004·· 00029
$0008·· 00025
$000C·· 00021
$0010·· 00016
$0014·· 00011
$0018·· 00008
$001C·· 00003
$0020·· 00254

·

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-01 19:35
    John,

    ·· It appears that you're losing the high-byte of each value on the return.· I will have to look at the code to see what's going on, but for each value you're writing (16 bits) if you mask the upper byte (8 bits) you get the return (read) value.· So perhaps the read routine?· Hopefully this will get you going until someone (perhaps myself) finds the exact spot it is happening.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-01 19:56
    John,

    ·· A further look at your code shows that you're only writing one byte of the address as data, then you are incrementing the address pointer by 2 bytes and writing on byte, even though you have moved 2 bytes.· If you refer to the original code notice that there are 4 writes for the 4 addresses, but your example only writes twice.· You will need to write the highbyte and lowbyte of the address separately if that's what you're trying to do and this will need to be done for each word (2 bytes) that you're trying to write.· So you'll be writing 2 addresses per pass through the loop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.