0
\$\begingroup\$

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:

data to go in

When I write it to the chip and read it back I get:

data comes out

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 : )

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

Check that you have the ORG input tied appropriately, and that you have a chip that is either fixed in 64x16 or supports the ORG input.

For example, a Microchip/Atmel 93xx46A is 128x8 organization and cannot be changed (93xx46B is 64x16 and 93xx46C supports the ORG input).

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for your response. I have tried writing the data in the 64x16 and 128x8 formats, switching the level of the ORG pin as described in the datasheet. The initial data read from the chip initially was in the 64x16 format. \$\endgroup\$
    – kyotee89
    Commented Jan 14 at 6:43
0
\$\begingroup\$

I have managed to get this to work, by passing the values to e.write() from a 16 bit unsigned int array. Amended code below

#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

unsigned int combinedBuffer[64] = {5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 5921, 4128, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 2617, 12353, 6190, 2036, 13056, 3466, 6952, 43605};

// 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Ø¡²¥";
  } else {
    writeBuffer = "This is a string written in the 8-bit organization.\nAs you can see, the address space for this mode is much bigger!\nHey, world!\0";
  }



  int len = longMode ? 64 : 128;
  // Write your data
  for (int i = 0; i < len; i++) {
    e.write(i, combinedBuffer[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() {}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.