Hi there all,
So I'm pretty much new to this Arduino and programming stuff. But I managed to write some code as I want to learn.
So I hooked up my arduino and M93C86-x EEPROM to breadboard. I found library that can easily Read and Write to these types of EEPROM. I wrote some code but when I'm writing from a file full of let's say 0x41 (ANSII = "A") value I do not see full EEPROM of 0x41 value. Only half or less.
I do not know If the problem is in the code or timing or maybe it's because of the library. I'm confused. I tried reading .cpp and .h file of the library but I didn't manage how to fix this.
To let you know, I want to write some data from .bin file (or any file basically) throught TeraTerm using Serial Communication.
But there are more issues ... I was reading the datasheet of this EEPROM and i found out that this EEPROM has 16384 BITS / 2048 8-bit BYTES / 1024 16-bit WORDS. How hard I'm trying, every time I can read only 256 Words and Bytes too ... even after changing the CHIP_ORGANIZATION. When I want to read for example 1024 bytes or words , after 256 it will start showing data from the beggining.
Besides these problems, Every time I'm reading data from EEPROM It will show FFFF instead of FF .. And when data includes some letter for example 0xEA or 0x4F it will display FFEA ... FF4F . But when the data includes only numbers for example 0x41 it will display only 41 on Serial output.
Any advices ? 
If it would help I can send you whole code, pin out and photo of connection on breadboard.
Screenshot from TeraTerm output is in attachments.
Libraries used in code : M93Cx6 EEPROM Library
Arduino-SerialCommand Library
Datasheet : m93c86-w.pdf
Code :
void Write() {
byte counter = 0;
Serial.println("!! Waiting for a file to upload !!");
while(!Serial.available()){} //Waiting for a file to be send over TeraTerm
for(int j = 0; j < 256; j++){
tempStore[counter++] = Serial.read();
delay(5);
}
delay(10);
eeprom.writeEnable();
for (int i = 0; i < 256; i++) {
eeprom.write(i, tempStore[i]);
delay(5);
}
eeprom.writeDisable();
Serial.println(">> Write completed successfully <<");
}
void Read() {
eeprom.writeDisable();
char *arg; //Parameter
int aNumber; // INT parameter
char data; //DATA from EEPROM
arg = SCmd.next(); //Reading First parameter from command
if (arg != NULL) {
aNumber = atoi(arg); //Converting Parameter from Char to Int
for (int i = 0; i < aNumber; i++) {
data = eeprom.read(i);
char buf[256];
char buf2[256];
if (i % 16 == 0) {
Serial.println();
sprintf(buf2, "%03X : ", i);
Serial.print(buf2);
}
sprintf(buf, "%5X", data);
Serial.print(buf);
}
Serial.println("\n >> Read command completed <<");
} else {
Serial.println("\n >> Wrong or No parameter entered for command READ <<");
}
}
The reason you only read 256 bytes is because you have that value in the loop of the code you have shown, plus it is shown as the size of your buffers.
To get this LIBRARY to work, you must edit the library files to set the chip you intend to use; the default is the 93C56.
So you must make changes in the .cpp and the .h files to use the 93C86 instead of the default.
You should post your entire code because the problem could be in your header or setup and it is useless to troubleshoot without seeing it all.
I managed how to see only FF insted of FFFF on the output.
kenny256:
The reason you only read 256 bytes is because you have that value in the loop of the code you have shown, plus it is shown as the size of your buffers.
Even after changing it to 1024 , every 256 bytes I see the first byte. It will just start showing data from beggining. I even wrote function to write single byte to one specific address. And when I try to write for example to address 257 the data will appear on address 0 when I'm reading. See attachments
kenny256:
To get this LIBRARY to work, you must edit the library files to set the chip you intend to use; the default is the 93C56.
So you must make changes in the .cpp and the .h files to use the 93C86 instead of the default.
This library has the function of choosing your CHIP . You can see it in my code .
eeprom.setChip(86); // set chip 93C86
Next problem is, when I try to write from a file to eeprom every time it will just don't write into 2nd position which is address 1. Everytime i see there FF. And one value from file won't be written into the EEPROM. See attachments
Here's full code :
#include <M93Cx6.h>
#include <SerialCommand.h>
#define PWR_PIN 7
#define CS_PIN 10
#define SK_PIN 13
#define DO_PIN 12
#define DI_PIN 11
#define ORG_PIN 8
#define ORG 16
#define CHIP 56
M93Cx6 eeprom = M93Cx6(PWR_PIN, CS_PIN, SK_PIN, DO_PIN, DI_PIN, ORG_PIN);
SerialCommand SCmd;
byte tempStore[1024];
void unrecognized()
{
Serial.println("<< Unrecognized Command >>");
}
void CH_ORG() { //Change Organization
char *arg; //Parameter
int aNumber; // INT parameter
arg = SCmd.next(); //Reading First parameter from command
if (arg != NULL) {
aNumber = atoi(arg); //Converting Parameter from Char to Int
if (aNumber == 16) {
eeprom.setOrg(ORG_16);
Serial.println("<< Organization set to WORD(16) >>");
}
else if (aNumber == 8) {
eeprom.setOrg(ORG_8);
Serial.println("<< Organization set to BYTE(8) >>");
}
else {
Serial.println("<< NO or WRONG ORG NUMBER >>");
}
}
}
void FullErase() { // Erase whole eeprom
eeprom.writeEnable();
eeprom.eraseAll();
eeprom.writeDisable();
Serial.println("<< EEPROM Erased successfully >>");
}
void WriteSingle() {
Serial.println("<< Writing Single Byte to 1 Address >>");
byte *arg; //Parameter
byte address, value; // INT parameter
arg = SCmd.next(); //Reading First parameter from command
if (arg != NULL) {
address = atoi(arg); //Converting Parameter from Char to Int
arg = SCmd.next();
if (arg != NULL) {
value = atoi(arg);
eeprom.writeEnable();
eeprom.write(address, value);
eeprom.writeDisable();
Serial.println(">> Write Single command completed successfully <<");
}
else {
Serial.println("\n >> Wrong or No parameter entered for command SWRITE <<");
}
}
else {
Serial.println("\n >> Wrong or No parameter entered for command SWRITE <<");
}
}
void Write() {
Serial.println("!! Waiting for a file to upload !!");
while (!Serial.available()) {} //Waiting for a file to be send over TeraTerm
for (int j = 0; j < 1024; j++) {
tempStore[j] = Serial.read();
delay(1);
}
delay(10);
eeprom.writeEnable();
for (int i = 0; i < 256; i++) {
eeprom.write(i, tempStore[i]);
delayMicroseconds(2);
}
eeprom.writeDisable();
Serial.println(">> Write completed successfully <<");
}
void Read() {
eeprom.writeDisable();
byte *arg; //Parameter
int aNumber; // INT parameter
byte data; //DATA from EEPROM
arg = SCmd.next(); //Reading First parameter from command
if (arg != NULL) {
aNumber = atoi(arg); //Converting Parameter from Char to Int
for (int i = 0; i < aNumber; i++) {
data = eeprom.read(i);
char buf[1024];
char buf2[128];
if (i % 16 == 0) {
Serial.println();
sprintf(buf2, "%03X : ", i);
Serial.print(buf2);
}
sprintf(buf, "%5X", data);
Serial.print(buf);
}
Serial.println("\n >> Read command completed <<");
} else {
Serial.println("\n >> Wrong or No parameter entered for command READ <<");
}
}
void setup() {
Serial.begin(9600);
eeprom.setChip(86); // set chip 93C86
eeprom.setOrg(ORG_16);
SCmd.addCommand("read", Read); //Reading Command
SCmd.addCommand("ea", FullErase); // Erase All Command
SCmd.addCommand("write", Write); // Writing Command
SCmd.addCommand("org", CH_ORG); // Change Organization of Memory Command
SCmd.addCommand("swrite", WriteSingle);
SCmd.addDefaultHandler(unrecognized); // Default
Serial.println("Ready");
}
void loop() {
SCmd.readSerial();
}
Howdy Lukas,
i was able to download and install the library, write a sketch and read a 93C76 today. After doing that i have noticed some items that may be an issue with your code and causing the strange missing and misplaced bytes.
Early on you mentioned you were using a 93C86, which can be organized as 1024 words x 16-bits per word, or 2048 bytes x 8-bits per byte, but it is not clear which organization you desire to use, have you decided?
In the #defines section you have ORG as 16, and the CHIP is 56, meaning 93C56. i believe this will cause issues with trying to read or write to the 93C86 device.
you have a tempStore declared as byte data type with size of 1024, but the 16-bit organization data are not bytes but rather "words" consisting of 2 bytes in length. This is causing problems because you are trying to display only bytes.
i don't know if it matters, but you have your main loop void functions before your void setup() which is intended to run at the start of the program. In this setup you have calls to set chip and set ORG, so there may be some confusion about what chip the program thinks is connected.
i used the example sketch in the library with some modifications to simply read the chip without writing the "hello world".
Here is a scope capture of the CLK, DI and DO signals reading the last address 0x1FF of a blank chip filled with 0xFFFF.
Good Luck to you while learning to use the Arduino,
kenny