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

Cant write 16 bit data values while in 16 bit write mode #9

Open kyotee89 opened 10 months ago

kyotee89 commented 10 months ago

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

data comes out image

So its like its only writing one half of the value into each word.

I am using the code as below, with the data converted from hex to string to match the input type of the example code.

#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() {}
0xJoey commented 4 months ago

Hey, I don't check this repository all too often, so my apologies for the late reply.

Please make sure that your chip is the 93C46C variant that has an ORG pin and make sure it is asserted high. It looks like the chip is still in the 8-bit configuration.