0xJoey / Arduino_93C46

A simple library to interface an arduino with a 93C46 EEPROM chip
GNU General Public License v3.0
20 stars 13 forks source link

Only reading half of the memory? #3

Closed SpaceCommanderTravis closed 4 years ago

SpaceCommanderTravis commented 4 years ago

Please go easy on me, this is my first interaction with Github. I'm learning to access the 93C46 eeprom embedded in a Datakey serial memory key. These operate in 16x64 bit mode. I've installed this library and I'm playing about with the example read sketch. But I dont understand. In 16x64 mode, it only reads the first 64 bytes of the buffer. Surely, it should read 128 bytes? The data is arranged in 64 "doublewords" (an old IBM assembler term there), but this is still 128 bytes (or words) of data to read. My understanding from the chips datasheet is that the only difference between 128x8 and 64x16 is the size of then control messages in and out. The actual storage is still the same - 1024 bits.

0xJoey commented 4 years ago

Your last line is correct, but you are not reading the first 64 bytes(8 bits), but all 64 words(16 bits). A doubleword is 32 bits.

This could probably easily be solved by filling the buffer as follows(Though I haven't tested this, I don't have my arduino handy at the moment):

byte readBuffer[128];
for(int i = 0; i < 64; i++) {
    word r = e.read(i);
    readBuffer[i*2] = r>>8; // Assuming the high byte of the word comes first
    readBuffer[i*2 + 1] = r;
}
SpaceCommanderTravis commented 3 years ago

I have now tested this in 8 bit mode using a 93C46D EEPROM. All five functions - read, write, erase, write_all and erase_all appear to work fine. I've had a lot of fun with this library. Thanks for writing it.