Shop OBEX P1 Docs P2 Docs Learn Events
Error to read eeprom — Parallax Forums

Error to read eeprom

dardar Posts: 15
edited 2012-12-18 06:04 in Propeller 1
Hi:

I'm trying to write/read eeprom, and i have a problem:
When i try to read a eepromLocation and i go to the next location, it doesn`t read a correct data, but if i increase the location 4 positions, it read right data.
Can you tell me why it happens?

The code i'm using:



if i2cObject.devicePresent(SCL,eepromAddr) == true
debug.str(string("EEPROM Present"))
eeprom_present:=1
else
debug.str(string("EEPROM Missing"))
waitcnt(clkfreq*3+cnt)
eepromData2:=100.23

if eeprom_present==1


eepromLocation := EEPROM_Base
eepromData2 := 0

repeat 10

' write long
eepromData2 :=100.23
i2cObject.WriteLong(SCL, EEPROMAddr, eepromLocation, eepromData2)

' next
eepromLocation +=1


' slowit
waitcnt(clkfreq/2 + cnt)

eepromLocation := EEPROM_Base
repeat 10
' read long
eepromData :=0
eepromData := i2cObject.ReadLong(SCL, EEPROMAddr, eepromLocation)

' debug
debug.str(string("Read Location="))
debug.dec(eepromLocation)
debug.NewLine
debug.str(ftos.FloatToString(eepromData))
'debug.dec(eepromData)
debug.NewLine

' next
eepromLocation +=1


' slowit
waitcnt(clkfreq/2 + cnt)


When i do this, only the last eepromLocation read 100.23, but if i change and increase eepromLocation+=4 then all eepromLocation read the right data. (100.23)

Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-17 07:49
    First of all ...

    attachment.php?attachmentid=78421&d=1297987572

    Each location in EEPROM can hold an 8-bit byte value. ReadLong and WriteLong take a long word (32-bits) and break it up into four 8-bit bytes that are stored in four successive EEPROM locations starting at the address specified. That's why your program only works properly when the EEPROM address is incremented by 4. That's how many bytes it takes to store the value.

    You can use ReadByte and WriteByte to read and write a single 8-bit byte if you want.
  • dardar Posts: 15
    edited 2012-12-17 07:56
    Thank you! i waste many hours to do that...!!
  • lardomlardom Posts: 1,659
    edited 2012-12-17 11:00
    @dario, The first problem is the value is a float number.
    [SIZE=2]eepromData2 :=[COLOR="#FF0000"]100.23[/COLOR][/SIZE]
    
    It will not display properly without additional processing. Start by learning to save a number like "100" or "10023".
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-12-17 11:42
    lardom wrote: »
    @dario, The first problem is the value is a float number.
    [SIZE=2]eepromData2 :=[COLOR=#ff0000]100.23[/COLOR][/SIZE]
    
    It will not display properly without additional processing. Start by learning to save a number like "100" or "10023".

    Larry,

    It looks like dario was displaying the float value. He used this line of code:
    debug.str(ftos.FloatToString(eepromData))
    

    So it looks like "ftos" is some sort of float to string object.

    I'm guessing the "100.23" is displaying properly.
  • lardomlardom Posts: 1,659
    edited 2012-12-17 15:27
    @dario, I wrote a quick object that I think will clear a few things up. Press F11 and F12. Any integer you put in will show up after you reset your Propeller but you'll see that if you enter a decimal number you'll get an error. It's not the best object but it should help clear a few things up.
  • dardar Posts: 15
    edited 2012-12-18 06:04
    Thanks to all!
    I only want to know why i can't to read a location in eeprom, i didn't think that a float it's 32 bits.
Sign In or Register to comment.