B4R Question SOLVED Trying to write to EEPROM.

tigrot

Well-Known Member
Licensed User
Longtime User
Hi everybody,
I was testing some sub to read and write 3 integers (6 bytes) using EEPROM.
The tests bring strange results:
If I write different ints the read before and after write are always the same.
Of course I'm missing something.
Here is code:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Public bc As ByteConverter
    Dim eeprom As EEPROM

End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")

    Dim res() As Int=readlastdate(0)
    Log(res(0)," ",res(1)," ",res(2))
    Log("AFTER")
    writelastdate(0,Array As Int(11,22,33)) 'whatever values I put here I get always the same readout before and after write
    Dim resi() As Int=readlastdate(0)
    Log(resi(0)," ",resi(1)," ",resi(2))
End Sub
Sub readlastdate(off As Int)As Int()
    Dim by() As Byte=eeprom.ReadBytes(64*off,6)
    Dim dat() As Int=bc.IntsFromBytes(by)
    Return dat
End Sub
Sub writelastdate(off As Int,data() As Int)
    Dim by() As Byte=bc.IntsToBytes(data)
    eeprom.WriteBytes(by, 64*off)
End Sub

The log for this code is:
B4X:
AppStart
11 22 33
AFTER
11 22 33

On previous try I put 77 88 99.
Anybody knows why?
Thank you.

Mauro Zanin
 

tigrot

Well-Known Member
Licensed User
Longtime User
I rewrote the example:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Public bc As ByteConverter
    Dim eeprom As EEPROM

End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")

    Dim res() As Int=readlastdate(0)
    Log(res(0)," ",res(1)," ",res(2))
    Log("AFTER")
    writelastdate(0,Array As Int(11,22,33)) 'whatever values I put here I get always the same readout before and after write
    Dim resi() As Int=readlastdate(0)
    Log(resi(0)," ",resi(1)," ",resi(2))
    writelastdate(0,Array As Int(44,55,66)) 'whatever values I put here I get always the same readout before and after write
    Dim resi() As Int=readlastdate(0)
    Log(resi(0)," ",resi(1)," ",resi(2))
    writelastdate(0,Array As Int(77,88,99)) 'whatever values I put here I get always the same readout before and after write
    Dim resi() As Int=readlastdate(0)
    Log(resi(0)," ",resi(1)," ",resi(2))

End Sub
Sub readlastdate(off As Int)As Int()
    Dim by() As Byte=eeprom.ReadBytes(64*off,6)
    Dim dat() As Int=bc.IntsFromBytes(by)
    Return dat
End Sub
Sub writelastdate(off As Int,data() As Int)
    Dim by() As Byte=bc.IntsToBytes(data)
    eeprom.WriteBytes(by, 64*off)
End Sub
AppStart
77 88 99
AFTER
11 22 33
44 55 66
77 88 99
[/CODE]

The question is still opened and I don't know why my first example is not working.

Mauro
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top