I am trying to write data to an EEPROM with some success but not quite. The chip is a 93C46 128 words at 8 bit or 64 words at 16 bit. The data to go in is in 64 word (16 bit) format as follows:
When I write it to the chip and read it back I get:
So its like its only writing one half of the value into each word.
The code I'm using to write/read is from here link to EEPROM Arduino code:
And I'm using it as below:
CODE START
#include <93C46.h>
/*
* Example Sketch demonstration on how to write to (and read from) a 93C46 eeprom
*
* Wiring:
* Pin 7(CS) to Chip pin 1
* Pin 9(CS) to Chip pin 2
* Pin 10(DI/MOSI) to Chip pin 3
* Pin 11(DO/MISO) to Chip pin 4
*
* (For some chips:) GND/VCC to Chip pin 6
* This determines the organization:
* HIGH is 64x16 (Use EEPROM_MODE_16BIT)
* LOW is 128x8 (Use EEPROM_MODE_8BIT)
*
*/
#define pCS 10
#define pSK 13
#define pDI 11
#define pDO 12
// Prints all words of the buffer
void debugPrint(word* buff, int len) {
Serial.print("\n\t00\t01\t02\t03\t04\t05\t06\t07\t08\t09\t0A\t0B\t0C\t0D\t0E\t0F");
for(int i = 0; i < len; i++) {
if(i % 16 == 0) {
Serial.println();
Serial.print(i, HEX);
}
Serial.print("\t");
if(buff[i] < 0x10) {
Serial.print("0");
}
Serial.print(buff[i], HEX);
}
}
void setup() {
bool longMode = EEPROM_93C46_MODE_16BIT;
eeprom_93C46 e = eeprom_93C46(pCS, pSK, pDI, pDO);
e.set_mode(longMode);
Serial.begin(9600);
Serial.println("Writing data...");
// First, enable EW (Erase/Write)
e.ew_enable();
String writeBuffer;
if(longMode) {
writeBuffer = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ£çô3Ø¡²¥";
//writeBuffer = (!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!,!, ,ÿÿ,ÿÿ,ÿÿ,ÿÿ,ÿÿ,ÿÿ,ÿÿ,£,,ç,ô3,Ø¡,²,¥);
} else {
writeBuffer = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ£çô3Ø¡²¥";
}
int len = longMode ? 64 : 128;
// Write your data
for(int i = 0; i < len; i++) {
e.write(i, writeBuffer[i]);
}
// Optionally, disable EW after writing
e.ew_disable();
Serial.println("Reading data...\n");
word readBuffer[len];
for(int i = 0; i < len; i++) {
word r = e.read(i);
readBuffer[i] = r;
Serial.print(char(r));
}
debugPrint(readBuffer, len);
Serial.println();
}
void loop() {}
CODE END
I think it might be because I'm passing the values in string format so its taking each single character as the whole word, not combining them. I'm not sure how to change the code to pass the values to the chip as a 16 bit hex code or what. The library files don't look too complicated compared to some I've opened but its still above my level of expertise to change it up much.
Any help or advice appreciated : )