I'm trying to keep a timer in a Ramtron FRAM chip, which is like an eeprom except that with 10^14 write cycles, I can read and write every second for hundreds of years. To do this, I declared a couple of DWORD (32 bit) variables RTC1 and RTC2. In order to read and write these 32-bit numbers to the FRAM, which wants 8-bit bytes, I tried something that I thought I saw somewhere:
Code: Select all
var RTCA1 : array[4] of byte at RTC1; // Map run time counters to array
RTCA2 : array[4] of byte at RTC2; // for FRAM read/write
It was my understanding that by doing this, it would map the 4-byte array right over the top of the 32-bit word, and so all I would have to do to read/write the counters RTC1 and RTC2 is index reading and writing bytes through the arrays RTCA1 and RTCA2.
I tested the FRAM code separately, and it works correctly (the protocol is identical to SPI EEPROM), but when I tried this,
Code: Select all
for i := 0 to 3 do RTCA1[i] := framread(i);
for i := 4 to 7 do RTCA2[i] := framread(i);
if out1 then inc(RTC1);
if out2 then inc(RTC2);
for i := 0 to 3 do framwrite(i,RTCA1[i]);
for i := 4 to 7 do framwrite(i,RTCA2[i]);
I got essentially random numbers. So I went to the help file, which only talks about using 'at' on bits.
I'm sure I saw something about mapping arrays on top of words and dwords in the forum here, but searching for "at" is pointless. Is this supposed to work, and am I doing it right? Or did I remember seeing something esle?
If you know what you're doing, you're not learning anything.