SPI EEPROM refuses to communicate, returns FF everytime

I've been trying to learn SPI, using an EEPROM 25L4005. I've tinkered it all day, read the datasheet multiple times, but still the output from the eeprom is FF. The data is sent to the slave correctly, but MISO doesn't seem to respond. I taught there was something wrong with the IC so ran an simulation on proteus software, but still the problem persists( tried debugging using SPI debugger in the simulator ). I don't have an logic analyzer to test practically. There is a similar EEPROM named 25LC512, using this in the simulator works perfectly without any errors. Communication is clean. what can be the possible problem here

#include <SPI.h>
#define READ 0x03
#define WRITE 0x02
#define WREN 0x06  // write enable

const int csPin = 10;
const int wpPin = 9; // For this sketch you could also leave the wpPin unconnected
const int writeCycle = 5;

void setup(){
  pinMode(csPin, OUTPUT);
  digitalWrite(csPin, HIGH);
  pinMode(wpPin, OUTPUT);
  digitalWrite(wpPin,HIGH);
  SPI.begin();
  Serial.begin(9600);
 
  int intToWrite = 42;
  eepromWriteInt(4, intToWrite);
  intToWrite = -1111;
  eepromWriteInt(6, intToWrite);
  
  int intToRead = 0;
  intToRead = eepromReadInt(4);
  Serial.print("intToRead (Address = 4): ");
  Serial.println(intToRead);
  intToRead = 0;
  intToRead = eepromReadInt(6);
  Serial.print("intToRead (Address = 6): ");
  Serial.println(intToRead);
}

void loop(){}

void eepromWriteEnable(){
  digitalWrite(csPin, LOW);
  SPI.transfer(WREN); 
  digitalWrite(csPin, HIGH);
}

void eepromWriteInt(int addr, int value){
  eepromWriteEnable();
  // If you want to change the SPI clock speed, uncomment the following line and adjust
  SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
  digitalWrite(csPin, LOW);
  SPI.transfer(WRITE);
  SPI.transfer((byte)(addr>>8));
  SPI.transfer((byte)(addr&0xFF));
  SPI.transfer((byte)(value>>8));
  SPI.transfer((byte)(value&0xFF));
  digitalWrite(csPin, HIGH);
  SPI.endTransaction(); // Uncomment if you have uncommented SPI.beginTransaction()
  delay(writeCycle);
}

int eepromReadInt(int addr){
  byte MSB = 0;
  byte LSB = 0;
  int value = 0; 
  SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
  digitalWrite(csPin, LOW);
  SPI.transfer(READ); 
  SPI.transfer((byte)(addr>>8));
  SPI.transfer((byte)(addr&0xFF));
  MSB = SPI.transfer(0x00);
  LSB = SPI.transfer(0x00);
  digitalWrite(csPin, HIGH);
  SPI.endTransaction();
  value = (int)((MSB<<8)|LSB);
  return value;
}

below is the arduino code, works for both IC's no need for changes, same command instructions and sequence.
datasheet of 25L4005 the one with the problem. And this is the datasheet for 25LC512 the working one.


Post a link to the datasheet of that chip!

1 Like

Connect MISO and MOSI together and see if you get anything. Post an annotated schematic of how you have it wired including all power, ground, power supplies etc. Also include the requested data sheet.

1 Like

I've updated post, sorry.

I've updated the post. apologies.

I see a frizzy picture I cannot read, still waiting on the schematic showing all connections including power, ground, and power sources.

The datasheet I found for a 25L4005 indicates that the device is a somewhat ancient SPI FLASH device (circa 2005), and not an EEPROM.

Maybe I missed it, but I could not find anything specific about the HOLD pin - i.e. whether it can be left floating - as you have it in the images in post #1. I would suggest connecting it to VCC to disable the HOLD feature.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.