Eeprom reading and flashing

Hi, im trying to find a way to read some 95320 Eeprom's using the arduino, i tried using this code that i found and modified, but the output on serial monitor is always 255 and i am also looking on how to edit that data which is already in the Eeprom using external files, like saving/making dumps and then flashing it back.

#define DATAOUT 11//MOSI
#define DATAIN  12//MISO 
#define SPICLOCK  13//sck
#define SLAVESELECT 10//ss

//opcodes
#define WREN  6
#define WRDI  4
#define RDSR  5
#define WRSR  1
#define READ  3
#define WRITE 2

byte eeprom_output_data;
byte eeprom_input_data=0;
byte clr;
int address=0;
//data buffer
char buffer [256];

void fill_buffer()
{
  for (int I=0;I<256;I++)
  {
    buffer[I]=I;
  }
}

char spi_transfer(volatile char data)
{
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };
  return SPDR;                    // return the received byte
}

void setup()
{
  Serial.begin(115200);

  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  digitalWrite(SLAVESELECT,HIGH); //disable device
  // SPCR = 01010000
  //interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
  //sample on leading edge of clk,system clock/4 rate (fastest)
  SPCR = (1<<SPE)|(1<<MSTR);
  clr=SPSR;
  clr=SPDR;
  delay(10);
  //fill buffer with data
  fill_buffer();
  //fill eeprom w/ buffer
  digitalWrite(SLAVESELECT,LOW);
  spi_transfer(WREN); //write enable
  digitalWrite(SLAVESELECT,HIGH);
  delay(10);
  digitalWrite(SLAVESELECT,LOW);
  spi_transfer(WRITE); //write instruction
  address=0;
  spi_transfer((char)(address>>8));   //send MSByte address first
  spi_transfer((char)(address));      //send LSByte address
  //write 256 bytes
  for (int I=0;I<256;I++)
  {
    spi_transfer(buffer[I]); //write data byte
  }
  digitalWrite(SLAVESELECT,HIGH); //release chip
  //wait for eeprom to finish writing
  delay(3000);
}

byte read_eeprom(int EEPROM_address)
{
  //READ EEPROM
  int data;
  digitalWrite(SLAVESELECT,LOW);
  spi_transfer(READ); //transmit read opcode
  spi_transfer((char)(EEPROM_address>>8));   //send MSByte address first
  spi_transfer((char)(EEPROM_address));      //send LSByte address
  data = spi_transfer(0xFF); //get data byte
  digitalWrite(SLAVESELECT,HIGH); //release chip, signal end transfer
  return data;
}

void loop()
{
  eeprom_output_data = read_eeprom(address);
  Serial.print(eeprom_output_data,DEC);
  Serial.print('\n',BYTE);
  address++;
  if (address == 256)
    address = 0;
  delay(500); //pause for readability
}

DATASHEET:SGS Thomson Microelectronics mXqwztz datasheet pdf

I'm not very happy with that code. Where did you find it ?
Which Arduino board are you using ?
How did you connect the '/W' and '/HOLD' ?

Peter_n:
I'm not very happy with that code. Where did you find it ?
Which Arduino board are you using ?
How did you connect the '/W' and '/HOLD' ?

Here: http://arduino.cc/en/Tutorial/SPIEEPROM , yes i connected them, i am using an arduino uno r3

The Arduino Uno with that code should be okay.
I don't know how to help. Sorry. I don't have such an EEPROM myself.

When you read a value of 255, it could mean that the SPI bus is not working, and it could mean that you are actually reading the contents of the EEPROM (it could be filled with 0xFF = 255 when it is not written). So it is hard to tell. Is there a status register that you can read ?

I took a look at the website of 'ST', but didn't find example code how to use it. They probably have some Application Note how the code/sequence is to read and write it.

Peter_n:

I think that i am almost in somewhere i found a code and a external java utility that reads the eeprom data from other kinds of eeproms those with more legs, i tried to edit the arduino code of it but i think i broke it, it should read the data as hex but the output in the progam is being showed as binaries, but i need to use them as hex, i will put the code here, i changed some of the arduino ports and others parts of the code i couldnt comprehend.
i put both codes, the original and the edited here in paste2 because it exceeded the maximum allowed characters on the forum.

When direct register writing is used (for faster data transfer) it is harder to check what is wrong.

You should focus on reading and writing a single byte, for example the first byte of the EERPOM. Once that is working, you can add everything else.

I read some more about the M95320, and it is not an easy EEPROM to use.
The pins are the same as many other SPI EEPROM chips, but it has a few different things.

You started with this I think : http://arduino.cc/en/Tutorial/SPIEEPROM
That seems okay, and the AT25HP512 is a normal SPI EEPROM.

The M95320 is not normal. Did you read the datasheet (a few times) ?
It has special startup conditions, or it won't even work. I think you must connect a resistor from VCC to /S.
When I look at the datasheet at this page : http://www.st.com/web/catalog/mmc/FM76/CL1276/SC112/PF253320
it seems that some special things have been added, like a standby mode, and it needs special things with the chip select and lock pins.

Can you determine which 95320 you have ? I can find a few different versions.
I assume the brand of your chip is 'ST' ?
And is it a M9530-DF or the -R or -W, or the automotive versions -125, -A125 or -A145 ?

Peter_n:
I read some more about the M95320, and it is not an easy EEPROM to use.
The pins are the same as many other SPI EEPROM chips, but it has a few different things.

You started with this I think : http://arduino.cc/en/Tutorial/SPIEEPROM
That seems okay, and the AT25HP512 is a normal SPI EEPROM.

The M95320 is not normal. Did you read the datasheet (a few times) ?
It has special startup conditions, or it won't even work. I think you must connect a resistor from VCC to /S.
When I look at the datasheet at this page : http://www.st.com/web/catalog/mmc/FM76/CL1276/SC112/PF253320
it seems that some special things have been added, like a standby mode, and it needs special things with the chip select and lock pins.

Can you determine which 95320 you have ? I can find a few different versions.
I assume the brand of your chip is 'ST' ?
And is it a M9530-DF or the -R or -W, or the automotive versions -125, -A125 or -A145 ?

I am using the automotive version, this one.

EDIT:I got to read as hex data but the only problem now is that it only shows as FF all the addresses, also how can i add a write line to this code?

the code:

#define DATAOUT 11//MOSI
#define DATAIN  12//MISO 
#define SPICLOCK  13//sck
#define SLAVESELECT 10//ss

//opcodes
#define WREN  6
#define WRDI  4
#define RDSR  5
#define WRSR  1
#define READ  3
#define WRITE 2

byte eeprom_output_data;
byte eeprom_input_data=0;
byte clr;
int address=0;
//data buffer
char buffer [256];

void fill_buffer()
{
  for (int I=0;I<256;I++)
  {
    buffer[I]=I;
  }
}

char spi_transfer(volatile char data)
{
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };
  return SPDR;                    // return the received byte
}

void setup()
{
  Serial.begin(115200);

  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  digitalWrite(SLAVESELECT,HIGH); //disable device
  // SPCR = 01010000
  //interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
  //sample on leading edge of clk,system clock/4 rate (fastest)
  SPCR = (1<<SPE)|(1<<MSTR);
  clr=SPSR;
  clr=SPDR;
  delay(10);
  //fill buffer with data
  fill_buffer();
  //fill eeprom w/ buffer
  digitalWrite(SLAVESELECT,LOW);
  spi_transfer(WREN); //write enable
  digitalWrite(SLAVESELECT,HIGH);
  delay(10);
  digitalWrite(SLAVESELECT,LOW);
  spi_transfer(WRITE); //write instruction
  address=0;
  spi_transfer((char)(address>>8));   //send MSByte address first
  spi_transfer((char)(address));      //send LSByte address
  //write 256 bytes
  for (int I=0;I<256;I++)
  {
    spi_transfer(buffer[I]); //write data byte
  }
  digitalWrite(SLAVESELECT,HIGH); //release chip
  //wait for eeprom to finish writing
  delay(3000);
}

byte read_eeprom(int EEPROM_address)
{
  //READ EEPROM
  int data;
  digitalWrite(SLAVESELECT,LOW);
  spi_transfer(READ); //transmit read opcode
  spi_transfer((char)(EEPROM_address>>8));   //send MSByte address first
  spi_transfer((char)(EEPROM_address));      //send LSByte address
  data = spi_transfer(0xFF); //get data byte
  digitalWrite(SLAVESELECT,HIGH); //release chip, signal end transfer
  return data;
}

void loop()
{
  eeprom_output_data = read_eeprom(address);
  Serial.print(eeprom_output_data,HEX);
  Serial.print('\n',BYTE);
  address++;
  if (address == 256)
    address = 0;
  delay(500); //pause for readability
}

I want to be sure which chip it is, to be sure to get the right datasheet. Is it a -125 or a -A125/-A145 ?
Looking at picture, this might be an older version, without the extra things. But if it is a newer version you need a resistor from VCC to /S.
I'm sorry, but I think we are not even half-way there.

How can you tell that you are reading the chip ? Perhaps you are reading nothing and that results into 0xFF.

Peter_n:
I want to be sure which chip it is, to be sure to get the right datasheet. Is it a -125 or a -A125/-A145 ?
Looking at picture, this might be an older version, without the extra things. But if it is a newer version you need a resistor from VCC to /S.
I'm sorry, but I think we are not even half-way there.

How can you tell that you are reading the chip ? Perhaps you are reading nothing and that results into 0xFF.

I couldnt find where i can see those infos about the eeprom like 125 or a125, a145, the chip is just as in the image.

Ok, got some new things and got it working with a software named ponyprog, but i would like to ask if i can manage to do a "my own program" that uses arduino to read from the eeprom because with this it doesnt uses arduino only some resistors and a serial port or maybe configure the arduino to work with this software but i dont think that it's possible any ideas?