Skip to content

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

@kyotee89

Description

@kyotee89

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() {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions