📖 Reading and recording flash memory using Arduino on the example of 25L8005

📖 Reading and recording flash memory using Arduino on the example of 25L8005

Daniil Zhuk

In this article, we will look at how to write to flash memory and read from flash memory using Arduino using the example of a 25L8005 chip.

Flash memory chip 25L8005


Chip flash memory (or ROM) 25L8005 manufactured in different buildings. But as a rule, due to its small size, it is more convenient to use surface-mounted microchips. I just have this. It is made in the case type SOP 8L.

Therefore, you first need to do so that we can easily connect to the flash chip. To do this, you can use either a special adapter, to which you have to solder the chip or (which is preferable) to use a panel with zero gain.

This is what our ROM chip looks like, soldered to an adapter card with DIP-outputs:

And this is how a flash memory chip in a ZIF panel looks like:

Now we can use the breadboard (breadboard) and easily connect to the chip.

Arduino connection to flash memory chip 25L8005


The purpose of the conclusions of the ROM chip, given in the datasheet, is as follows:

We will use the SPI interface for programming flash memory, so we will connect to the standard SPI pins of the Arduino:

Flash Chip Output Arduino board output
CS# pin 10
SI pin 11
SO pin 12
SCLK pin 13
WP# 3V3
HOLD# 3V3
VCC 3V3
GND GND


Let's assemble the wiring diagram of the MX25L8005 flash memory chip to the Arduino.

I have a ROM on the circuit board and connected to the Arduino looks like this:

Cleaning flash memory using Arduino


Before you write data to flash memory, you must erase the sector or page in which we are going to record. If there is little data to be recorded (in our educational example it will be only 16 bytes), then it is enough to erase 1 sector. From the documentation on the chip, we see that the erase sequence is as follows: set write permission (1 byte), send an erase command (1 byte) and address (3 bytes), set write prohibition (1 byte). This sequence is shown in the figure below:

This is exactly what the sketch below does:

#include <SPI.h>

const int SSPin = 10;
const byte WREN = 0x06;
const byte WRDI = 0x04;
const byte SER = 0x20;
const byte ADDR1 = 0;
const byte ADDR2 = 0;
const byte ADDR3 = 0;

void setup() {
  pinMode(SSPin, OUTPUT);
  SPI.begin();

  SPISettings mySet(100000, MSBFIRST, SPI_MODE0);
  
  SPI.beginTransaction(mySet);
  digitalWrite(SSPin, LOW);
  SPI.transfer(WREN);
  digitalWrite(SSPin, HIGH);
  SPI.endTransaction();

  SPI.beginTransaction(mySet);
  digitalWrite(SSPin, LOW);
  SPI.transfer(SER);
  SPI.transfer(ADDR1);
  SPI.transfer(ADDR2);
  SPI.transfer(ADDR3);
  digitalWrite(SSPin, HIGH);
  SPI.endTransaction();
 
  SPI.beginTransaction(mySet);
  digitalWrite(SSPin, LOW);
  SPI.transfer(WRDI);
  digitalWrite(SSPin, HIGH);
  SPI.endTransaction();
}

void loop() {
}

Let's load this sketch into Arduino with a memory chip connected as shown above. After he worked, the flash drive is ready to write.

Write data to flash memory using Arduino


Now write the data to it. For example, take a small array of 16 bytes. As can be seen from the documentation, to write data to the flash, you must first set the write permission (1 byte), then send a write command (1 byte), transfer the starting address (3 bytes) and data (in our example 16 bytes), and end write prohibition (1 byte):

We write a sketch that writes an array of 16 bytes of data in the ROM:

#include <SPI.h>

const int SSPin = 10;
const byte WREN = 0x06;
const byte WRDI = 0x04;
const byte READ = 0x03;
const byte PP = 0x02;
const byte ADDR1 = 0;
const byte ADDR2 = 0;
const byte ADDR3 = 0;

void setup() {
  pinMode(SSPin, OUTPUT);
  SPI.begin();

  SPISettings mySet(100000, MSBFIRST, SPI_MODE0);
  
  SPI.beginTransaction(mySet);
  digitalWrite(SSPin, LOW);
  SPI.transfer(WREN);
  digitalWrite(SSPin, HIGH);
  SPI.endTransaction();

  SPI.beginTransaction(mySet);
  digitalWrite(SSPin, LOW);
  SPI.transfer(PP);
  SPI.transfer(ADDR1);
  SPI.transfer(ADDR2);
  SPI.transfer(ADDR3);
  byte data[] = {0x48,0x45,0x4c,0x4c,0x4f,0x2c,0x20,0x53,0x4f,0x4c,0x54,0x41,0x55,0x2e,0x52,0x55};
  for (int i=0; i<sizeof(data); i++) {
    SPI.transfer(data[i]);
  }
  digitalWrite(SSPin, HIGH);
  SPI.endTransaction();
  
  SPI.beginTransaction(mySet);
  digitalWrite(SSPin, LOW);
  SPI.transfer(WRDI);
  digitalWrite(SSPin, HIGH);
  SPI.endTransaction();
}

void loop() {
}

Загрузим скетч в Arduino. Кстати, вот так выглядит на логическом анализаторе обмен по SPI между Arduino и ПЗУ 25L8005, когда выполняется данный скетч.

After performing this sketch, our test array should have been written into flash memory. Let's check it out.

Reading data from flash memory using Arduino


According to the documentation, reading from a flash drive is performed using the following sequence: sending a command for reading (1 byte), a starting address (3 bytes), and then as many bytes are requested as we want to read from the ROM. Actually, we will transfer 16 zeros to the ROM. Since SPI is a synchronous interface, we will return 16 bytes written to the ROM. Here is a diagram is given in the description of the chip:

We will write a sketch to read our cherished 16-bytes from a 25L8005 flash memory chip:

#include <SPI.h>

const int SSPin = 10;
const byte READ = 0x03;
const byte ADDR1 = 0;
const byte ADDR2 = 0;
const byte ADDR3 = 0;

void setup() {
  Serial.begin(9600);
  pinMode(SSPin, OUTPUT);
  SPI.begin();  
}

void loop() { 
  SPISettings mySet(100000, MSBFIRST, SPI_MODE0);
  SPI.beginTransaction(mySet);
  digitalWrite(SSPin, LOW);
  SPI.transfer(READ); 
  SPI.transfer(ADDR1);
  SPI.transfer(ADDR2);
  SPI.transfer(ADDR3);
  for (int i=0; i<16; i++) {
    byte data = SPI.transfer(0);
    Serial.print((char)data);
  }
  Serial.println();
  digitalWrite(SSPin, HIGH);
  SPI.endTransaction();
  delay(1000); 
}

Load the sketch into Arduino and open the serial port monitor. In the monitor, as expected, our array, read from flash memory using Arduino, will be output 1 time per second.

Here's what reading from the ROM looks like if you connect to the SPI lines with a logic analyzer:

As you can see, the bytes of this array corresponds to the ASCII codes of the string "HELLO, SOLTAU.RU"

Add a comment

* Comments must be approved before being displayed.