Write to and later read from EEPROM
Building a data logger. One program measures data and writes it to EEPROM. Another program later reads the data from the EEPROM. Using Word vars. but the program that reads always gets zeroes for the high byte. Low byte is ok. What is going on? How can i read the data correctly? I have confirmed that the writing program can immediately read the data correctly. This is on BS2.
Comments
Remember that you need the WORD prefix to read and write words like: WRITE <address>, WORD <data>
Remember also that, if you're using WORD, that the addresses should increment by two.
' PulseIntervalTimer2.bs2 ' Measure the intervals between successive HIGH states on an input pin ' Pin 14 is the input pin ' An on-board astable multivibrator generates a pulse train ' which is fed to pin 14 ' This method uses the pulsin command ' {$STAMP BS2} ' {$PBASIC 2.5} locount VAR Word 'count of 2 usec intervals for low pulse hicount VAR Word 'count of 2 usec intervals for high pulse cyclecount VAR Word ' count of 2 usec intervals for a cycle memloc VAR Word 'memory location memlochi VAR Word 'highest memory location to use memcontent VAR Word ' content read from a memory location memloc = 0 memlochi = 10 DO UNTIL memloc = memlochi+1 PULSIN 14, 0, locount ' count duration of low state PULSIN 14, 1, hicount ' count duration of high state cyclecount = locount + hicount ' compute count for one cycle DEBUG ? cyclecount ' echo cycle count to screen WRITE memloc, Word cyclecount ' write cycle count to eeprom READ memloc, Word memcontent ' then immediately read it and echo to screen DEBUG "memory location ", DEC memloc, " memory contents ", DEC memcontent, CR memloc = memloc + 1 LOOP ' Check what is read from memory to see if it is as expected memloc = 0 DO UNTIL memloc = memlochi + 1 READ memloc, Word memcontent DEBUG "memory location ", DEC memloc, " memory contents ", DEC memcontent, CR memloc = memloc + 1 LOOP END
Here is some output:
cyclecount = 10283
memory location 0 memory contents 10283
cyclecount = 10282
memory location 1 memory contents 10282
cyclecount = 10283
memory location 2 memory contents 10283
cyclecount = 10282
memory location 3 memory contents 10282
cyclecount = 10280
memory location 4 memory contents 10280
cyclecount = 10283
memory location 5 memory contents 10283
cyclecount = 10281
memory location 6 memory contents 10281
cyclecount = 10282
memory location 7 memory contents 10282
cyclecount = 10283
memory location 8 memory contents 10283
cyclecount = 10283
memory location 9 memory contents 10283
cyclecount = 10283
memory location 10 memory contents 10283
memory location 0 memory contents 10795
memory location 1 memory contents 11050
memory location 2 memory contents 10795
memory location 3 memory contents 10282
memory location 4 memory contents 11048
memory location 5 memory contents 10539
memory location 6 memory contents 10793
memory location 7 memory contents 11050
memory location 8 memory contents 11051
memory location 9 memory contents 11051
memory location 10 memory contents 10283
Steve
You have to divide that WORD into two BYTEs and WRITE them into two registers.
Same goes with READ.
READ memloc, word memcontent
WRITE memloc, word memcontent
You have to do
memloc = memloc + 2