Code Monkey home page Code Monkey logo

arduino_93c46's Introduction

93C46 Library for Arduino

N.b. This library only works for chips in the 64x16 mode. If your chip support 128x8 mode, please make sure your ORG pin is tied to GND. 128x8 support is planned in the future, i.e., when I get a chip that supports it.

93C46 Datasheet

Introduction

The 93C46 is a 1KB EEPROM communicating over 3-wire serial, with an additional CS wire. As I could not find any ready-made solution, I decided to write this library. This library sends data to the chip by bitbanging, so it's not going to give the best performance.

EW (Erase/Write)

When the chip is powered on, EW is disabled. This blocks are attempts to erase/write anything on the chip. Once enabled, EW will stay enabled until it is explicitly disabled or the chip loses power.

Organization

Some 93C46 chips support different organizations. If the ORG pin is pulled high, the chip with organize itself in 64 words of 16 bits, if ORG is pulled low, it will organize itself as 128 words of 8 bits. The mode the library uses can be changed with set_mode. The library starts with 16-bit mode by default.

Data written into one organization may or may not be able to be read in the other organization. Your mileage may vary, have fun.

Using the mode not corresponding to the chip organization will result in undefined behaviour.

Methods

Method Returns EW required Description
eeprom_93C46(int pCS, int pSK, int pDI, int pDO) - - Constructor
set_mode(bool longMode) void No true enables 16-bit mode, false enables 8-bit mode
ew_enable() void No Enables EW, disabled read-only mode
ew_disable() void Yes Disables EW, returns to read-only mode
is_ew_enabled() bool No true if EW is enabled
erase_all() void Yes Changes all memory locations to 0xFFFF
write_all(word value) void Yes Changes all memory locations to the provided value
write(byte addr, word value) void Yes Changes the provided memory location to the provided value
erase(byte addr) void Yes Changes the provided memory location to 0xFDFF
read(byte addr) word No Returns the value of the provided memory location

Example

#include <93C46.h>
/*
 * Example Sketch demonstration on how to write to 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
 * GND to Chip pin 5
 * (For some chips:) GND/5V to pin 6 (This determines the organization, 5V is 16-bit, GND is 8-bit)
 * 5V to Chip pin 8
 * 
 */
#define pCS 7
#define pSK 9
#define pDI 10
#define pDO 11

// 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 = true; // Change this to 'false' to use the 8-bit mode
  
  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 = "This is a string written in the 16-bit organization.\nHi, world!\0";
  } 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, 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();
  delay(500);
}

void loop() {}

arduino_93c46's People

Contributors

0xjoey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

arduino_93c46's Issues

About CONTROL

Hello.
I think that:

void eeprom_93C46::ew_enable() {
	digitalWrite(_pCS, HIGH);
	send_bits(HIGH, 1);
		if(_mode) {
			send_bits(EW_ENABLE, 8);
		} else {
			send_bits(EW_ENABLE<<1, 9);
		}
	digitalWrite(_pCS, LOW);
	_ew = true;
};

void eeprom_93C46::ew_disable() {
	digitalWrite(_pCS, HIGH);
	send_bits(HIGH, 1);
	if(_mode) {
		send_bits(EW_DISABLE, 8);
	} else {
		send_bits(EW_DISABLE<<1, 9);
	}
	digitalWrite(_pCS, LOW);
	_ew = false;
}

void eeprom_93C46::erase_all() {
	if(!this->is_ew_enabled()) {
		return;
	}
	digitalWrite(_pCS, HIGH);
	send_bits(HIGH, 1);
	if(_mode) {
		send_bits(ERASE_ALL, 8);
	} else {
		send_bits(ERASE_ALL<<1, 9);
	}
	digitalWrite(_pCS, LOW);
	wait();
}

void eeprom_93C46::write_all(word value) {
	if(!this->is_ew_enabled()) {
		return;
	}
	digitalWrite(_pCS, HIGH);
	send_bits(HIGH, 1);
	if(_mode) {
		send_bits(WRITE_ALL, 8);
		send_bits(0xFFFF & value, 16);
	} else {
		send_bits(WRITE_ALL<<1, 9);
		send_bits(0xFF & value, 8);
	}
	digitalWrite(_pCS, LOW);
	wait();
}

Instructions are not sent correctly

There is a serious bug in your code. For reading 16bit organization structure you assume there are 8 bits used for opcode + address together. This is incorrect, there are 2 bits of opcode and 8 bits of address (10 total). First bit of address is ignored by the chip but it still needs to be sent, the ignored bit is marked "X" in the documentation.

This error exists in other (all?) functions too.

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

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

Database Care

Can you please update your Database?!
i found the Issues #4, it's open and already one year old!
I Update my 96C43.cpp and now are my Read_Datas complete different.
But your Datas are over 2 years old!!!
And can you please check you examples for Issues #3?
Is this really a wrong output, ore a half size output?
Sorry but your answers are not good documented or explained.
I become on all this changes, different outputs.
Which ones are the right ones?
Which is the right way?
What is written correctly?
Need Help!!!!!!!!!!!!

Only reading half of the memory?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.